시스템 프롬프트는 Claude의 동작, 기능 및 응답 스타일을 정의합니다. Claude Agent SDK는 시스템 프롬프트를 커스터마이즈하는 세 가지 방법을 제공합니다: 출력 스타일(영구적, 파일 기반 구성) 사용, Claude Code의 프롬프트에 추가, 또는 완전히 커스텀 프롬프트 사용입니다.
시스템 프롬프트는 대화 전반에 걸쳐 Claude의 동작 방식을 형성하는 초기 지시 세트입니다.
기본 동작: Agent SDK는 기본적으로 최소한의 시스템 프롬프트를 사용합니다. 필수 도구 지시사항만 포함하며 Claude Code의 코딩 가이드라인, 응답 스타일, 프로젝트 컨텍스트는 생략됩니다. 전체 Claude Code 시스템 프롬프트를 포함하려면 TypeScript에서 systemPrompt: { preset: "claude_code" }를, Python에서 system_prompt={"type": "preset", "preset": "claude_code"}를 지정하세요.
Claude Code의 시스템 프롬프트에는 다음이 포함됩니다:
CLAUDE.md 파일은 Agent SDK가 디렉토리에서 실행될 때 자동으로 읽히는 프로젝트별 컨텍스트와 지시사항을 제공합니다. 프로젝트의 영구적인 "메모리" 역할을 합니다.
위치 및 검색:
CLAUDE.md 또는 .claude/CLAUDE.md~/.claude/CLAUDE.md중요: SDK는 settingSources(TypeScript) 또는 setting_sources(Python)를 명시적으로 구성할 때만 CLAUDE.md 파일을 읽습니다:
'project'를 포함하세요~/.claude/CLAUDE.md)를 로드하려면 'user'를 포함하세요claude_code 시스템 프롬프트 프리셋은 CLAUDE.md를 자동으로 로드하지 않습니다 - 설정 소스도 반드시 지정해야 합니다.
콘텐츠 형식: CLAUDE.md 파일은 일반 마크다운을 사용하며 다음을 포함할 수 있습니다:
# Project Guidelines
## Code Style
- Use TypeScript strict mode
- Prefer functional components in React
- Always include JSDoc comments for public APIs
## Testing
- Run `npm test` before committing
- Maintain >80% code coverage
- Use jest for unit tests, playwright for E2E
## Commands
- Build: `npm run build`
- Dev server: `npm run dev`
- Type check: `npm run typecheck`import { query } from "@anthropic-ai/claude-agent-sdk";
// 중요: CLAUDE.md를 로드하려면 settingSources를 지정해야 합니다
// claude_code 프리셋만으로는 CLAUDE.md 파일을 로드하지 않습니다
const messages = [];
for await (const message of query({
prompt: "Add a new React component for user profiles",
options: {
systemPrompt: {
type: "preset",
preset: "claude_code", // Claude Code의 시스템 프롬프트 사용
},
settingSources: ["project"], // 프로젝트에서 CLAUDE.md를 로드하는 데 필요
},
})) {
messages.push(message);
}
// 이제 Claude가 CLAUDE.md의 프로젝트 가이드라인에 접근할 수 있습니다적합한 용도:
주요 특성:
settingSources를 통한 설정 로드 필요출력 스타일은 Claude의 시스템 프롬프트를 수정하는 저장된 구성입니다. 마크다운 파일로 저장되며 세션과 프로젝트 간에 재사용할 수 있습니다.
import { writeFile, mkdir } from "fs/promises";
import { join } from "path";
import { homedir } from "os";
async function createOutputStyle(
name: string,
description: string,
prompt: string
) {
// 사용자 수준: ~/.claude/output-styles
// 프로젝트 수준: .claude/output-styles
const outputStylesDir = join(homedir(), ".claude", "output-styles");
await mkdir(outputStylesDir, { recursive: true });
const content = `---
name: ${name}
description: ${description}
---
${prompt}`;
const filePath = join(
outputStylesDir,
`${name.toLowerCase().replace(/\s+/g, "-")}.md`
);
await writeFile(filePath, content, "utf-8");
}
// 예시: 코드 리뷰 전문가 만들기
await createOutputStyle(
"Code Reviewer",
"Thorough code review assistant",
`You are an expert code reviewer.
For every code submission:
1. Check for bugs and security issues
2. Evaluate performance
3. Suggest improvements
4. Rate code quality (1-10)`
);생성 후 다음을 통해 출력 스타일을 활성화합니다:
/output-style [style-name].claude/settings.local.json/output-style:new [description]SDK 사용자 참고: 출력 스타일은 옵션에 settingSources: ['user'] 또는 settingSources: ['project'](TypeScript) / setting_sources=["user"] 또는 setting_sources=["project"](Python)를 포함할 때 로드됩니다.
systemPrompt 사용Claude Code 프리셋에 append 속성을 사용하여 모든 내장 기능을 유지하면서 커스텀 지시사항을 추가할 수 있습니다.
import { query } from "@anthropic-ai/claude-agent-sdk";
const messages = [];
for await (const message of query({
prompt: "Help me write a Python function to calculate fibonacci numbers",
options: {
systemPrompt: {
type: "preset",
preset: "claude_code",
append:
"Always include detailed docstrings and type hints in Python code.",
},
},
})) {
messages.push(message);
if (message.type === "assistant") {
console.log(message.message.content);
}
}커스텀 문자열을 systemPrompt로 제공하여 기본값을 완전히 자신의 지시사항으로 대체할 수 있습니다.
import { query } from "@anthropic-ai/claude-agent-sdk";
const customPrompt = `You are a Python coding specialist.
Follow these guidelines:
- Write clean, well-documented code
- Use type hints for all functions
- Include comprehensive docstrings
- Prefer functional programming patterns when appropriate
- Always explain your code choices`;
const messages = [];
for await (const message of query({
prompt: "Create a data processing pipeline",
options: {
systemPrompt: customPrompt,
},
})) {
messages.push(message);
if (message.type === "assistant") {
console.log(message.message.content);
}
}| 기능 | CLAUDE.md | 출력 스타일 | append를 사용한 systemPrompt | 커스텀 systemPrompt |
|---|---|---|---|---|
| 영속성 | 프로젝트별 파일 | 파일로 저장 | 세션 한정 | 세션 한정 |
| 재사용성 | 프로젝트별 | 프로젝트 간 | 코드 중복 | 코드 중복 |
| 관리 | 파일 시스템에서 | CLI + 파일 | 코드 내 | 코드 내 |
| 기본 도구 | 유지 | 유지 | 유지 | 손실 (포함하지 않는 한) |
| 내장 안전성 | 유지 | 유지 | 유지 | 직접 추가 필요 |
| 환경 컨텍스트 | 자동 | 자동 | 자동 | 직접 제공 필요 |
| 커스터마이즈 수준 | 추가만 | 기본값 대체 | 추가만 | 완전한 제어 |
| 버전 관리 | 프로젝트와 함께 | 가능 | 코드와 함께 | 코드와 함께 |
| 범위 | 프로젝트 한정 | 사용자 또는 프로젝트 | 코드 세션 | 코드 세션 |
참고: "append 사용"은 TypeScript에서 systemPrompt: { type: "preset", preset: "claude_code", append: "..." }를, Python에서 system_prompt={"type": "preset", "preset": "claude_code", "append": "..."}를 사용하는 것을 의미합니다.
적합한 용도:
예시:
npm run lint:fix를 실행하세요"migrations/ 디렉토리에 있습니다"중요: CLAUDE.md 파일을 로드하려면 settingSources: ['project'](TypeScript) 또는 setting_sources=["project"](Python)를 명시적으로 설정해야 합니다. claude_code 시스템 프롬프트 프리셋은 이 설정 없이는 CLAUDE.md를 자동으로 로드하지 않습니다.
적합한 용도:
예시:
systemPrompt를 사용해야 하는 경우적합한 용도:
systemPrompt를 사용해야 하는 경우적합한 용도:
최대한의 유연성을 위해 이러한 방법을 결합할 수 있습니다:
import { query } from "@anthropic-ai/claude-agent-sdk";
// "Code Reviewer" 출력 스타일이 활성화되어 있다고 가정 (/output-style을 통해)
// 세션별 중점 영역 추가
const messages = [];
for await (const message of query({
prompt: "Review this authentication module",
options: {
systemPrompt: {
type: "preset",
preset: "claude_code",
append: `
For this review, prioritize:
- OAuth 2.0 compliance
- Token storage security
- Session management
`,
},
},
})) {
messages.push(message);
}Was this page helpful?