Claude Code์์ ์ฒซ ๋ฒ์งธ ์์ฒญ์ ์
๋ ฅํ๋ฉด ๊ฐ์ฅ ๋จผ์ ๋ค์๊ณผ ๊ฐ์ JSON์ API๋ก ๋ณด๋ธ๋ค. ์ด ์์ฒญ์ ์ค์ ์์
์ ์์ ๋ํ ์ฃผ์ ๋ฅผ ํ์
ํ๊ณ ์ ๋ชฉ์ ์์ฑํ๊ธฐ ์ํ ๋ณด์กฐ ์์ฒญ์ด๋ค.
{
"model": "claude-haiku-4-5-20251001",
"messages": [
{
"role": "user",
"content": [
{
"type": "text",
"text": "Request Body์ ๊ตฌ์กฐ๋ฅผ ๋ถ์ํ๊ณ ๋ถ๋ฅ๋ณ๋ก ๋ฌถ์ด์ ํํํ๋ค. ultrathink"
}
]
},
{
"role": "assistant",
"content": [
{
"type": "text",
"text": "{"
}
]
}
],
"system": [
{
"type": "text",
"text": "You are Claude Code, Anthropic's official CLI for Claude."
},
{
"type": "text",
"text": "Analyze if this message indicates a new conversation topic. If it does, extract a 2-3 word title that captures the new topic. Format your response as a JSON object with two fields: 'isNewTopic' (boolean) and 'title' (string, or null if isNewTopic is false). Only include these fields, no other text. ONLY generate the JSON object, no other text (eg. no markdown)."
}
],
"tools": [],
"metadata": {
"user_id": "user-id"
},
"max_tokens": 32000,
"stream": true
}
์์คํ
ํ๋กฌํํธ๋ฅผ ๋ณด๋ฉด ์ด ์์ฒญ์ด ์ ๊ท ๋ํ์ธ์ง ํ๋จํ๊ณ , ์ ๊ท ๋ํ๋ผ๋ฉด 2-3 ๋จ์ด์ ์ ๋ชฉ์ ์ถ์ถํ์ฌ isNewTopic๊ณผ title ํ๋๋ก ๊ตฌ์ฑ๋ JSON๋ง ๋ฐํํ๋ผ๊ณ ์ง์ํ๊ณ ์๋ค.
์ฌ๊ธฐ์ ๋ด ๋์ ๋ ๊ฒ์ ์ฒซ ๋ฒ์งธ ์์ฒญ์์๋ ๋ถ๊ตฌํ๊ณ ๋ง์น ๋ฉํฐํด ๋ํ๊ฐ ์งํ๋ ๊ฒ์ฒ๋ผ messages์ ๋ง์ง๋ง role์ด assistant๋ผ๋ ์ ์ด์๋ค. ๊ฒ๋ค๊ฐ Claude๊ฐ { ํ ๊ธ์๋ง ์๋ตํ ๊ฒ์ฒ๋ผ ๊ตฌ์ฑ๋์ด ์๋ค.
์ด ์์ฒญ์ ๋ํ ์๋ต์ ๋ค์๊ณผ ๊ฐ๋ค.
{
"id": "msg_id",
"type": "message",
"role": "assistant",
"model": "claude-haiku-4-5-20251001",
"content": [
{
"type": "text",
"text": "\n \"isNewTopic\": true,\n \"title\": \"Request Body Formatting\"\n}"
}
],
"stop_reason": "end_turn",
"stop_sequence": null,
"usage": {
"input_tokens": 187,
"output_tokens": 26,
"cache_creation_input_tokens": 0,
"cache_read_input_tokens": 0
}
}
content.text๋ฅผ ๋ณด๊ธฐ์ข๊ฒ ์ ๋ฆฌํด์ ์ ์ผ๋ฉด ๋ค์๊ณผ ๊ฐ๋ค.
"isNewTopic": true,
"title": "Request Body Formatting"
}
์์ ํ JSON์์ ๋งจ ์์ {๊ฐ ๋น ์ง ํํ๋ค. ์๊ณ ๋ณด๋ ์ด๊ฒ์ prefill ๊ธฐ๋ฒ์ด๋ผ ๋ถ๋ฆฌ๋ ๊ฒ์ผ๋ก, ๋ชจ๋ธ์ด ์๋ต์ ์๋ถ๋ถ์ ์ด๋ฏธ ์ถ๋ ฅํ ๊ฒ์ฒ๋ผ ์ค์ ํ์ฌ ์ด์ด์ง๋ ์๋ต์ ์ํ๋ ํ์์ผ๋ก ์ ๋ํ๋ ๋ฐฉ๋ฒ์ด๋ค.
Claude Code๋ ์ด ๊ธฐ๋ฒ์ ํ์ฉํด ๋ชจ๋ธ์ด JSON ํ์์ผ๋ก ์๋ตํ๋๋ก ๊ฐ์ ํ๊ณ ์๋ค. ๋จ์ํ "JSON์ผ๋ก ์๋ตํด์ค"๋ผ๊ณ ์์ฒญํ๋ ๊ฒ๋ณด๋ค ํจ์ฌ ํ์คํ ๋ฐฉ๋ฒ์ด๋ค. ๋ชจ๋ธ ์
์ฅ์์๋ ์ด๋ฏธ {๋ก ์์ํ์ผ๋ ์์ฐ์ค๋ฝ๊ฒ JSON์ ์์ฑํ ์๋ฐ์ ์๊ธฐ ๋๋ฌธ์ด๋ค.
Prefill์ JSON ์ธ์๋ ๋ค์ํ๊ฒ ํ์ฉํ ์ ์๋ค. ์๋ฅผ ๋ค์ด ```python์ผ๋ก ์์ํ๋ฉด ๋ชจ๋ธ์ด ํ์ด์ฌ ์ฝ๋ ๋ธ๋ก์ ์์ฑํ๊ฒ ๋๊ณ , <analysis>๋ก ์์ํ๋ฉด XML ํ์์ ์๋ต์ ์ ๋ํ ์ ์๋ค.
Read more โ