modified
--- a/modifying-system-prompts.md +++ b/modifying-system-prompts.md @@ -336,7 +336,7 @@ ## Context Claude Code adds outside the system prompt -System reminders are messages Claude Code adds to the conversation during a session to give Claude context, such as the contents of your CLAUDE.md files or a note that a file changed on disk. Claude Code sends them in the conversation, not in the system prompt, so most reach Claude whether you use the `claude_code` preset or pass your own string as `systemPrompt`. This section covers the reminders most likely to change how your agent behaves, how to turn off the ones your agent replaces, and how to see what Claude received in a specific request. +System reminders are messages Claude Code adds to the conversation during a session to give Claude context, such as the contents of your CLAUDE.md files. Claude Code sends them in the conversation, not in the system prompt, so most reach Claude whether you use the `claude_code` preset or pass your own string as `systemPrompt`. This section covers the reminders most likely to change how your agent behaves, how to turn off the ones your agent replaces, and how to see what Claude received in a specific request. ### Reminders Claude Code adds to the conversation @@ -349,7 +349,7 @@ * **Available skills** : the names and descriptions of the [skills](</docs/en/agent-sdk/skills>) Claude can call * **Available subagents** : the names and descriptions of the [subagents](</docs/en/agent-sdk/subagents>) Claude can start * **Task list nudges** : in a [session that has the task-tracking tools](</docs/en/agent-sdk/todo-tracking#model-availability>), a prompt to update the task list when Claude hasn’t touched it for several turns - * **File-changed notes** : a note that a file Claude read earlier has changed on disk + * **File-changed notes** : a note that a file Claude edited earlier has since changed on disk Claude Code introduces your CLAUDE.md files with a line telling Claude that the instructions override default behavior. If you pass your own string as `systemPrompt`, add a sentence to it that says what a system reminder is. The `claude_code` preset has one, and your string replaces the whole preset. Without it, nothing in your prompt tells Claude that reminders such as CLAUDE.md content and hook output come from the application rather than the user. For example:
modified
--- a/modifying-system-prompts.md +++ b/modifying-system-prompts.md @@ -438,7 +438,7 @@ **Persistence**| Per-project file| Saved as files| Session only| Session only **Reusability**| Per-project| Across projects| Code duplication| Code duplication **Management**| On filesystem| CLI + files| In code| In code -**Default tools**| Preserved| Preserved| Preserved| Lost (unless included) +**Tool guidance**| Preserved| Preserved| Preserved| Lost (unless included) **Built-in safety**| Maintained| Maintained| Maintained| Must be added **Customization level**| Additions only| Additions; can omit coding instructions| Additions only| Complete control **Version control**| With project| Yes| With code| With code
modified
Show diff (271 lines)
--- a/modifying-system-prompts.md +++ b/modifying-system-prompts.md @@ -1,10 +1,6 @@ System prompts define Claude’s behavior, capabilities, and response style. Start from the `claude_code` preset for CLI or IDE-like coding tools where a human watches and steers the work. Write your own prompt for agents with a different surface, identity, or permission model. -## - -​ - -How system prompts work +## How system prompts work A system prompt is the initial instruction set that shapes how Claude behaves throughout a conversation. The Agent SDK has three starting points for it: @@ -12,11 +8,7 @@ * **`claude_code` preset**: the system prompt that the Claude Code CLI uses, with tool usage instructions and security and safety instructions. Set `systemPrompt: { type: "preset", preset: "claude_code" }` in TypeScript or `system_prompt={"type": "preset", "preset": "claude_code"}` in Python, optionally with `append` to add your own instructions on the end. * **Custom string** : a prompt you write yourself. The SDK sends only what you provide. -### - -​ - -Decide on a starting point +### Decide on a starting point The deciding factor is how closely your agent resembles Claude Code: a coding agent operating in a repository, with a human watching streaming output and steering the work. The further your product is from that, the more you’ll want to write your own prompt. @@ -36,27 +28,15 @@ The comparison table shows what each customization method preserves. -## - -​ - -Customize agent behavior +## Customize agent behavior `append` and a custom prompt string each change the system prompt directly, and an output style changes the instructions Claude Code gives Claude for every response. CLAUDE.md takes a different path: the SDK reads it and injects its content into the conversation as project context, so it shapes behavior alongside whichever system prompt you choose. [Skills](</docs/en/agent-sdk/skills>), [hooks](</docs/en/agent-sdk/hooks>), and [permissions](</docs/en/agent-sdk/permissions>) also shape behavior outside the system prompt and are covered on their own pages. -### - -​ - -CLAUDE.md files for project-level instructions +### CLAUDE.md files for project-level instructions CLAUDE.md files give Claude persistent project context and instructions. The SDK injects their content into the conversation and leaves the system prompt untouched, so they work with any system prompt configuration. For what to put in CLAUDE.md, where to place it, and how to write effective instructions, see [When to add to CLAUDE.md](</docs/en/memory#when-to-add-to-claude-md>) and the rest of [How Claude remembers your project](</docs/en/memory>). This section covers what’s specific to the SDK: how CLAUDE.md loads. The SDK reads CLAUDE.md when the matching setting source is enabled: `'project'` loads `CLAUDE.md` or `.claude/CLAUDE.md` from the working directory, and `'user'` loads `~/.claude/CLAUDE.md`. Default `query()` options enable both sources, so CLAUDE.md loads automatically. If you set `settingSources` in TypeScript or `setting_sources` in Python explicitly, include the sources you need. CLAUDE.md loading is controlled by setting sources, not by the `claude_code` preset. -#### - -​ - -Load CLAUDE.md with the SDK +#### Load CLAUDE.md with the SDK To load CLAUDE.md, set `settingSources` to include the level where you keep your CLAUDE.md. The example below loads a project-level CLAUDE.md alongside the `claude_code` preset, so Claude has both the coding-agent prompt and your project’s conventions: @@ -108,19 +88,11 @@ When you run either example, the SDK streams messages as Claude works: a system init message, assistant messages, user messages carrying tool results, and a final result message with the session outcome. CLAUDE.md is persistent across all sessions in a project, shared with your team through git, and discovered automatically without code changes. It is not loaded if you pass an empty `settingSources` array. -### - -​ - -Output styles for persistent configurations +### Output styles for persistent configurations Output styles are saved sets of instructions that change Claude’s role, tone, and output format. They’re stored as markdown files and can be reused across sessions and projects. -#### - -​ - -Create an output style +#### Create an output style An output style is a markdown file with [frontmatter](</docs/en/output-styles#frontmatter>) for metadata, followed by the prompt content. Save it to `~/.claude/output-styles/` for a user-level style available in every project, or `.claude/output-styles/` in your repository for a project-level style you can commit and share with your team. A custom output style leaves the `claude_code` preset’s software engineering instructions out and uses your own. To keep them and layer your instructions on top, set `keep-coding-instructions: true` in the frontmatter. Those instructions are only in Claude Code’s full system prompt, so the setting has no effect in a session on the shorter system prompt; set [`CLAUDE_CODE_SIMPLE_SYSTEM_PROMPT`](</docs/en/env-vars#variables>) to `0` to select the full prompt on any model. Keep them when your agent is still doing software engineering work. Leave them out when you’re replacing the role entirely. The example below defines a code-review persona that keeps the coding instructions, since reviewing code still benefits from Claude Code’s security and code-quality guidance. Save it as `~/.claude/output-styles/code-reviewer.md` to make it available across projects: @@ -140,11 +112,7 @@ 3. Suggest improvements 4. Rate code quality (1-10) -#### - -​ - -Activate an output style +#### Activate an output style Once created, activate output styles via: @@ -156,11 +124,7 @@ In the Python SDK, set `outputStyle` through the `settings` option, which takes a JSON string such as `'{"outputStyle": "Explanatory"}'` or a path to a settings file that sets it. **Note for SDK users:** Output styles are loaded when you include `settingSources: ['user']` or `settingSources: ['project']` (TypeScript) / `setting_sources=["user"]` or `setting_sources=["project"]` (Python) in your options. -### - -​ - -Append to the `claude_code` preset +### Append to the `claude_code` preset You can use the Claude Code preset with an `append` property to add your custom instructions while preserving all built-in functionality. @@ -211,11 +175,7 @@ asyncio.run(main()) -#### - -​ - -Improve prompt caching across users and machines +#### Improve prompt caching across users and machines By default, two sessions that use the same `claude_code` preset and `append` text still can’t share a prompt cache entry when their auto memory locations differ. The preset embeds that location in the system prompt ahead of your `append` text. The location defaults to an absolute path under `~/.claude/projects/` named for the repository’s path on disk, so it differs across users, machines, and checkouts. CLAUDE.md content and environment details such as the working directory, platform, shell, and OS version don’t affect the system prompt cache, because Claude Code delivers them in the conversation, not the system prompt. To make the system prompt identical across sessions, set `excludeDynamicSections: true` in TypeScript or `"exclude_dynamic_sections": True` in Python. The per-user context moves into the first user message, leaving only the static preset and your `append` text in the system prompt so identical configurations share a cache entry across users and machines. @@ -265,11 +225,7 @@ **Tradeoffs:** the text that moves out of the system prompt still reaches Claude, but in a user message. That text is at least the auto memory directory’s location, and often the whole auto memory section. Instructions in a user message carry marginally less weight than the same text in the system prompt, so Claude may follow its auto memory guidance less consistently. Enable this option when cross-session cache reuse matters more than that. For the equivalent flag in non-interactive CLI mode, see [`--exclude-dynamic-system-prompt-sections`](</docs/en/cli-reference>). -### - -​ - -Custom system prompts +### Custom system prompts You can provide a custom string as `systemPrompt` to replace the default entirely with your own instructions. @@ -328,11 +284,7 @@ In Python, load a large custom prompt from a file with `system_prompt={"type": "file", "path": "..."}` instead of passing it as a string. The Python SDK passes a string prompt as one command-line argument to the CLI subprocess, so a prompt that exceeds the OS argument-length limit fails at process spawn before any API request is sent. On Linux the error is `Argument list too long`. See [`SystemPromptFile`](</docs/en/agent-sdk/python#systempromptfile>) for the platform thresholds and the Windows behavior. -#### - -​ - -Cache the static part of a custom prompt +#### Cache the static part of a custom prompt In the TypeScript SDK, you can pass a custom prompt as an array of strings instead of one string, with the `SYSTEM_PROMPT_DYNAMIC_BOUNDARY` marker between the static part and the rest. Use this when your prompt combines instructions that are the same on every request with context that changes per request, such as the customer or ticket the agent is handling. When you pass both parts as one string, a change to the per-request part changes the whole system prompt, so the static instructions miss the cache too. The array form isn’t available in the Python SDK; [`ClaudeAgentOptions`](</docs/en/agent-sdk/python#claudeagentoptions>) lists the forms `system_prompt` accepts. @@ -367,46 +319,26 @@ With the CLI’s [`--system-prompt` or `--system-prompt-file` flags](</docs/en/cli-reference#system-prompt-flags>), the prompt is one string, so there is no array to carry the marker. Include a line containing only `__SYSTEM_PROMPT_DYNAMIC_BOUNDARY__` between the static and per-request parts instead. Claude Code splits the prompt at the first such line into the same two blocks and removes that line. Requires Claude Code v2.1.275 or later. In the SDK, prefer the array form, which carries the boundary without a marker line. -### - -​ - -Change the prompt of an existing session +### Change the prompt of an existing session By default, if you pass a different `append` or custom prompt when you return to a session with `resume` or `continue`, Claude doesn’t see it on the next turn. Claude Code records the system prompt on a session’s first request and reuses that record until the session is compacted. The new text takes effect after that compaction, or in a new session. -#### - -​ - -Update Claude’s instructions mid-session +#### Update Claude’s instructions mid-session If the instructions you put in the system prompt need to change while a session is running, for example because your user switched the agent to a read-only mode or edited its configuration in your app, send the new instructions in the conversation instead of changing `systemPrompt`: * **In your next message** : include the new instructions in the next user message you send. * **From a hook** : return [`additionalContext`](</docs/en/hooks#add-context-for-claude>) from a `UserPromptSubmit` or `PostToolUse` [hook callback](</docs/en/agent-sdk/hooks#outputs>), written as a factual statement such as “The workspace is now read-only”. The SDK inserts the text into the conversation at the point where the hook fired, so the recorded prompt stays unchanged. -#### - -​ - -Turn recording off while you iterate on wording +#### Turn recording off while you iterate on wording While you iterate on prompt wording and want each edit to reach a session you resume, set `snapshot` to false on the object form of the system prompt. Claude Code then rebuilds the prompt on every request. The field is available on the preset and custom forms of [`systemPrompt`](</docs/en/agent-sdk/typescript#options>) in TypeScript and of [`system_prompt`](</docs/en/agent-sdk/python#systempromptpreset>) in Python, and requires `@anthropic-ai/claude-agent-sdk` v0.3.257 or later, or `claude-agent-sdk` v0.2.153 or later. Keep recording on in production. With recording off, a different `append` or custom prompt on a resumed session reaches Claude on the next turn, and that request can’t reuse the session’s [prompt cache](</docs/en/prompt-caching#how-the-cache-is-organized>). Where the API enforces [preserved thinking](<https://platform.claude.com/docs/en/build-with-claude/preserved-thinking>), Claude also loses its thinking from earlier turns. Outside of [cloud sessions](</docs/en/cloud-environments>), if you start Claude Code in [bare mode](</docs/en/headless#start-faster-with-bare-mode>) by passing `--bare` through `extraArgs` or setting `CLAUDE_CODE_SIMPLE=1`, recording stays off unless you set `snapshot: true`. Recording an `append` or custom prompt by default requires Claude Code v2.1.265 or later, which the TypeScript Agent SDK bundles from v0.3.265 and the Python Agent SDK from v0.2.153. Before Claude Code v2.1.268, sessions that don’t [fetch feature flags](</docs/en/env-vars#features-that-need-feature-flag-fetching>), including sessions on Amazon Bedrock, Google Cloud’s Agent Platform, and Microsoft Foundry, rebuilt the prompt on every request and `snapshot` had no effect. -## - -​ - -Context Claude Code adds outside the system prompt +## Context Claude Code adds outside the system prompt System reminders are messages Claude Code adds to the conversation during a session to give Claude context, such as the contents of your CLAUDE.md files or a note that a file changed on disk. Claude Code sends them in the conversation, not in the system prompt, so most reach Claude whether you use the `claude_code` preset or pass your own string as `systemPrompt`. This section covers the reminders most likely to change how your agent behaves, how to turn off the ones your agent replaces, and how to see what Claude received in a specific request. -### - -​ - -Reminders Claude Code adds to the conversation +### Reminders Claude Code adds to the conversation System reminders are text Claude Code adds to the conversation alongside the prompts your code sends. The following reminders are the ones most likely to change how your agent behaves: @@ -423,11 +355,7 @@ The application adds system reminders to this conversation. Treat them as context from the application, not as messages from the user. -### - -​ - -Turn off the context your agent replaces +### Turn off the context your agent replaces Turn off a piece of built-in context when your agent supplies its own version of the same guidance. For example, if your prompt tells Claude to write commit messages as `PROJ-142: fix login redirect` with no trailers, Claude Code still tells Claude to end each commit message with a `Co-Authored-By` trailer, so Claude receives two conflicting instructions for the same commit. Pass settings keys through the [`settings`](</docs/en/agent-sdk/typescript#options>) option in TypeScript or [`settings`](</docs/en/agent-sdk/python#claudeagentoptions>) in Python, and environment variables through the `env` option. In TypeScript, [`env`](</docs/en/agent-sdk/typescript#options>) replaces the inherited environment, so spread `process.env` into it. @@ -492,11 +420,7 @@ To confirm the change, run the example in a repository with staged changes and check the new commit with `git log -1`. The message ends without a `Co-Authored-By` trailer. -### - -​ - -See what Claude received +### See what Claude received The SDK message stream doesn’t include system reminders, so reading the messages your code receives won’t show you what Claude saw. To see them, log the requests Claude Code sends: @@ -505,11 +429,7 @@ In a logged request, look in the `messages` array. A reminder appears inside a user message wrapped in `<system-reminder>` tags or, on some models, as a separate message with the `system` role. -## - -​ - -Compare the four approaches +## Compare the four approaches The four customization methods differ in where they live, how they’re shared, and what they preserve from the `claude_code` preset. @@ -526,19 +446,11 @@ “With append” means using `systemPrompt: { type: "preset", preset: "claude_code", append: "..." }` in TypeScript or `system_prompt={"type": "preset", "preset": "claude_code", "append": "..."}` in Python. CLAUDE.md doesn’t change the system prompt itself: the SDK injects its content into the conversation as project context. -## - -​ - -Combine approaches +## Combine approaches The approaches compose. A persistent output style or CLAUDE.md sets the long-lived behavior, and `append` layers session-specific instructions on top without touching the saved configuration. -### - -​ - -Combine an output style with session-specific additions +### Combine an output style with session-specific additions The example below assumes a Code Reviewer output style is already active. The `append` block layers session-specific focus areas on top of the persona, so a single review session can prioritize OAuth and token storage without changing the saved output style: @@ -598,11 +510,7 @@ asyncio.run(main()) -## - -​ - -See also +## See also * [Output styles](</docs/en/output-styles>): create, manage, and share output styles for the CLI, including the file format and storage locations * [How Claude remembers your project](</docs/en/memory>): what to put in CLAUDE.md, where to place it, and how to write effective project instructions
modified
--- a/modifying-system-prompts.md +++ b/modifying-system-prompts.md @@ -439,7 +439,12 @@ Every CLAUDE.md file| Set `CLAUDE_CODE_DISABLE_CLAUDE_MDS=1` Task list nudges, file-changed notes, and the skill list| Set `CLAUDE_CODE_DISABLE_ATTACHMENTS=1` -Set `includeGitInstructions` to `false` to keep out the built-in commit and pull request instructions, which are part of the Bash tool’s description and reach Claude even with a custom `systemPrompt`. With the minimal default, a custom `systemPrompt`, or a custom main-thread agent that has its own prompt, though, the session starts without the git status snapshot. If you set `CLAUDE_CODE_DISABLE_ATTACHMENTS`, Claude Code also sends `@` file mentions as plain text instead of expanding them into file content. The list of available subagents and background task notifications still arrive. To stop only `@` file mentions from expanding, set [`CLAUDE_CODE_DISABLE_FILE_MENTIONS=1`](</docs/en/env-vars#variables>) instead, on Claude Code v2.1.299 or later. Claude then gets the mentioned paths plus a note to read them with its file tools. The following example is for an agent that carries its own commit rules in `append`. It sets both `attribution` keys to empty strings to remove the trailer and footer, and turns off `includeGitInstructions` so Claude Code’s own commit workflow instructions don’t compete with yours: +Set `includeGitInstructions` to `false` to keep out the built-in commit and pull request instructions, which are part of the Bash tool’s description and reach Claude even with a custom `systemPrompt`. With the minimal default, a custom `systemPrompt`, or a custom main-thread agent that has its own prompt, though, the session starts without the git status snapshot. + + * If you set `CLAUDE_CODE_DISABLE_ATTACHMENTS`, Claude Code also sends `@` file mentions as plain text instead of expanding them into file content. The list of available subagents and background task notifications still arrive. + * To stop only `@` file mentions from expanding, set [`CLAUDE_CODE_DISABLE_FILE_MENTIONS=1`](</docs/en/env-vars#variables>) instead, on Claude Code v2.1.299 or later. Claude then gets the mentioned paths plus a note to read them with its file tools, and your `PreToolUse` hooks see each file read as a tool call. + +The following example is for an agent that carries its own commit rules in `append`. It sets both `attribution` keys to empty strings to remove the trailer and footer, and turns off `includeGitInstructions` so Claude Code’s own commit workflow instructions don’t compete with yours: TypeScript
modified
--- a/modifying-system-prompts.md +++ b/modifying-system-prompts.md @@ -400,7 +400,7 @@ Context Claude Code adds outside the system prompt -System reminders are messages Claude Code adds to the conversation during a session to give Claude context, such as the contents of your CLAUDE.md files or a note that a file changed on disk. Claude Code sends them in the conversation, not in the system prompt, so they reach Claude whether you use the `claude_code` preset or pass your own string as `systemPrompt`. This section covers the reminders most likely to change how your agent behaves, how to turn off the ones your agent replaces, and how to see what Claude received in a specific request. +System reminders are messages Claude Code adds to the conversation during a session to give Claude context, such as the contents of your CLAUDE.md files or a note that a file changed on disk. Claude Code sends them in the conversation, not in the system prompt, so most reach Claude whether you use the `claude_code` preset or pass your own string as `systemPrompt`. This section covers the reminders most likely to change how your agent behaves, how to turn off the ones your agent replaces, and how to see what Claude received in a specific request. ### @@ -439,7 +439,7 @@ Every CLAUDE.md file| Set `CLAUDE_CODE_DISABLE_CLAUDE_MDS=1` Task list nudges, file-changed notes, and the skill list| Set `CLAUDE_CODE_DISABLE_ATTACHMENTS=1` -Claude Code’s built-in commit and pull request instructions aren’t a reminder. They are part of the Bash tool’s description, so they also reach Claude when you pass a custom `systemPrompt`. If you set `CLAUDE_CODE_DISABLE_ATTACHMENTS`, Claude Code also sends `@` file mentions as plain text instead of expanding them into file content. The list of available subagents and background task notifications still arrive. The following example is for an agent that carries its own commit rules in `append`. It sets both `attribution` keys to empty strings to remove the trailer and footer, and turns off `includeGitInstructions` so Claude Code’s own commit workflow instructions don’t compete with yours: +Set `includeGitInstructions` to `false` to keep out the built-in commit and pull request instructions, which are part of the Bash tool’s description and reach Claude even with a custom `systemPrompt`. With the minimal default, a custom `systemPrompt`, or a custom main-thread agent that has its own prompt, though, the session starts without the git status snapshot. If you set `CLAUDE_CODE_DISABLE_ATTACHMENTS`, Claude Code also sends `@` file mentions as plain text instead of expanding them into file content. The list of available subagents and background task notifications still arrive. To stop only `@` file mentions from expanding, set [`CLAUDE_CODE_DISABLE_FILE_MENTIONS=1`](</docs/en/env-vars#variables>) instead, on Claude Code v2.1.299 or later. Claude then gets the mentioned paths plus a note to read them with its file tools. The following example is for an agent that carries its own commit rules in `append`. It sets both `attribution` keys to empty strings to remove the trailer and footer, and turns off `includeGitInstructions` so Claude Code’s own commit workflow instructions don’t compete with yours: TypeScript
modified
--- a/modifying-system-prompts.md +++ b/modifying-system-prompts.md @@ -122,7 +122,7 @@ Create an output style -An output style is a markdown file with [frontmatter](</docs/en/output-styles#frontmatter>) for metadata, followed by the prompt content. Save it to `~/.claude/output-styles/` for a user-level style available in every project, or `.claude/output-styles/` in your repository for a project-level style you can commit and share with your team. A custom output style leaves the `claude_code` preset’s software engineering instructions out and uses your own. To keep them and layer your instructions on top, set `keep-coding-instructions: true` in the frontmatter. Those instructions are only in Claude Code’s full system prompt, so the setting has no effect in a session on the shorter system prompt, which you pin on or off with [`CLAUDE_CODE_SIMPLE_SYSTEM_PROMPT`](</docs/en/env-vars#variables>). Keep them when your agent is still doing software engineering work. Leave them out when you’re replacing the role entirely. The example below defines a code-review persona that keeps the coding instructions, since reviewing code still benefits from Claude Code’s security and code-quality guidance. Save it as `~/.claude/output-styles/code-reviewer.md` to make it available across projects: +An output style is a markdown file with [frontmatter](</docs/en/output-styles#frontmatter>) for metadata, followed by the prompt content. Save it to `~/.claude/output-styles/` for a user-level style available in every project, or `.claude/output-styles/` in your repository for a project-level style you can commit and share with your team. A custom output style leaves the `claude_code` preset’s software engineering instructions out and uses your own. To keep them and layer your instructions on top, set `keep-coding-instructions: true` in the frontmatter. Those instructions are only in Claude Code’s full system prompt, so the setting has no effect in a session on the shorter system prompt; set [`CLAUDE_CODE_SIMPLE_SYSTEM_PROMPT`](</docs/en/env-vars#variables>) to `0` to select the full prompt on any model. Keep them when your agent is still doing software engineering work. Leave them out when you’re replacing the role entirely. The example below defines a code-review persona that keeps the coding instructions, since reviewing code still benefits from Claude Code’s security and code-quality guidance. Save it as `~/.claude/output-styles/code-reviewer.md` to make it available across projects: ~/.claude/output-styles/code-reviewer.md @@ -515,7 +515,7 @@ **Management**| On filesystem| CLI + files| In code| In code **Default tools**| Preserved| Preserved| Preserved| Lost (unless included) **Built-in safety**| Maintained| Maintained| Maintained| Must be added -**Customization level**| Additions only| Replace or extend default| Additions only| Complete control +**Customization level**| Additions only| Additions; can omit coding instructions| Additions only| Complete control **Version control**| With project| Yes| With code| With code **Scope**| Project-specific| User or project| Code session| Code session
modified
--- a/modifying-system-prompts.md +++ b/modifying-system-prompts.md @@ -8,8 +8,8 @@ A system prompt is the initial instruction set that shapes how Claude behaves throughout a conversation. The Agent SDK has three starting points for it: - * **Minimal default** : when you don’t set `systemPrompt` in TypeScript or `system_prompt` in Python, the SDK uses a minimal prompt that covers tool calling but omits the rest of the `claude_code` preset’s content, including its security and safety instructions and its context about the working directory and environment. This differs from `claude -p`, which uses the Claude Code system prompt by default. If you’re migrating from the CLI and want matching behavior, set the `claude_code` preset. - * **`claude_code` preset**: the system prompt that the Claude Code CLI uses, with tool usage instructions, security and safety instructions, and context about the working directory and environment. Set `systemPrompt: { type: "preset", preset: "claude_code" }` in TypeScript or `system_prompt={"type": "preset", "preset": "claude_code"}` in Python, optionally with `append` to add your own instructions on the end. + * **Minimal default** : when you don’t set `systemPrompt` in TypeScript or `system_prompt` in Python, the SDK uses a minimal prompt that covers tool calling but omits the rest of the `claude_code` preset’s content, including its security and safety instructions. This differs from `claude -p`, which uses the Claude Code system prompt by default. If you’re migrating from the CLI and want matching behavior, set the `claude_code` preset. + * **`claude_code` preset**: the system prompt that the Claude Code CLI uses, with tool usage instructions and security and safety instructions. Set `systemPrompt: { type: "preset", preset: "claude_code" }` in TypeScript or `system_prompt={"type": "preset", "preset": "claude_code"}` in Python, optionally with `append` to add your own instructions on the end. * **Custom string** : a prompt you write yourself. The SDK sends only what you provide. ### @@ -22,7 +22,7 @@ You’re building| Use| What you get ---|---|--- -A CLI or IDE-like coding tool where a human watches and steers, and Claude Code’s defaults are what you want| `claude_code` preset| The Claude Code prompt, including tool guidance, safety rules, and environment context +A CLI or IDE-like coding tool where a human watches and steers, and Claude Code’s defaults are what you want| `claude_code` preset| The Claude Code prompt, including tool guidance and safety rules The same kind of tool, plus product-specific rules like coding standards, output format, or domain context| `claude_code` preset with `append`| Everything above, with your instructions added after the preset. Nothing is removed, so this is the lowest-risk customization An agent with a different surface, identity, or permission model, or a non-coding agent| Custom prompt string| Only what you write. You take responsibility for replacing the tool guidance and safety instructions your agent still needs A thin tool-calling loop with no agent persona, where you supply all behavior in the user prompt| No `systemPrompt` option| The minimal default: tool-calling support and nothing else @@ -217,11 +217,11 @@ Improve prompt caching across users and machines -By default, two sessions that use the same `claude_code` preset and `append` text still cannot share a prompt cache entry if they run from different working directories. This is because the preset embeds per-session context in the system prompt ahead of your `append` text: the working directory, whether it’s a git repository, the platform, the active shell, the OS version, and auto memory paths. Any difference in that context produces a different system prompt and a cache miss. CLAUDE.md content doesn’t affect the system prompt cache because the SDK injects it into the conversation, not the system prompt. To make the system prompt identical across sessions, set `excludeDynamicSections: true` in TypeScript or `"exclude_dynamic_sections": True` in Python. The per-session context moves into the first user message, leaving only the static preset and your `append` text in the system prompt so identical configurations share a cache entry across users and machines. +By default, two sessions that use the same `claude_code` preset and `append` text still can’t share a prompt cache entry when their auto memory locations differ. The preset embeds that location in the system prompt ahead of your `append` text. The location defaults to an absolute path under `~/.claude/projects/` named for the repository’s path on disk, so it differs across users, machines, and checkouts. CLAUDE.md content and environment details such as the working directory, platform, shell, and OS version don’t affect the system prompt cache, because Claude Code delivers them in the conversation, not the system prompt. To make the system prompt identical across sessions, set `excludeDynamicSections: true` in TypeScript or `"exclude_dynamic_sections": True` in Python. The per-user context moves into the first user message, leaving only the static preset and your `append` text in the system prompt so identical configurations share a cache entry across users and machines. `excludeDynamicSections` requires `@anthropic-ai/claude-agent-sdk` v0.2.98 or later, or `claude-agent-sdk` v0.1.58 or later for Python. Set it on the preset object form only. The SDK ignores it when you pass a custom prompt instead of the preset; to keep a custom prompt’s instructions cached in the TypeScript SDK, see Cache the static part of a custom prompt. -The following example pairs a shared `append` block with `excludeDynamicSections` so a fleet of agents running from different directories can reuse the same cached system prompt: +The following example pairs a shared `append` block with `excludeDynamicSections` so a fleet of agents can reuse the same cached system prompt: TypeScript @@ -263,7 +263,7 @@ asyncio.run(main()) -**Tradeoffs:** the working directory, the git-repo flag, the platform, the active shell, the OS version, and auto memory paths still reach Claude, but as part of the first user message rather than the system prompt. Instructions in the user message carry marginally less weight than the same text in the system prompt, so Claude may rely on them less strongly when reasoning about the current directory or auto memory paths. Enable this option when cross-session cache reuse matters more than maximally authoritative environment context. For the equivalent flag in non-interactive CLI mode, see [`--exclude-dynamic-system-prompt-sections`](</docs/en/cli-reference>). +**Tradeoffs:** the text that moves out of the system prompt still reaches Claude, but in a user message. That text is at least the auto memory directory’s location, and often the whole auto memory section. Instructions in a user message carry marginally less weight than the same text in the system prompt, so Claude may follow its auto memory guidance less consistently. Enable this option when cross-session cache reuse matters more than that. For the equivalent flag in non-interactive CLI mode, see [`--exclude-dynamic-system-prompt-sections`](</docs/en/cli-reference>). ### @@ -515,7 +515,6 @@ **Management**| On filesystem| CLI + files| In code| In code **Default tools**| Preserved| Preserved| Preserved| Lost (unless included) **Built-in safety**| Maintained| Maintained| Maintained| Must be added -**Environment context**| Automatic| Automatic| Automatic| Must be provided **Customization level**| Additions only| Replace or extend default| Additions only| Complete control **Version control**| With project| Yes| With code| With code **Scope**| Project-specific| User or project| Code session| Code session
modified
Show diff (115 lines)
--- a/modifying-system-prompts.md +++ b/modifying-system-prompts.md @@ -393,6 +393,112 @@ Turn recording off while you iterate on wording While you iterate on prompt wording and want each edit to reach a session you resume, set `snapshot` to false on the object form of the system prompt. Claude Code then rebuilds the prompt on every request. The field is available on the preset and custom forms of [`systemPrompt`](</docs/en/agent-sdk/typescript#options>) in TypeScript and of [`system_prompt`](</docs/en/agent-sdk/python#systempromptpreset>) in Python, and requires `@anthropic-ai/claude-agent-sdk` v0.3.257 or later, or `claude-agent-sdk` v0.2.153 or later. Keep recording on in production. With recording off, a different `append` or custom prompt on a resumed session reaches Claude on the next turn, and that request can’t reuse the session’s [prompt cache](</docs/en/prompt-caching#how-the-cache-is-organized>). Where the API enforces [preserved thinking](<https://platform.claude.com/docs/en/build-with-claude/preserved-thinking>), Claude also loses its thinking from earlier turns. Outside of [cloud sessions](</docs/en/cloud-environments>), if you start Claude Code in [bare mode](</docs/en/headless#start-faster-with-bare-mode>) by passing `--bare` through `extraArgs` or setting `CLAUDE_CODE_SIMPLE=1`, recording stays off unless you set `snapshot: true`. Recording an `append` or custom prompt by default requires Claude Code v2.1.265 or later, which the TypeScript Agent SDK bundles from v0.3.265 and the Python Agent SDK from v0.2.153. Before Claude Code v2.1.268, sessions that don’t [fetch feature flags](</docs/en/env-vars#features-that-need-feature-flag-fetching>), including sessions on Amazon Bedrock, Google Cloud’s Agent Platform, and Microsoft Foundry, rebuilt the prompt on every request and `snapshot` had no effect. + +## + +​ + +Context Claude Code adds outside the system prompt + +System reminders are messages Claude Code adds to the conversation during a session to give Claude context, such as the contents of your CLAUDE.md files or a note that a file changed on disk. Claude Code sends them in the conversation, not in the system prompt, so they reach Claude whether you use the `claude_code` preset or pass your own string as `systemPrompt`. This section covers the reminders most likely to change how your agent behaves, how to turn off the ones your agent replaces, and how to see what Claude received in a specific request. + +### + +​ + +Reminders Claude Code adds to the conversation + +System reminders are text Claude Code adds to the conversation alongside the prompts your code sends. The following reminders are the ones most likely to change how your agent behaves: + + * **Project instructions** : the CLAUDE.md files that your `settingSources` option loads + * **Output style instructions** : the instructions of the active output style, in the main conversation + * **Commit and pull request attribution** : the `Co-Authored-By` trailer and pull request footer from the [`attribution`](</docs/en/settings-reference#attribution>) setting + * **Hook output** : text your [hooks](</docs/en/agent-sdk/hooks#outputs>) return as `additionalContext` + * **Available skills** : the names and descriptions of the [skills](</docs/en/agent-sdk/skills>) Claude can call + * **Available subagents** : the names and descriptions of the [subagents](</docs/en/agent-sdk/subagents>) Claude can start + * **Task list nudges** : in a [session that has the task-tracking tools](</docs/en/agent-sdk/todo-tracking#model-availability>), a prompt to update the task list when Claude hasn’t touched it for several turns + * **File-changed notes** : a note that a file Claude read earlier has changed on disk + +Claude Code introduces your CLAUDE.md files with a line telling Claude that the instructions override default behavior. If you pass your own string as `systemPrompt`, add a sentence to it that says what a system reminder is. The `claude_code` preset has one, and your string replaces the whole preset. Without it, nothing in your prompt tells Claude that reminders such as CLAUDE.md content and hook output come from the application rather than the user. For example: + + The application adds system reminders to this conversation. Treat them as context from the application, not as messages from the user. + +### + +​ + +Turn off the context your agent replaces + +Turn off a piece of built-in context when your agent supplies its own version of the same guidance. For example, if your prompt tells Claude to write commit messages as `PROJ-142: fix login redirect` with no trailers, Claude Code still tells Claude to end each commit message with a `Co-Authored-By` trailer, so Claude receives two conflicting instructions for the same commit. Pass settings keys through the [`settings`](</docs/en/agent-sdk/typescript#options>) option in TypeScript or [`settings`](</docs/en/agent-sdk/python#claudeagentoptions>) in Python, and environment variables through the `env` option. In TypeScript, [`env`](</docs/en/agent-sdk/typescript#options>) replaces the inherited environment, so spread `process.env` into it. + +Built-in context| How to turn it off +---|--- +The built-in commit and pull request instructions and the git status snapshot| Set [`includeGitInstructions`](</docs/en/settings-reference#includegitinstructions>) to `false`, or `CLAUDE_CODE_DISABLE_GIT_INSTRUCTIONS=1` +The `Co-Authored-By` trailer and the pull request footer| Set [`attribution.commit`](</docs/en/settings-reference#attribution-commit>) and [`attribution.pr`](</docs/en/settings-reference#attribution-pr>) to your own text, or to empty strings to remove them +The user or project settings source, including its CLAUDE.md| Leave `'user'` or `'project'` out of [`settingSources`](</docs/en/agent-sdk/claude-code-features#control-filesystem-settings-with-settingsources>) +Every CLAUDE.md file| Set `CLAUDE_CODE_DISABLE_CLAUDE_MDS=1` +Task list nudges, file-changed notes, and the skill list| Set `CLAUDE_CODE_DISABLE_ATTACHMENTS=1` + +Claude Code’s built-in commit and pull request instructions aren’t a reminder. They are part of the Bash tool’s description, so they also reach Claude when you pass a custom `systemPrompt`. If you set `CLAUDE_CODE_DISABLE_ATTACHMENTS`, Claude Code also sends `@` file mentions as plain text instead of expanding them into file content. The list of available subagents and background task notifications still arrive. The following example is for an agent that carries its own commit rules in `append`. It sets both `attribution` keys to empty strings to remove the trailer and footer, and turns off `includeGitInstructions` so Claude Code’s own commit workflow instructions don’t compete with yours: + +TypeScript + +Python + + import { query } from "@anthropic-ai/claude-agent-sdk"; + + for await (const message of query({ + prompt: "Commit the staged changes for ticket PROJ-142", + options: { + systemPrompt: { + type: "preset", + preset: "claude_code", + append: "Write commit messages as: <ticket id>: <summary>. Add no trailers." + }, + settings: { + includeGitInstructions: false, + attribution: { commit: "", pr: "" } + }, + allowedTools: ["Bash(git *)"] + } + })) { + if (message.type === "result") console.log(message.subtype); + } + + import asyncio + from claude_agent_sdk import query, ClaudeAgentOptions + + async def main(): + async for message in query( + prompt="Commit the staged changes for ticket PROJ-142", + options=ClaudeAgentOptions( + system_prompt={ + "type": "preset", + "preset": "claude_code", + "append": "Write commit messages as: <ticket id>: <summary>. Add no trailers.", + }, + settings='{"includeGitInstructions": false, "attribution": {"commit": "", "pr": ""}}', + allowed_tools=["Bash(git *)"], + ), + ): + print(message) + + asyncio.run(main()) + +To confirm the change, run the example in a repository with staged changes and check the new commit with `git log -1`. The message ends without a `Co-Authored-By` trailer. + +### + +​ + +See what Claude received + +The SDK message stream doesn’t include system reminders, so reading the messages your code receives won’t show you what Claude saw. To see them, log the requests Claude Code sends: + + * **Raw request logging** : set [`OTEL_LOG_RAW_API_BODIES`](</docs/en/monitoring-usage#api-request-body-event>) to `file:<dir>`. Claude Code writes each request body to that directory. + * **A gateway you control** : point [`ANTHROPIC_BASE_URL`](</docs/en/llm-gateway>) at a proxy that logs request bodies. + +In a logged request, look in the `messages` array. A reminder appears inside a user message wrapped in `<system-reminder>` tags or, on some models, as a separate message with the `system` role. ##
modified
--- a/modifying-system-prompts.md +++ b/modifying-system-prompts.md @@ -336,7 +336,7 @@ In the TypeScript SDK, you can pass a custom prompt as an array of strings instead of one string, with the `SYSTEM_PROMPT_DYNAMIC_BOUNDARY` marker between the static part and the rest. Use this when your prompt combines instructions that are the same on every request with context that changes per request, such as the customer or ticket the agent is handling. When you pass both parts as one string, a change to the per-request part changes the whole system prompt, so the static instructions miss the cache too. The array form isn’t available in the Python SDK; [`ClaudeAgentOptions`](</docs/en/agent-sdk/python#claudeagentoptions>) lists the forms `system_prompt` accepts. -The SDK splits the prompt only when it calls the Claude API directly or runs on [Claude Platform on AWS](</docs/en/claude-platform-on-aws>). In every other configuration, such as Amazon Bedrock, Google Cloud’s Agent Platform, Microsoft Foundry, or an [LLM gateway](</docs/en/llm-gateway-connect>), and whenever you set [`CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS=1`](</docs/en/llm-gateway-protocol#disable-pre-release-capabilities>), the SDK sends the whole prompt as one block, the same as passing one string. +Claude Code splits the prompt only when it calls the Claude API directly or runs on [Claude Platform on AWS](</docs/en/claude-platform-on-aws>). In every other configuration, such as Amazon Bedrock, Google Cloud’s Agent Platform, Microsoft Foundry, or an [LLM gateway](</docs/en/llm-gateway-connect>), it sends the whole prompt as one block, the same as passing one string. The same happens whenever you set [`CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS=1`](</docs/en/llm-gateway-protocol#disable-pre-release-capabilities>). To split the prompt, import `SYSTEM_PROMPT_DYNAMIC_BOUNDARY` from `@anthropic-ai/claude-agent-sdk` and pass it as its own array element between the two parts. The SDK sends the strings before the marker as one text block and the strings after it as a second block, each with its own cache breakpoint. In the example below, a support agent loads its triage instructions from a file and receives details about one ticket on each request, so the instructions stay cached while the ticket details change: @@ -364,6 +364,8 @@ * The SDK joins the strings on each side of the marker with a blank line between them and removes the marker itself, so the marker text doesn’t reach Claude. * If you include the marker more than once, the first one is the split and the SDK removes the others. * If you leave the marker out, the SDK joins all the strings into one block, the same as passing one string. + +With the CLI’s [`--system-prompt` or `--system-prompt-file` flags](</docs/en/cli-reference#system-prompt-flags>), the prompt is one string, so there is no array to carry the marker. Include a line containing only `__SYSTEM_PROMPT_DYNAMIC_BOUNDARY__` between the static and per-request parts instead. Claude Code splits the prompt at the first such line into the same two blocks and removes that line. Requires Claude Code v2.1.275 or later. In the SDK, prefer the array form, which carries the boundary without a marker line. ###
modified
--- a/modifying-system-prompts.md +++ b/modifying-system-prompts.md @@ -148,7 +148,7 @@ Once created, activate output styles via: - * **CLI** : run `/config` and select an output style + * **CLI** : run `/output-style <style>`, for example `/output-style concise`, or run `/config` and select one. The `/output-style` command requires Claude Code v2.1.269 or later. * **Settings** : set `outputStyle` in `.claude/settings.local.json` * **TypeScript SDK** : set `outputStyle` inside the inline `settings` object passed to `query()`, or point `settings` at a settings file that sets it. `outputStyle` is not a top-level `Options` field:
modified
--- a/modifying-system-prompts.md +++ b/modifying-system-prompts.md @@ -334,7 +334,7 @@ Cache the static part of a custom prompt -In the TypeScript SDK, you can pass a custom prompt as an array of strings instead of one string, with the `SYSTEM_PROMPT_DYNAMIC_BOUNDARY` marker between the static part and the rest. Use this when your prompt combines instructions that are the same on every request with context that changes per request, such as the customer or ticket the agent is handling. When you pass both parts as one string, a change to the per-request part changes the whole system prompt, so the static instructions miss the cache too. This form isn’t available in the Python SDK, whose `system_prompt` option accepts a string, a preset, or a [file](</docs/en/agent-sdk/python#systempromptfile>). +In the TypeScript SDK, you can pass a custom prompt as an array of strings instead of one string, with the `SYSTEM_PROMPT_DYNAMIC_BOUNDARY` marker between the static part and the rest. Use this when your prompt combines instructions that are the same on every request with context that changes per request, such as the customer or ticket the agent is handling. When you pass both parts as one string, a change to the per-request part changes the whole system prompt, so the static instructions miss the cache too. The array form isn’t available in the Python SDK; [`ClaudeAgentOptions`](</docs/en/agent-sdk/python#claudeagentoptions>) lists the forms `system_prompt` accepts. The SDK splits the prompt only when it calls the Claude API directly or runs on [Claude Platform on AWS](</docs/en/claude-platform-on-aws>). In every other configuration, such as Amazon Bedrock, Google Cloud’s Agent Platform, Microsoft Foundry, or an [LLM gateway](</docs/en/llm-gateway-connect>), and whenever you set [`CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS=1`](</docs/en/llm-gateway-protocol#disable-pre-release-capabilities>), the SDK sends the whole prompt as one block, the same as passing one string. @@ -371,7 +371,26 @@ Change the prompt of an existing session -By default, Claude Code builds the system prompt once, on a session’s first request, with your `append` text or custom prompt included, and records it in the session. Until the session is compacted, every later request uses that recorded prompt, including after you return to the session with `resume` or `continue`. If you pass a different `append` or custom prompt on that later call, it takes effect once the session is compacted or in a new session. If you start Claude Code in [bare mode](</docs/en/headless#start-faster-with-bare-mode>) by passing `--bare` through `extraArgs` or setting `CLAUDE_CODE_SIMPLE=1`, recording stays off unless you set `snapshot: true` on the object form of `systemPrompt`. Recording an `append` or custom prompt by default requires Claude Code v2.1.265 or later, which the TypeScript Agent SDK bundles from v0.3.265. Before Claude Code v2.1.268, sessions that don’t [fetch feature flags](</docs/en/env-vars#features-that-need-feature-flag-fetching>), including sessions on Amazon Bedrock, Google Cloud’s Agent Platform, and Microsoft Foundry, rebuilt the prompt on every request and `snapshot` had no effect. To rebuild the prompt on every request instead, set `snapshot: false` on the object form of `systemPrompt` in the TypeScript SDK: `{ type: "preset", preset: "claude_code", append, snapshot: false }` or `{ type: "custom", prompt, snapshot: false }`. Use this form while you iterate on prompt wording, or when your application changes `append` between calls that resume the same session. The `snapshot` field requires `@anthropic-ai/claude-agent-sdk` v0.3.257 or later. +By default, if you pass a different `append` or custom prompt when you return to a session with `resume` or `continue`, Claude doesn’t see it on the next turn. Claude Code records the system prompt on a session’s first request and reuses that record until the session is compacted. The new text takes effect after that compaction, or in a new session. + +#### + +​ + +Update Claude’s instructions mid-session + +If the instructions you put in the system prompt need to change while a session is running, for example because your user switched the agent to a read-only mode or edited its configuration in your app, send the new instructions in the conversation instead of changing `systemPrompt`: + + * **In your next message** : include the new instructions in the next user message you send. + * **From a hook** : return [`additionalContext`](</docs/en/hooks#add-context-for-claude>) from a `UserPromptSubmit` or `PostToolUse` [hook callback](</docs/en/agent-sdk/hooks#outputs>), written as a factual statement such as “The workspace is now read-only”. The SDK inserts the text into the conversation at the point where the hook fired, so the recorded prompt stays unchanged. + +#### + +​ + +Turn recording off while you iterate on wording + +While you iterate on prompt wording and want each edit to reach a session you resume, set `snapshot` to false on the object form of the system prompt. Claude Code then rebuilds the prompt on every request. The field is available on the preset and custom forms of [`systemPrompt`](</docs/en/agent-sdk/typescript#options>) in TypeScript and of [`system_prompt`](</docs/en/agent-sdk/python#systempromptpreset>) in Python, and requires `@anthropic-ai/claude-agent-sdk` v0.3.257 or later, or `claude-agent-sdk` v0.2.153 or later. Keep recording on in production. With recording off, a different `append` or custom prompt on a resumed session reaches Claude on the next turn, and that request can’t reuse the session’s [prompt cache](</docs/en/prompt-caching#how-the-cache-is-organized>). Where the API enforces [preserved thinking](<https://platform.claude.com/docs/en/build-with-claude/preserved-thinking>), Claude also loses its thinking from earlier turns. Outside of [cloud sessions](</docs/en/cloud-environments>), if you start Claude Code in [bare mode](</docs/en/headless#start-faster-with-bare-mode>) by passing `--bare` through `extraArgs` or setting `CLAUDE_CODE_SIMPLE=1`, recording stays off unless you set `snapshot: true`. Recording an `append` or custom prompt by default requires Claude Code v2.1.265 or later, which the TypeScript Agent SDK bundles from v0.3.265 and the Python Agent SDK from v0.2.153. Before Claude Code v2.1.268, sessions that don’t [fetch feature flags](</docs/en/env-vars#features-that-need-feature-flag-fetching>), including sessions on Amazon Bedrock, Google Cloud’s Agent Platform, and Microsoft Foundry, rebuilt the prompt on every request and `snapshot` had no effect. ##
modified
--- a/modifying-system-prompts.md +++ b/modifying-system-prompts.md @@ -154,7 +154,7 @@ const options = { settings: { outputStyle: "Explanatory" } }; -The Python SDK does not have an option to select an output style programmatically. For code-only deployments where you can’t write to `.claude/settings.local.json`, use `append` or a custom prompt string instead. **Note for SDK users:** Output styles are loaded when you include `settingSources: ['user']` or `settingSources: ['project']` (TypeScript) / `setting_sources=["user"]` or `setting_sources=["project"]` (Python) in your options. +In the Python SDK, set `outputStyle` through the `settings` option, which takes a JSON string such as `'{"outputStyle": "Explanatory"}'` or a path to a settings file that sets it. **Note for SDK users:** Output styles are loaded when you include `settingSources: ['user']` or `settingSources: ['project']` (TypeScript) / `setting_sources=["user"]` or `setting_sources=["project"]` (Python) in your options. ###
modified
--- a/modifying-system-prompts.md +++ b/modifying-system-prompts.md @@ -371,7 +371,7 @@ Change the prompt of an existing session -By default, Claude Code builds the system prompt once, on a session’s first request, with your `append` text or custom prompt included, and records it in the session. Until the session is compacted, every later request uses that recorded prompt, including after you return to the session with `resume` or `continue`. If you pass a different `append` or custom prompt on that later call, it takes effect once the session is compacted or in a new session. Recording applies in sessions that [fetch feature flags](</docs/en/env-vars#features-that-need-feature-flag-fetching>), as sessions using a claude.ai or Console account do by default. On Amazon Bedrock, Google Cloud’s Agent Platform, Microsoft Foundry, and in other sessions that don’t fetch them, Claude Code rebuilds the prompt on every request. If you start Claude Code in [bare mode](</docs/en/headless#start-faster-with-bare-mode>) by passing `--bare` through `extraArgs` or setting `CLAUDE_CODE_SIMPLE=1`, recording stays off unless you set `snapshot: true` on the object form of `systemPrompt`. Recording an `append` or custom prompt by default requires Claude Code v2.1.265 or later, which the TypeScript Agent SDK bundles from v0.3.265. To rebuild the prompt on every request instead, set `snapshot: false` on the object form of `systemPrompt` in the TypeScript SDK: `{ type: "preset", preset: "claude_code", append, snapshot: false }` or `{ type: "custom", prompt, snapshot: false }`. Use this form while you iterate on prompt wording, or when your application changes `append` between calls that resume the same session. The `snapshot` field requires `@anthropic-ai/claude-agent-sdk` v0.3.257 or later and has no effect in sessions that don’t fetch feature flags. +By default, Claude Code builds the system prompt once, on a session’s first request, with your `append` text or custom prompt included, and records it in the session. Until the session is compacted, every later request uses that recorded prompt, including after you return to the session with `resume` or `continue`. If you pass a different `append` or custom prompt on that later call, it takes effect once the session is compacted or in a new session. If you start Claude Code in [bare mode](</docs/en/headless#start-faster-with-bare-mode>) by passing `--bare` through `extraArgs` or setting `CLAUDE_CODE_SIMPLE=1`, recording stays off unless you set `snapshot: true` on the object form of `systemPrompt`. Recording an `append` or custom prompt by default requires Claude Code v2.1.265 or later, which the TypeScript Agent SDK bundles from v0.3.265. Before Claude Code v2.1.268, sessions that don’t [fetch feature flags](</docs/en/env-vars#features-that-need-feature-flag-fetching>), including sessions on Amazon Bedrock, Google Cloud’s Agent Platform, and Microsoft Foundry, rebuilt the prompt on every request and `snapshot` had no effect. To rebuild the prompt on every request instead, set `snapshot: false` on the object form of `systemPrompt` in the TypeScript SDK: `{ type: "preset", preset: "claude_code", append, snapshot: false }` or `{ type: "custom", prompt, snapshot: false }`. Use this form while you iterate on prompt wording, or when your application changes `append` between calls that resume the same session. The `snapshot` field requires `@anthropic-ai/claude-agent-sdk` v0.3.257 or later. ##
modified
--- a/modifying-system-prompts.md +++ b/modifying-system-prompts.md @@ -42,7 +42,7 @@ Customize agent behavior -Output styles, `append`, and a custom prompt string each change the system prompt directly. CLAUDE.md takes a different path: the SDK reads it and injects its content into the conversation as project context, not into the system prompt, so it shapes behavior alongside whichever system prompt you choose. [Skills](</docs/en/agent-sdk/skills>), [hooks](</docs/en/agent-sdk/hooks>), and [permissions](</docs/en/agent-sdk/permissions>) also shape behavior outside the system prompt and are covered on their own pages. +`append` and a custom prompt string each change the system prompt directly, and an output style changes the instructions Claude Code gives Claude for every response. CLAUDE.md takes a different path: the SDK reads it and injects its content into the conversation as project context, so it shapes behavior alongside whichever system prompt you choose. [Skills](</docs/en/agent-sdk/skills>), [hooks](</docs/en/agent-sdk/hooks>), and [permissions](</docs/en/agent-sdk/permissions>) also shape behavior outside the system prompt and are covered on their own pages. ### @@ -114,7 +114,7 @@ Output styles for persistent configurations -Output styles are saved configurations that modify Claude’s system prompt. They’re stored as markdown files and can be reused across sessions and projects. +Output styles are saved sets of instructions that change Claude’s role, tone, and output format. They’re stored as markdown files and can be reused across sessions and projects. #### @@ -364,6 +364,14 @@ * The SDK joins the strings on each side of the marker with a blank line between them and removes the marker itself, so the marker text doesn’t reach Claude. * If you include the marker more than once, the first one is the split and the SDK removes the others. * If you leave the marker out, the SDK joins all the strings into one block, the same as passing one string. + +### + +​ + +Change the prompt of an existing session + +By default, Claude Code builds the system prompt once, on a session’s first request, with your `append` text or custom prompt included, and records it in the session. Until the session is compacted, every later request uses that recorded prompt, including after you return to the session with `resume` or `continue`. If you pass a different `append` or custom prompt on that later call, it takes effect once the session is compacted or in a new session. Recording applies in sessions that [fetch feature flags](</docs/en/env-vars#features-that-need-feature-flag-fetching>), as sessions using a claude.ai or Console account do by default. On Amazon Bedrock, Google Cloud’s Agent Platform, Microsoft Foundry, and in other sessions that don’t fetch them, Claude Code rebuilds the prompt on every request. If you start Claude Code in [bare mode](</docs/en/headless#start-faster-with-bare-mode>) by passing `--bare` through `extraArgs` or setting `CLAUDE_CODE_SIMPLE=1`, recording stays off unless you set `snapshot: true` on the object form of `systemPrompt`. Recording an `append` or custom prompt by default requires Claude Code v2.1.265 or later, which the TypeScript Agent SDK bundles from v0.3.265. To rebuild the prompt on every request instead, set `snapshot: false` on the object form of `systemPrompt` in the TypeScript SDK: `{ type: "preset", preset: "claude_code", append, snapshot: false }` or `{ type: "custom", prompt, snapshot: false }`. Use this form while you iterate on prompt wording, or when your application changes `append` between calls that resume the same session. The `snapshot` field requires `@anthropic-ai/claude-agent-sdk` v0.3.257 or later and has no effect in sessions that don’t fetch feature flags. ##
modified
--- a/modifying-system-prompts.md +++ b/modifying-system-prompts.md @@ -219,7 +219,7 @@ By default, two sessions that use the same `claude_code` preset and `append` text still cannot share a prompt cache entry if they run from different working directories. This is because the preset embeds per-session context in the system prompt ahead of your `append` text: the working directory, whether it’s a git repository, the platform, the active shell, the OS version, and auto memory paths. Any difference in that context produces a different system prompt and a cache miss. CLAUDE.md content doesn’t affect the system prompt cache because the SDK injects it into the conversation, not the system prompt. To make the system prompt identical across sessions, set `excludeDynamicSections: true` in TypeScript or `"exclude_dynamic_sections": True` in Python. The per-session context moves into the first user message, leaving only the static preset and your `append` text in the system prompt so identical configurations share a cache entry across users and machines. -`excludeDynamicSections` requires `@anthropic-ai/claude-agent-sdk` v0.2.98 or later, or `claude-agent-sdk` v0.1.58 or later for Python. It applies only to the preset object form and has no effect when `systemPrompt` is a string. +`excludeDynamicSections` requires `@anthropic-ai/claude-agent-sdk` v0.2.98 or later, or `claude-agent-sdk` v0.1.58 or later for Python. Set it on the preset object form only. The SDK ignores it when you pass a custom prompt instead of the preset; to keep a custom prompt’s instructions cached in the TypeScript SDK, see Cache the static part of a custom prompt. The following example pairs a shared `append` block with `excludeDynamicSections` so a fleet of agents running from different directories can reuse the same cached system prompt: @@ -327,6 +327,43 @@ asyncio.run(main()) In Python, load a large custom prompt from a file with `system_prompt={"type": "file", "path": "..."}` instead of passing it as a string. The Python SDK passes a string prompt as one command-line argument to the CLI subprocess, so a prompt that exceeds the OS argument-length limit fails at process spawn before any API request is sent. On Linux the error is `Argument list too long`. See [`SystemPromptFile`](</docs/en/agent-sdk/python#systempromptfile>) for the platform thresholds and the Windows behavior. + +#### + +​ + +Cache the static part of a custom prompt + +In the TypeScript SDK, you can pass a custom prompt as an array of strings instead of one string, with the `SYSTEM_PROMPT_DYNAMIC_BOUNDARY` marker between the static part and the rest. Use this when your prompt combines instructions that are the same on every request with context that changes per request, such as the customer or ticket the agent is handling. When you pass both parts as one string, a change to the per-request part changes the whole system prompt, so the static instructions miss the cache too. This form isn’t available in the Python SDK, whose `system_prompt` option accepts a string, a preset, or a [file](</docs/en/agent-sdk/python#systempromptfile>). + +The SDK splits the prompt only when it calls the Claude API directly or runs on [Claude Platform on AWS](</docs/en/claude-platform-on-aws>). In every other configuration, such as Amazon Bedrock, Google Cloud’s Agent Platform, Microsoft Foundry, or an [LLM gateway](</docs/en/llm-gateway-connect>), and whenever you set [`CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS=1`](</docs/en/llm-gateway-protocol#disable-pre-release-capabilities>), the SDK sends the whole prompt as one block, the same as passing one string. + +To split the prompt, import `SYSTEM_PROMPT_DYNAMIC_BOUNDARY` from `@anthropic-ai/claude-agent-sdk` and pass it as its own array element between the two parts. The SDK sends the strings before the marker as one text block and the strings after it as a second block, each with its own cache breakpoint. In the example below, a support agent loads its triage instructions from a file and receives details about one ticket on each request, so the instructions stay cached while the ticket details change: + +TypeScript + + import { readFile } from "node:fs/promises"; + import { query, SYSTEM_PROMPT_DYNAMIC_BOUNDARY } from "@anthropic-ai/claude-agent-sdk"; + + // Identical on every request + const instructions = await readFile("triage-instructions.md", "utf8"); + // Different on every request + const ticketContext = "Customer plan: Enterprise. Other open tickets from this customer: 3."; + + for await (const message of query({ + prompt: "Triage ticket 4821", + options: { + systemPrompt: [instructions, SYSTEM_PROMPT_DYNAMIC_BOUNDARY, ticketContext] + } + })) { + // ... + } + +[Track cache tokens](</docs/en/agent-sdk/cost-tracking#track-cache-tokens>) describes the `cache_creation_input_tokens` and `cache_read_input_tokens` fields on each result message. The SDK assembles the blocks from the array as follows: + + * The SDK joins the strings on each side of the marker with a blank line between them and removes the marker itself, so the marker text doesn’t reach Claude. + * If you include the marker more than once, the first one is the split and the SDK removes the others. + * If you leave the marker out, the SDK joins all the strings into one block, the same as passing one string. ##
modified
--- a/modifying-system-prompts.md +++ b/modifying-system-prompts.md @@ -122,7 +122,7 @@ Create an output style -An output style is a markdown file with [frontmatter](</docs/en/output-styles#frontmatter>) for metadata, followed by the prompt content. Save it to `~/.claude/output-styles/` for a user-level style available in every project, or `.claude/output-styles/` in your repository for a project-level style you can commit and share with your team. By default, a custom output style replaces the `claude_code` preset’s software engineering instructions with your own. To keep them and layer your instructions on top, set `keep-coding-instructions: true` in the frontmatter. Keep them when your agent is still doing software engineering work. Leave them out when you’re replacing the role entirely. The example below defines a code-review persona that keeps the coding instructions, since reviewing code still benefits from Claude Code’s security and code-quality guidance. Save it as `~/.claude/output-styles/code-reviewer.md` to make it available across projects: +An output style is a markdown file with [frontmatter](</docs/en/output-styles#frontmatter>) for metadata, followed by the prompt content. Save it to `~/.claude/output-styles/` for a user-level style available in every project, or `.claude/output-styles/` in your repository for a project-level style you can commit and share with your team. A custom output style leaves the `claude_code` preset’s software engineering instructions out and uses your own. To keep them and layer your instructions on top, set `keep-coding-instructions: true` in the frontmatter. Those instructions are only in Claude Code’s full system prompt, so the setting has no effect in a session on the shorter system prompt, which you pin on or off with [`CLAUDE_CODE_SIMPLE_SYSTEM_PROMPT`](</docs/en/env-vars#variables>). Keep them when your agent is still doing software engineering work. Leave them out when you’re replacing the role entirely. The example below defines a code-review persona that keeps the coding instructions, since reviewing code still benefits from Claude Code’s security and code-quality guidance. Save it as `~/.claude/output-styles/code-reviewer.md` to make it available across projects: ~/.claude/output-styles/code-reviewer.md
modified
--- a/modifying-system-prompts.md +++ b/modifying-system-prompts.md @@ -8,8 +8,8 @@ A system prompt is the initial instruction set that shapes how Claude behaves throughout a conversation. The Agent SDK has three starting points for it: - * **Minimal default** : when you don’t set `systemPrompt` in TypeScript or `system_prompt` in Python, the SDK uses a minimal prompt that covers tool calling but omits Claude Code’s coding guidelines, response style, and project context. This differs from `claude -p`, which uses the full Claude Code prompt by default. If you’re migrating from the CLI and want matching behavior, set the `claude_code` preset. - * **`claude_code` preset**: the full system prompt that the Claude Code CLI uses, with tool usage instructions, code style and formatting guidelines, response tone and verbosity rules, security and safety instructions, and context about the working directory and environment. Set `systemPrompt: { type: "preset", preset: "claude_code" }` in TypeScript or `system_prompt={"type": "preset", "preset": "claude_code"}` in Python, optionally with `append` to add your own instructions on the end. + * **Minimal default** : when you don’t set `systemPrompt` in TypeScript or `system_prompt` in Python, the SDK uses a minimal prompt that covers tool calling but omits the rest of the `claude_code` preset’s content, including its security and safety instructions and its context about the working directory and environment. This differs from `claude -p`, which uses the Claude Code system prompt by default. If you’re migrating from the CLI and want matching behavior, set the `claude_code` preset. + * **`claude_code` preset**: the system prompt that the Claude Code CLI uses, with tool usage instructions, security and safety instructions, and context about the working directory and environment. Set `systemPrompt: { type: "preset", preset: "claude_code" }` in TypeScript or `system_prompt={"type": "preset", "preset": "claude_code"}` in Python, optionally with `append` to add your own instructions on the end. * **Custom string** : a prompt you write yourself. The SDK sends only what you provide. ### @@ -22,7 +22,7 @@ You’re building| Use| What you get ---|---|--- -A CLI or IDE-like coding tool where a human watches and steers, and Claude Code’s defaults are what you want| `claude_code` preset| The full Claude Code prompt: tool guidance, safety rules, terminal-friendly responses, repo-convention awareness +A CLI or IDE-like coding tool where a human watches and steers, and Claude Code’s defaults are what you want| `claude_code` preset| The Claude Code prompt, including tool guidance, safety rules, and environment context The same kind of tool, plus product-specific rules like coding standards, output format, or domain context| `claude_code` preset with `append`| Everything above, with your instructions added after the preset. Nothing is removed, so this is the lowest-risk customization An agent with a different surface, identity, or permission model, or a non-coding agent| Custom prompt string| Only what you write. You take responsibility for replacing the tool guidance and safety instructions your agent still needs A thin tool-calling loop with no agent persona, where you supply all behavior in the user prompt| No `systemPrompt` option| The minimal default: tool-calling support and nothing else @@ -58,7 +58,7 @@ Load CLAUDE.md with the SDK -To load CLAUDE.md, set `settingSources` to include the level your CLAUDE.md lives at. The example below loads a project-level CLAUDE.md alongside the `claude_code` preset, so Claude has both the full coding-agent prompt and your project’s conventions: +To load CLAUDE.md, set `settingSources` to include the level where you keep your CLAUDE.md. The example below loads a project-level CLAUDE.md alongside the `claude_code` preset, so Claude has both the coding-agent prompt and your project’s conventions: TypeScript
modified
--- a/modifying-system-prompts.md +++ b/modifying-system-prompts.md @@ -356,7 +356,7 @@ Combine approaches -These methods compose. A persistent output style or CLAUDE.md sets the long-lived behavior, and `append` layers session-specific instructions on top without touching the saved configuration. +The approaches compose. A persistent output style or CLAUDE.md sets the long-lived behavior, and `append` layers session-specific instructions on top without touching the saved configuration. ###
modified
--- a/modifying-system-prompts.md +++ b/modifying-system-prompts.md @@ -50,7 +50,7 @@ CLAUDE.md files for project-level instructions -CLAUDE.md files give Claude persistent project context and instructions. The SDK injects their content into the conversation, not into the system prompt, so they work with any system prompt configuration. For what to put in CLAUDE.md, where to place it, and how to write effective instructions, see [How Claude remembers your project](</docs/en/memory>). This section covers what’s specific to the SDK: how CLAUDE.md loads. The SDK reads CLAUDE.md when the matching setting source is enabled: `'project'` loads `CLAUDE.md` or `.claude/CLAUDE.md` from the working directory, and `'user'` loads `~/.claude/CLAUDE.md`. Default `query()` options enable both sources, so CLAUDE.md loads automatically. If you set `settingSources` in TypeScript or `setting_sources` in Python explicitly, include the sources you need. CLAUDE.md loading is controlled by setting sources, not by the `claude_code` preset. +CLAUDE.md files give Claude persistent project context and instructions. The SDK injects their content into the conversation and leaves the system prompt untouched, so they work with any system prompt configuration. For what to put in CLAUDE.md, where to place it, and how to write effective instructions, see [When to add to CLAUDE.md](</docs/en/memory#when-to-add-to-claude-md>) and the rest of [How Claude remembers your project](</docs/en/memory>). This section covers what’s specific to the SDK: how CLAUDE.md loads. The SDK reads CLAUDE.md when the matching setting source is enabled: `'project'` loads `CLAUDE.md` or `.claude/CLAUDE.md` from the working directory, and `'user'` loads `~/.claude/CLAUDE.md`. Default `query()` options enable both sources, so CLAUDE.md loads automatically. If you set `settingSources` in TypeScript or `setting_sources` in Python explicitly, include the sources you need. CLAUDE.md loading is controlled by setting sources, not by the `claude_code` preset. #### @@ -217,7 +217,7 @@ Improve prompt caching across users and machines -By default, two sessions that use the same `claude_code` preset and `append` text still cannot share a prompt cache entry if they run from different working directories. This is because the preset embeds per-session context in the system prompt ahead of your `append` text: the working directory, whether it’s a git repository, the platform, the active shell, the OS version, and auto-memory paths. Any difference in that context produces a different system prompt and a cache miss. CLAUDE.md content doesn’t affect the system prompt cache because the SDK injects it into the conversation, not the system prompt. To make the system prompt identical across sessions, set `excludeDynamicSections: true` in TypeScript or `"exclude_dynamic_sections": True` in Python. The per-session context moves into the first user message, leaving only the static preset and your `append` text in the system prompt so identical configurations share a cache entry across users and machines. +By default, two sessions that use the same `claude_code` preset and `append` text still cannot share a prompt cache entry if they run from different working directories. This is because the preset embeds per-session context in the system prompt ahead of your `append` text: the working directory, whether it’s a git repository, the platform, the active shell, the OS version, and auto memory paths. Any difference in that context produces a different system prompt and a cache miss. CLAUDE.md content doesn’t affect the system prompt cache because the SDK injects it into the conversation, not the system prompt. To make the system prompt identical across sessions, set `excludeDynamicSections: true` in TypeScript or `"exclude_dynamic_sections": True` in Python. The per-session context moves into the first user message, leaving only the static preset and your `append` text in the system prompt so identical configurations share a cache entry across users and machines. `excludeDynamicSections` requires `@anthropic-ai/claude-agent-sdk` v0.2.98 or later, or `claude-agent-sdk` v0.1.58 or later for Python. It applies only to the preset object form and has no effect when `systemPrompt` is a string. @@ -263,7 +263,7 @@ asyncio.run(main()) -**Tradeoffs:** the working directory, the git-repo flag, the platform, the active shell, the OS version, and auto-memory paths still reach Claude, but as part of the first user message rather than the system prompt. Instructions in the user message carry marginally less weight than the same text in the system prompt, so Claude may rely on them less strongly when reasoning about the current directory or auto-memory paths. Enable this option when cross-session cache reuse matters more than maximally authoritative environment context. For the equivalent flag in non-interactive CLI mode, see [`--exclude-dynamic-system-prompt-sections`](</docs/en/cli-reference>). +**Tradeoffs:** the working directory, the git-repo flag, the platform, the active shell, the OS version, and auto memory paths still reach Claude, but as part of the first user message rather than the system prompt. Instructions in the user message carry marginally less weight than the same text in the system prompt, so Claude may rely on them less strongly when reasoning about the current directory or auto memory paths. Enable this option when cross-session cache reuse matters more than maximally authoritative environment context. For the equivalent flag in non-interactive CLI mode, see [`--exclude-dynamic-system-prompt-sections`](</docs/en/cli-reference>). ### @@ -349,67 +349,6 @@ **Scope**| Project-specific| User or project| Code session| Code session “With append” means using `systemPrompt: { type: "preset", preset: "claude_code", append: "..." }` in TypeScript or `system_prompt={"type": "preset", "preset": "claude_code", "append": "..."}` in Python. CLAUDE.md doesn’t change the system prompt itself: the SDK injects its content into the conversation as project context. - -## - -​ - -Use cases and best practices - -### - -​ - -When to use CLAUDE.md - -Use CLAUDE.md for instructions that should apply to every session in a project, regardless of which system prompt the session uses: coding standards, common commands, architecture context, and team conventions. CLAUDE.md is committed to your repository, so it stays in sync with the code it describes. See [When to add to CLAUDE.md](</docs/en/memory#when-to-add-to-claude-md>) for full guidance. - -### - -​ - -When to use output styles - -Output styles are for personas you want to reuse across the CLI and SDK without changing application code. Because they live as files in `.claude/output-styles`, the same persona is available from `/config` in the CLI and from any SDK session that loads the matching setting source. **Best for:** - - * Persistent behavior changes across sessions - * Team-shared configurations - * Specialized assistants like a code reviewer, data scientist, or DevOps assistant - * Complex prompt modifications that need versioning - -**Examples:** - - * Creating a dedicated SQL optimization assistant - * Building a security-focused code reviewer - * Developing a teaching assistant with specific pedagogy - -### - -​ - -When to use `systemPrompt` with append - -Use `append` when the `claude_code` preset already fits your product and you only need to layer in extra instructions. You keep the preset’s tool guidance, safety rules, and coding conventions without reimplementing them. **Best for:** - - * Adding specific coding standards or preferences - * Customizing output formatting - * Adding domain-specific knowledge - * Modifying response verbosity - * Enhancing Claude Code’s default behavior without losing tool instructions - -### - -​ - -When to use custom `systemPrompt` - -Use a custom prompt when your agent’s surface, identity, or permission model differs from Claude Code’s, as described in Decide on a starting point. You define the full instruction set, including any tool guidance and safety rules your agent needs. **Best for:** - - * Complete control over Claude’s behavior - * Specialized single-session tasks - * Testing new prompt strategies - * Situations where default tools aren’t needed - * Building specialized agents with unique behavior ##
modified
--- a/modifying-system-prompts.md +++ b/modifying-system-prompts.md @@ -1,9 +1,4 @@ -System prompts define Claude’s behavior, capabilities, and response style. Start from the `claude_code` preset for CLI or IDE-like coding tools where a human watches and steers the work. Write your own prompt for agents with a different surface, identity, or permission model. This page covers: - - * How system prompts work, with a decision table for choosing between the preset, the preset with `append`, and a custom prompt - * Customize agent behavior with CLAUDE.md files, output styles, `append`, or a custom string - * Compare the four approaches by persistence, scope, and what they preserve - * Combine approaches to layer customization methods together +System prompts define Claude’s behavior, capabilities, and response style. Start from the `claude_code` preset for CLI or IDE-like coding tools where a human watches and steers the work. Write your own prompt for agents with a different surface, identity, or permission model. ## @@ -367,7 +362,7 @@ When to use CLAUDE.md -Use CLAUDE.md for instructions that should apply to every session in a project, regardless of which system prompt the session uses: coding standards, common commands, architecture context, and team conventions. CLAUDE.md is committed to your repository, so it stays in sync with the code it describes. See [When to add to CLAUDE.md](</docs/en/memory#when-to-add-to-claude-md>) for full guidance. CLAUDE.md files load when the `project` setting source is enabled, which it is for default `query()` options. If you set `settingSources` in TypeScript or `setting_sources` in Python explicitly, include `'project'` to keep loading project-level CLAUDE.md. +Use CLAUDE.md for instructions that should apply to every session in a project, regardless of which system prompt the session uses: coding standards, common commands, architecture context, and team conventions. CLAUDE.md is committed to your repository, so it stays in sync with the code it describes. See [When to add to CLAUDE.md](</docs/en/memory#when-to-add-to-claude-md>) for full guidance. ###
modified
Show diff (210 lines)
--- a/modifying-system-prompts.md +++ b/modifying-system-prompts.md @@ -88,25 +88,30 @@ // Now Claude has access to your project guidelines from CLAUDE.md + import asyncio + from claude_agent_sdk import query, ClaudeAgentOptions messages = [] - async for message in query( - prompt="Add a new React component for user profiles", - options=ClaudeAgentOptions( - system_prompt={ - "type": "preset", - "preset": "claude_code", # Use Claude Code's system prompt - }, - setting_sources=["project"], # Loads CLAUDE.md from project - ), - ): - messages.append(message) + async def main(): + async for message in query( + prompt="Add a new React component for user profiles", + options=ClaudeAgentOptions( + system_prompt={ + "type": "preset", + "preset": "claude_code", # Use Claude Code's system prompt + }, + setting_sources=["project"], # Loads CLAUDE.md from project + ), + ): + messages.append(message) + + asyncio.run(main()) # Now Claude has access to your project guidelines from CLAUDE.md -CLAUDE.md is persistent across all sessions in a project, shared with your team through git, and discovered automatically without code changes. It is not loaded if you pass an empty `settingSources` array. +When you run either example, the SDK streams messages as Claude works: a system init message, assistant messages, user messages carrying tool results, and a final result message with the session outcome. CLAUDE.md is persistent across all sessions in a project, shared with your team through git, and discovered automatically without code changes. It is not loaded if you pass an empty `settingSources` array. ### @@ -188,23 +193,28 @@ } } + import asyncio + from claude_agent_sdk import query, ClaudeAgentOptions, AssistantMessage messages = [] - async for message in query( - prompt="Help me write a Python function to calculate fibonacci numbers", - options=ClaudeAgentOptions( - system_prompt={ - "type": "preset", - "preset": "claude_code", - "append": "Always include detailed docstrings and type hints in Python code.", - } - ), - ): - messages.append(message) - if isinstance(message, AssistantMessage): - print(message.content) + async def main(): + async for message in query( + prompt="Help me write a Python function to calculate fibonacci numbers", + options=ClaudeAgentOptions( + system_prompt={ + "type": "preset", + "preset": "claude_code", + "append": "Always include detailed docstrings and type hints in Python code.", + } + ), + ): + messages.append(message) + if isinstance(message, AssistantMessage): + print(message.content) + + asyncio.run(main()) #### @@ -238,20 +248,25 @@ // ... } + import asyncio + from claude_agent_sdk import query, ClaudeAgentOptions - async for message in query( - prompt="Triage the open issues in this repo", - options=ClaudeAgentOptions( - system_prompt={ - "type": "preset", - "preset": "claude_code", - "append": "You operate Acme's internal triage workflow. Label issues by component and severity.", - "exclude_dynamic_sections": True, - }, - ), - ): - ... + async def main(): + async for message in query( + prompt="Triage the open issues in this repo", + options=ClaudeAgentOptions( + system_prompt={ + "type": "preset", + "preset": "claude_code", + "append": "You operate Acme's internal triage workflow. Label issues by component and severity.", + "exclude_dynamic_sections": True, + }, + ), + ): + ... + + asyncio.run(main()) **Tradeoffs:** the working directory, the git-repo flag, the platform, the active shell, the OS version, and auto-memory paths still reach Claude, but as part of the first user message rather than the system prompt. Instructions in the user message carry marginally less weight than the same text in the system prompt, so Claude may rely on them less strongly when reasoning about the current directory or auto-memory paths. Enable this option when cross-session cache reuse matters more than maximally authoritative environment context. For the equivalent flag in non-interactive CLI mode, see [`--exclude-dynamic-system-prompt-sections`](</docs/en/cli-reference>). @@ -291,6 +306,8 @@ } } + import asyncio + from claude_agent_sdk import query, ClaudeAgentOptions, AssistantMessage custom_prompt = """You are a Python coding specialist. @@ -303,13 +320,18 @@ messages = [] - async for message in query( - prompt="Create a data processing pipeline", - options=ClaudeAgentOptions(system_prompt=custom_prompt), - ): - messages.append(message) - if isinstance(message, AssistantMessage): - print(message.content) + async def main(): + async for message in query( + prompt="Create a data processing pipeline", + options=ClaudeAgentOptions(system_prompt=custom_prompt), + ): + messages.append(message) + if isinstance(message, AssistantMessage): + print(message.content) + + asyncio.run(main()) + +In Python, load a large custom prompt from a file with `system_prompt={"type": "file", "path": "..."}` instead of passing it as a string. The Python SDK passes a string prompt as one command-line argument to the CLI subprocess, so a prompt that exceeds the OS argument-length limit fails at process spawn before any API request is sent. On Linux the error is `Argument list too long`. See [`SystemPromptFile`](</docs/en/agent-sdk/python#systempromptfile>) for the platform thresholds and the Windows behavior. ## @@ -438,28 +460,33 @@ messages.push(message); } + import asyncio + from claude_agent_sdk import query, ClaudeAgentOptions # Assuming "Code Reviewer" output style is active (via /config or settings) # Add session-specific focus areas messages = [] - async for message in query( - prompt="Review this authentication module", - options=ClaudeAgentOptions( - system_prompt={ - "type": "preset", - "preset": "claude_code", - "append": """ - For this review, prioritize: - - OAuth 2.0 compliance - - Token storage security - - Session management - """, - } - ), - ): - messages.append(message) + async def main(): + async for message in query( + prompt="Review this authentication module", + options=ClaudeAgentOptions( + system_prompt={ + "type": "preset", + "preset": "claude_code", + "append": """ + For this review, prioritize: + - OAuth 2.0 compliance + - Token storage security + - Session management + """, + } + ), + ): + messages.append(message) + + asyncio.run(main()) ##
modified
Show diff (131 lines)
--- a/modifying-system-prompts.md +++ b/modifying-system-prompts.md @@ -88,6 +88,24 @@ // Now Claude has access to your project guidelines from CLAUDE.md + from claude_agent_sdk import query, ClaudeAgentOptions + + messages = [] + + async for message in query( + prompt="Add a new React component for user profiles", + options=ClaudeAgentOptions( + system_prompt={ + "type": "preset", + "preset": "claude_code", # Use Claude Code's system prompt + }, + setting_sources=["project"], # Loads CLAUDE.md from project + ), + ): + messages.append(message) + + # Now Claude has access to your project guidelines from CLAUDE.md + CLAUDE.md is persistent across all sessions in a project, shared with your team through git, and discovered automatically without code changes. It is not loaded if you pass an empty `settingSources` array. ### @@ -169,6 +187,24 @@ console.log(message.message.content); } } + + from claude_agent_sdk import query, ClaudeAgentOptions, AssistantMessage + + messages = [] + + async for message in query( + prompt="Help me write a Python function to calculate fibonacci numbers", + options=ClaudeAgentOptions( + system_prompt={ + "type": "preset", + "preset": "claude_code", + "append": "Always include detailed docstrings and type hints in Python code.", + } + ), + ): + messages.append(message) + if isinstance(message, AssistantMessage): + print(message.content) #### @@ -202,6 +238,21 @@ // ... } + from claude_agent_sdk import query, ClaudeAgentOptions + + async for message in query( + prompt="Triage the open issues in this repo", + options=ClaudeAgentOptions( + system_prompt={ + "type": "preset", + "preset": "claude_code", + "append": "You operate Acme's internal triage workflow. Label issues by component and severity.", + "exclude_dynamic_sections": True, + }, + ), + ): + ... + **Tradeoffs:** the working directory, the git-repo flag, the platform, the active shell, the OS version, and auto-memory paths still reach Claude, but as part of the first user message rather than the system prompt. Instructions in the user message carry marginally less weight than the same text in the system prompt, so Claude may rely on them less strongly when reasoning about the current directory or auto-memory paths. Enable this option when cross-session cache reuse matters more than maximally authoritative environment context. For the equivalent flag in non-interactive CLI mode, see [`--exclude-dynamic-system-prompt-sections`](</docs/en/cli-reference>). ### @@ -239,6 +290,26 @@ console.log(message.message.content); } } + + from claude_agent_sdk import query, ClaudeAgentOptions, AssistantMessage + + custom_prompt = """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""" + + messages = [] + + async for message in query( + prompt="Create a data processing pipeline", + options=ClaudeAgentOptions(system_prompt=custom_prompt), + ): + messages.append(message) + if isinstance(message, AssistantMessage): + print(message.content) ## @@ -367,6 +438,29 @@ messages.push(message); } + from claude_agent_sdk import query, ClaudeAgentOptions + + # Assuming "Code Reviewer" output style is active (via /config or settings) + # Add session-specific focus areas + messages = [] + + async for message in query( + prompt="Review this authentication module", + options=ClaudeAgentOptions( + system_prompt={ + "type": "preset", + "preset": "claude_code", + "append": """ + For this review, prioritize: + - OAuth 2.0 compliance + - Token storage security + - Session management + """, + } + ), + ): + messages.append(message) + ## ​
modified
--- a/modifying-system-prompts.md +++ b/modifying-system-prompts.md @@ -132,7 +132,9 @@ * **CLI** : run `/config` and select an output style * **Settings** : set `outputStyle` in `.claude/settings.local.json` - * **TypeScript SDK** : set `outputStyle` inside the inline `settings` object passed to `query()`, or point `settings` at a settings file that sets it. `outputStyle` is not a top-level `Options` field + * **TypeScript SDK** : set `outputStyle` inside the inline `settings` object passed to `query()`, or point `settings` at a settings file that sets it. `outputStyle` is not a top-level `Options` field: + + const options = { settings: { outputStyle: "Explanatory" } }; The Python SDK does not have an option to select an output style programmatically. For code-only deployments where you can’t write to `.claude/settings.local.json`, use `append` or a custom prompt string instead. **Note for SDK users:** Output styles are loaded when you include `settingSources: ['user']` or `settingSources: ['project']` (TypeScript) / `setting_sources=["user"]` or `setting_sources=["project"]` (Python) in your options.
modified
--- a/modifying-system-prompts.md +++ b/modifying-system-prompts.md @@ -1,9 +1,3 @@ -> ## Documentation Index -> -> Fetch the complete documentation index at: <https://code.claude.com/docs/llms.txt> -> -> Use this file to discover all available pages before exploring further. - System prompts define Claude’s behavior, capabilities, and response style. Start from the `claude_code` preset for CLI or IDE-like coding tools where a human watches and steers the work. Write your own prompt for agents with a different surface, identity, or permission model. This page covers: * How system prompts work, with a decision table for choosing between the preset, the preset with `append`, and a custom prompt
modified
--- a/modifying-system-prompts.md +++ b/modifying-system-prompts.md @@ -138,7 +138,7 @@ * **CLI** : run `/config` and select an output style * **Settings** : set `outputStyle` in `.claude/settings.local.json` - * **TypeScript SDK** : set `options.outputStyle` to the style’s name + * **TypeScript SDK** : set `outputStyle` inside the inline `settings` object passed to `query()`, or point `settings` at a settings file that sets it. `outputStyle` is not a top-level `Options` field The Python SDK does not have an option to select an output style programmatically. For code-only deployments where you can’t write to `.claude/settings.local.json`, use `append` or a custom prompt string instead. **Note for SDK users:** Output styles are loaded when you include `settingSources: ['user']` or `settingSources: ['project']` (TypeScript) / `setting_sources=["user"]` or `setting_sources=["project"]` (Python) in your options. @@ -379,6 +379,6 @@ * [Output styles](</docs/en/output-styles>): create, manage, and share output styles for the CLI, including the file format and storage locations * [How Claude remembers your project](</docs/en/memory>): what to put in CLAUDE.md, where to place it, and how to write effective project instructions - * [TypeScript SDK reference](</docs/en/agent-sdk/typescript>): the full `Options` type, including `systemPrompt`, `settingSources`, and `outputStyle` + * [TypeScript SDK reference](</docs/en/agent-sdk/typescript>): the full `Options` type, including `systemPrompt`, `settingSources`, and `settings` * [Python SDK reference](</docs/en/agent-sdk/python>): the full `ClaudeAgentOptions` type, including `system_prompt` and `setting_sources` * [Settings](</docs/en/settings>): the `settings.json` reference, including where output styles and other configuration are stored
modified
--- a/modifying-system-prompts.md +++ b/modifying-system-prompts.md @@ -110,13 +110,14 @@ Create an output style -An output style is a markdown file with a `name` and `description` in its frontmatter, followed by the prompt content. Save it to `~/.claude/output-styles/` for a user-level style available in every project, or `.claude/output-styles/` in your repository for a project-level style you can commit and share with your team. The example below defines a code-review persona. Save it as `~/.claude/output-styles/code-reviewer.md` to make it available across projects: +An output style is a markdown file with [frontmatter](</docs/en/output-styles#frontmatter>) for metadata, followed by the prompt content. Save it to `~/.claude/output-styles/` for a user-level style available in every project, or `.claude/output-styles/` in your repository for a project-level style you can commit and share with your team. By default, a custom output style replaces the `claude_code` preset’s software engineering instructions with your own. To keep them and layer your instructions on top, set `keep-coding-instructions: true` in the frontmatter. Keep them when your agent is still doing software engineering work. Leave them out when you’re replacing the role entirely. The example below defines a code-review persona that keeps the coding instructions, since reviewing code still benefits from Claude Code’s security and code-quality guidance. Save it as `~/.claude/output-styles/code-reviewer.md` to make it available across projects: ~/.claude/output-styles/code-reviewer.md --- name: Code Reviewer description: Thorough code review assistant + keep-coding-instructions: true --- You are an expert code reviewer. @@ -259,7 +260,7 @@ **Default tools**| Preserved| Preserved| Preserved| Lost (unless included) **Built-in safety**| Maintained| Maintained| Maintained| Must be added **Environment context**| Automatic| Automatic| Automatic| Must be provided -**Customization level**| Additions only| Replace default| Additions only| Complete control +**Customization level**| Additions only| Replace or extend default| Additions only| Complete control **Version control**| With project| Yes| With code| With code **Scope**| Project-specific| User or project| Code session| Code session
modified
Show diff (431 lines)
--- a/modifying-system-prompts.md +++ b/modifying-system-prompts.md @@ -4,90 +4,72 @@ > > Use this file to discover all available pages before exploring further. -System prompts define Claude’s behavior, capabilities, and response style. The Claude Agent SDK provides three ways to customize system prompts: using output styles (persistent, file-based configurations), appending to Claude Code’s prompt, or using a fully custom prompt. - -## - -​ - -Understanding system prompts - -A system prompt is the initial instruction set that shapes how Claude behaves throughout a conversation. - -**Default behavior:** The Agent SDK uses a **minimal system prompt** by default. It contains only essential tool instructions but omits Claude Code’s coding guidelines, response style, and project context. To include the full Claude Code system prompt, specify `systemPrompt: { type: "preset", preset: "claude_code" }` in TypeScript or `system_prompt={"type": "preset", "preset": "claude_code"}` in Python. - -Claude Code’s system prompt includes: - - * Tool usage instructions and available tools - * Code style and formatting guidelines - * Response tone and verbosity settings - * Security and safety instructions - * Context about the current working directory and environment - -## - -​ - -Methods of modification - -### - -​ - -Method 1: CLAUDE.md files (project-level instructions) - -CLAUDE.md files provide project-specific context and instructions that are automatically read by the Agent SDK when it runs in a directory. They serve as persistent “memory” for your project. +System prompts define Claude’s behavior, capabilities, and response style. Start from the `claude_code` preset for CLI or IDE-like coding tools where a human watches and steers the work. Write your own prompt for agents with a different surface, identity, or permission model. This page covers: + + * How system prompts work, with a decision table for choosing between the preset, the preset with `append`, and a custom prompt + * Customize agent behavior with CLAUDE.md files, output styles, `append`, or a custom string + * Compare the four approaches by persistence, scope, and what they preserve + * Combine approaches to layer customization methods together + +## + +​ + +How system prompts work + +A system prompt is the initial instruction set that shapes how Claude behaves throughout a conversation. The Agent SDK has three starting points for it: + + * **Minimal default** : when you don’t set `systemPrompt` in TypeScript or `system_prompt` in Python, the SDK uses a minimal prompt that covers tool calling but omits Claude Code’s coding guidelines, response style, and project context. This differs from `claude -p`, which uses the full Claude Code prompt by default. If you’re migrating from the CLI and want matching behavior, set the `claude_code` preset. + * **`claude_code` preset**: the full system prompt that the Claude Code CLI uses, with tool usage instructions, code style and formatting guidelines, response tone and verbosity rules, security and safety instructions, and context about the working directory and environment. Set `systemPrompt: { type: "preset", preset: "claude_code" }` in TypeScript or `system_prompt={"type": "preset", "preset": "claude_code"}` in Python, optionally with `append` to add your own instructions on the end. + * **Custom string** : a prompt you write yourself. The SDK sends only what you provide. + +### + +​ + +Decide on a starting point + +The deciding factor is how closely your agent resembles Claude Code: a coding agent operating in a repository, with a human watching streaming output and steering the work. The further your product is from that, the more you’ll want to write your own prompt. + +You’re building| Use| What you get +---|---|--- +A CLI or IDE-like coding tool where a human watches and steers, and Claude Code’s defaults are what you want| `claude_code` preset| The full Claude Code prompt: tool guidance, safety rules, terminal-friendly responses, repo-convention awareness +The same kind of tool, plus product-specific rules like coding standards, output format, or domain context| `claude_code` preset with `append`| Everything above, with your instructions added after the preset. Nothing is removed, so this is the lowest-risk customization +An agent with a different surface, identity, or permission model, or a non-coding agent| Custom prompt string| Only what you write. You take responsibility for replacing the tool guidance and safety instructions your agent still needs +A thin tool-calling loop with no agent persona, where you supply all behavior in the user prompt| No `systemPrompt` option| The minimal default: tool-calling support and nothing else + +“Different from Claude Code” usually means one of the following: + + * **Different surface** : the output isn’t read in a terminal by the person who triggered it. Chat UIs, structured-output consumers, and non-coding automation each need a prompt that matches how their output is rendered and reviewed. Unattended coding automation, like a CI job that fixes lint errors or reviews diffs, still fits the preset because the work itself is what the preset is written for. + * **Different identity** : the agent shouldn’t present itself as Claude Code. A support bot, a data-analysis assistant, or any domain-specific agent needs its own name, scope, and persona. + * **Different permission model** : the agent runs autonomously without a human approving each step, or operates on a narrow set of resources. Claude Code’s prompt assumes a human is in the loop with access to a full toolset. + * **Non-coding tasks** : most of Claude Code’s prompt is coding guidance. For research, content, or operations agents, that guidance competes with the instructions you actually need. + +The comparison table shows what each customization method preserves. + +## + +​ + +Customize agent behavior + +Output styles, `append`, and a custom prompt string each change the system prompt directly. CLAUDE.md takes a different path: the SDK reads it and injects its content into the conversation as project context, not into the system prompt, so it shapes behavior alongside whichever system prompt you choose. [Skills](</docs/en/agent-sdk/skills>), [hooks](</docs/en/agent-sdk/hooks>), and [permissions](</docs/en/agent-sdk/permissions>) also shape behavior outside the system prompt and are covered on their own pages. + +### + +​ + +CLAUDE.md files for project-level instructions + +CLAUDE.md files give Claude persistent project context and instructions. The SDK injects their content into the conversation, not into the system prompt, so they work with any system prompt configuration. For what to put in CLAUDE.md, where to place it, and how to write effective instructions, see [How Claude remembers your project](</docs/en/memory>). This section covers what’s specific to the SDK: how CLAUDE.md loads. The SDK reads CLAUDE.md when the matching setting source is enabled: `'project'` loads `CLAUDE.md` or `.claude/CLAUDE.md` from the working directory, and `'user'` loads `~/.claude/CLAUDE.md`. Default `query()` options enable both sources, so CLAUDE.md loads automatically. If you set `settingSources` in TypeScript or `setting_sources` in Python explicitly, include the sources you need. CLAUDE.md loading is controlled by setting sources, not by the `claude_code` preset. #### ​ -How CLAUDE.md works with the SDK - -**Location and discovery:** - - * **Project-level:** `CLAUDE.md` or `.claude/CLAUDE.md` in your working directory - * **User-level:** `~/.claude/CLAUDE.md` for global instructions across all projects - -CLAUDE.md files are read when the corresponding setting source is enabled: `'project'` for project-level CLAUDE.md and `'user'` for `~/.claude/CLAUDE.md`. With default `query()` options both sources are enabled, so CLAUDE.md loads automatically. If you set `settingSources` (TypeScript) or `setting_sources` (Python) explicitly, include the sources you need. CLAUDE.md loading is controlled by setting sources, not by the `claude_code` preset. **Content format:** CLAUDE.md files use plain markdown and can contain: - - * Coding guidelines and standards - * Project-specific context - * Common commands or workflows - * API conventions - * Testing requirements - -#### - -​ - -Example 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` - -#### - -​ - -Using CLAUDE.md with the SDK +Load CLAUDE.md with the SDK + +To load CLAUDE.md, set `settingSources` to include the level your CLAUDE.md lives at. The example below loads a project-level CLAUDE.md alongside the `claude_code` preset, so Claude has both the full coding-agent prompt and your project’s conventions: TypeScript @@ -112,99 +94,58 @@ // Now Claude has access to your project guidelines from CLAUDE.md +CLAUDE.md is persistent across all sessions in a project, shared with your team through git, and discovered automatically without code changes. It is not loaded if you pass an empty `settingSources` array. + +### + +​ + +Output styles for persistent configurations + +Output styles are saved configurations that modify Claude’s system prompt. They’re stored as markdown files and can be reused across sessions and projects. + #### ​ -When to use CLAUDE.md - -**Best for:** - - * **Team-shared context** \- Guidelines everyone should follow - * **Project conventions** \- Coding standards, file structure, naming patterns - * **Common commands** \- Build, test, deploy commands specific to your project - * **Long-term memory** \- Context that should persist across all sessions - * **Version-controlled instructions** \- Commit to git so the team stays in sync - -**Key characteristics:** - - * ✅ Persistent across all sessions in a project - * ✅ Shared with team via git - * ✅ Automatic discovery (no code changes needed) - * ⚠️ Not loaded if you pass `settingSources: []` - -### - -​ - -Method 2: Output styles (persistent configurations) - -Output styles are saved configurations that modify Claude’s system prompt. They’re stored as markdown files and can be reused across sessions and projects. - -#### - -​ - -Creating an output style - -TypeScript - -Python - - import { writeFile, mkdir } from "fs/promises"; - import { join } from "path"; - import { homedir } from "os"; - - async function createOutputStyle(name: string, description: string, prompt: string) { - // User-level: ~/.claude/output-styles - // Project-level: .claude/output-styles - const outputStylesDir = join(homedir(), ".claude", "output-styles"); - - await mkdir(outputStylesDir, { recursive: true }); - - const content = `--- - name: ${name} - description: ${description} +Create an output style + +An output style is a markdown file with a `name` and `description` in its frontmatter, followed by the prompt content. Save it to `~/.claude/output-styles/` for a user-level style available in every project, or `.claude/output-styles/` in your repository for a project-level style you can commit and share with your team. The example below defines a code-review persona. Save it as `~/.claude/output-styles/code-reviewer.md` to make it available across projects: + +~/.claude/output-styles/code-reviewer.md + --- - - ${prompt}`; - - const filePath = join(outputStylesDir, `${name.toLowerCase().replace(/\s+/g, "-")}.md`); - await writeFile(filePath, content, "utf-8"); - } - - // Example: Create a code review specialist - await createOutputStyle( - "Code Reviewer", - "Thorough code review assistant", - `You are an expert code reviewer. + name: Code Reviewer + description: 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)` - ); + 4. Rate code quality (1-10) #### ​ -Using output styles +Activate an output style Once created, activate output styles via: - * **CLI** : `/config`, then select Output style + * **CLI** : run `/config` and select an output style * **Settings** : set `outputStyle` in `.claude/settings.local.json` - * **Create new** : add a Markdown file at `~/.claude/output-styles/` or `.claude/output-styles/`; see [Create a custom output style](</docs/en/output-styles#create-a-custom-output-style>) for the format - -**Note for SDK users:** Output styles are loaded when you include `settingSources: ['user']` or `settingSources: ['project']` (TypeScript) / `setting_sources=["user"]` or `setting_sources=["project"]` (Python) in your options. - -### - -​ - -Method 3: Using `systemPrompt` with append + * **TypeScript SDK** : set `options.outputStyle` to the style’s name + +The Python SDK does not have an option to select an output style programmatically. For code-only deployments where you can’t write to `.claude/settings.local.json`, use `append` or a custom prompt string instead. **Note for SDK users:** Output styles are loaded when you include `settingSources: ['user']` or `settingSources: ['project']` (TypeScript) / `setting_sources=["user"]` or `setting_sources=["project"]` (Python) in your options. + +### + +​ + +Append to the `claude_code` preset You can use the Claude Code preset with an `append` property to add your custom instructions while preserving all built-in functionality. @@ -238,7 +179,7 @@ Improve prompt caching across users and machines -By default, two sessions that use the same `claude_code` preset and `append` text still cannot share a prompt cache entry if they run from different working directories. This is because the preset embeds per-session context in the system prompt ahead of your `append` text: the working directory, platform and OS version, current date, git status, and auto-memory paths. Any difference in that context produces a different system prompt and a cache miss. To make the system prompt identical across sessions, set `excludeDynamicSections: true` in TypeScript or `"exclude_dynamic_sections": True` in Python. The per-session context moves into the first user message, leaving only the static preset and your `append` text in the system prompt so identical configurations share a cache entry across users and machines. +By default, two sessions that use the same `claude_code` preset and `append` text still cannot share a prompt cache entry if they run from different working directories. This is because the preset embeds per-session context in the system prompt ahead of your `append` text: the working directory, whether it’s a git repository, the platform, the active shell, the OS version, and auto-memory paths. Any difference in that context produces a different system prompt and a cache miss. CLAUDE.md content doesn’t affect the system prompt cache because the SDK injects it into the conversation, not the system prompt. To make the system prompt identical across sessions, set `excludeDynamicSections: true` in TypeScript or `"exclude_dynamic_sections": True` in Python. The per-session context moves into the first user message, leaving only the static preset and your `append` text in the system prompt so identical configurations share a cache entry across users and machines. `excludeDynamicSections` requires `@anthropic-ai/claude-agent-sdk` v0.2.98 or later, or `claude-agent-sdk` v0.1.58 or later for Python. It applies only to the preset object form and has no effect when `systemPrompt` is a string. @@ -264,13 +205,13 @@ // ... } -**Tradeoffs:** the working directory, git status, and memory location still reach Claude, but as part of the first user message rather than the system prompt. Instructions in the user message carry marginally less weight than the same text in the system prompt, so Claude may rely on them less strongly when reasoning about the current directory or auto-memory paths. Enable this option when cross-session cache reuse matters more than maximally authoritative environment context. For the equivalent flag in non-interactive CLI mode, see [`--exclude-dynamic-system-prompt-sections`](</docs/en/cli-reference>). - -### - -​ - -Method 4: Custom system prompts +**Tradeoffs:** the working directory, the git-repo flag, the platform, the active shell, the OS version, and auto-memory paths still reach Claude, but as part of the first user message rather than the system prompt. Instructions in the user message carry marginally less weight than the same text in the system prompt, so Claude may rely on them less strongly when reasoning about the current directory or auto-memory paths. Enable this option when cross-session cache reuse matters more than maximally authoritative environment context. For the equivalent flag in non-interactive CLI mode, see [`--exclude-dynamic-system-prompt-sections`](</docs/en/cli-reference>). + +### + +​ + +Custom system prompts You can provide a custom string as `systemPrompt` to replace the default entirely with your own instructions. @@ -306,7 +247,9 @@ ​ -Comparison of all four approaches +Compare the four approaches + +The four customization methods differ in where they live, how they’re shared, and what they preserve from the `claude_code` preset. Feature| CLAUDE.md| Output Styles| `systemPrompt` with append| Custom `systemPrompt` ---|---|---|---|--- @@ -320,7 +263,7 @@ **Version control**| With project| Yes| With code| With code **Scope**| Project-specific| User or project| Code session| Code session -**Note:** “With append” means using `systemPrompt: { type: "preset", preset: "claude_code", append: "..." }` in TypeScript or `system_prompt={"type": "preset", "preset": "claude_code", "append": "..."}` in Python. +“With append” means using `systemPrompt: { type: "preset", preset: "claude_code", append: "..." }` in TypeScript or `system_prompt={"type": "preset", "preset": "claude_code", "append": "..."}` in Python. CLAUDE.md doesn’t change the system prompt itself: the SDK injects its content into the conversation as project context. ## @@ -334,21 +277,7 @@ When to use CLAUDE.md -**Best for:** - - * Project-specific coding standards and conventions - * Documenting project structure and architecture - * Listing common commands (build, test, deploy) - * Team-shared context that should be version controlled - * Instructions that apply to all SDK usage in a project - -**Examples:** - - * “All API endpoints should use async/await patterns” - * “Run `npm run lint:fix` before committing” - * “Database migrations are in the `migrations/` directory” - -CLAUDE.md files load when the `project` setting source is enabled, which it is for default `query()` options. If you set `settingSources` (TypeScript) or `setting_sources` (Python) explicitly, include `'project'` to keep loading project-level CLAUDE.md. +Use CLAUDE.md for instructions that should apply to every session in a project, regardless of which system prompt the session uses: coding standards, common commands, architecture context, and team conventions. CLAUDE.md is committed to your repository, so it stays in sync with the code it describes. See [When to add to CLAUDE.md](</docs/en/memory#when-to-add-to-claude-md>) for full guidance. CLAUDE.md files load when the `project` setting source is enabled, which it is for default `query()` options. If you set `settingSources` in TypeScript or `setting_sources` in Python explicitly, include `'project'` to keep loading project-level CLAUDE.md. ### @@ -356,11 +285,11 @@ When to use output styles -**Best for:** +Output styles are for personas you want to reuse across the CLI and SDK without changing application code. Because they live as files in `.claude/output-styles`, the same persona is available from `/config` in the CLI and from any SDK session that loads the matching setting source. **Best for:** * Persistent behavior changes across sessions * Team-shared configurations - * Specialized assistants (code reviewer, data scientist, DevOps) + * Specialized assistants like a code reviewer, data scientist, or DevOps assistant * Complex prompt modifications that need versioning **Examples:** @@ -375,7 +304,7 @@ When to use `systemPrompt` with append -**Best for:** +Use `append` when the `claude_code` preset already fits your product and you only need to layer in extra instructions. You keep the preset’s tool guidance, safety rules, and coding conventions without reimplementing them. **Best for:** * Adding specific coding standards or preferences * Customizing output formatting @@ -389,7 +318,7 @@ When to use custom `systemPrompt` -**Best for:** +Use a custom prompt when your agent’s surface, identity, or permission model differs from Claude Code’s, as described in Decide on a starting point. You define the full instruction set, including any tool guidance and safety rules your agent needs. **Best for:** * Complete control over Claude’s behavior * Specialized single-session tasks @@ -401,15 +330,17 @@ ​ -Combining approaches - -You can combine these methods for maximum flexibility: - -### - -​ - -Example: Output style with session-specific additions +Combine approaches + +These methods compose. A persistent output style or CLAUDE.md sets the long-lived behavior, and `append` layers session-specific instructions on top without touching the saved configuration. + +### + +​ + +Combine an output style with session-specific additions + +The example below assumes a Code Reviewer output style is already active. The `append` block layers session-specific focus areas on top of the persona, so a single review session can prioritize OAuth and token storage without changing the saved output style: TypeScript @@ -445,6 +376,8 @@ See also - * [Output styles](</docs/en/output-styles>) \- Complete output styles documentation - * [TypeScript SDK guide](</docs/en/agent-sdk/typescript>) \- Complete SDK usage guide - * [Configuration guide](</docs/en/settings>) \- General configuration options + * [Output styles](</docs/en/output-styles>): create, manage, and share output styles for the CLI, including the file format and storage locations + * [How Claude remembers your project](</docs/en/memory>): what to put in CLAUDE.md, where to place it, and how to write effective project instructions + * [TypeScript SDK reference](</docs/en/agent-sdk/typescript>): the full `Options` type, including `systemPrompt`, `settingSources`, and `outputStyle` + * [Python SDK reference](</docs/en/agent-sdk/python>): the full `ClaudeAgentOptions` type, including `system_prompt` and `setting_sources` + * [Settings](</docs/en/settings>): the `settings.json` reference, including where output styles and other configuration are stored
modified
--- a/modifying-system-prompts.md +++ b/modifying-system-prompts.md @@ -194,9 +194,9 @@ Once created, activate output styles via: - * **CLI** : `/output-style [style-name]` - * **Settings** : `.claude/settings.local.json` - * **Create new** : `/output-style:new [description]` + * **CLI** : `/config`, then select Output style + * **Settings** : set `outputStyle` in `.claude/settings.local.json` + * **Create new** : add a Markdown file at `~/.claude/output-styles/` or `.claude/output-styles/`; see [Create a custom output style](</docs/en/output-styles#create-a-custom-output-style>) for the format **Note for SDK users:** Output styles are loaded when you include `settingSources: ['user']` or `settingSources: ['project']` (TypeScript) / `setting_sources=["user"]` or `setting_sources=["project"]` (Python) in your options. @@ -417,7 +417,7 @@ import { query } from "@anthropic-ai/claude-agent-sdk"; - // Assuming "Code Reviewer" output style is active (via /output-style) + // Assuming "Code Reviewer" output style is active (via /config or settings) // Add session-specific focus areas const messages = [];
modified
--- a/modifying-system-prompts.md +++ b/modifying-system-prompts.md @@ -1,3 +1,9 @@ +> ## Documentation Index +> +> Fetch the complete documentation index at: <https://code.claude.com/docs/llms.txt> +> +> Use this file to discover all available pages before exploring further. + System prompts define Claude’s behavior, capabilities, and response style. The Claude Agent SDK provides three ways to customize system prompts: using output styles (persistent, file-based configurations), appending to Claude Code’s prompt, or using a fully custom prompt. ##
modified
--- a/modifying-system-prompts.md +++ b/modifying-system-prompts.md @@ -43,12 +43,7 @@ * **Project-level:** `CLAUDE.md` or `.claude/CLAUDE.md` in your working directory * **User-level:** `~/.claude/CLAUDE.md` for global instructions across all projects -**IMPORTANT:** The SDK only reads CLAUDE.md files when you explicitly configure `settingSources` (TypeScript) or `setting_sources` (Python): - - * Include `'project'` to load project-level CLAUDE.md - * Include `'user'` to load user-level CLAUDE.md (`~/.claude/CLAUDE.md`) - -The `claude_code` system prompt preset does NOT automatically load CLAUDE.md - you must also specify setting sources. **Content format:** CLAUDE.md files use plain markdown and can contain: +CLAUDE.md files are read when the corresponding setting source is enabled: `'project'` for project-level CLAUDE.md and `'user'` for `~/.claude/CLAUDE.md`. With default `query()` options both sources are enabled, so CLAUDE.md loads automatically. If you set `settingSources` (TypeScript) or `setting_sources` (Python) explicitly, include the sources you need. CLAUDE.md loading is controlled by setting sources, not by the `claude_code` preset. **Content format:** CLAUDE.md files use plain markdown and can contain: * Coding guidelines and standards * Project-specific context @@ -94,8 +89,6 @@ import { query } from "@anthropic-ai/claude-agent-sdk"; - // IMPORTANT: You must specify settingSources to load CLAUDE.md - // The claude_code preset alone does NOT load CLAUDE.md files const messages = []; for await (const message of query({ @@ -105,7 +98,7 @@ type: "preset", preset: "claude_code" // Use Claude Code's system prompt }, - settingSources: ["project"] // Required to load CLAUDE.md from project + settingSources: ["project"] // Loads CLAUDE.md from project } })) { messages.push(message); @@ -132,7 +125,7 @@ * ✅ Persistent across all sessions in a project * ✅ Shared with team via git * ✅ Automatic discovery (no code changes needed) - * ⚠️ Requires loading settings via `settingSources` + * ⚠️ Not loaded if you pass `settingSources: []` ### @@ -349,7 +342,7 @@ * “Run `npm run lint:fix` before committing” * “Database migrations are in the `migrations/` directory” -**Important:** To load CLAUDE.md files, you must explicitly set `settingSources: ['project']` (TypeScript) or `setting_sources=["project"]` (Python). The `claude_code` system prompt preset does NOT automatically load CLAUDE.md without this setting. +CLAUDE.md files load when the `project` setting source is enabled, which it is for default `query()` options. If you set `settingSources` (TypeScript) or `setting_sources` (Python) explicitly, include `'project'` to keep loading project-level CLAUDE.md. ###
modified
--- a/modifying-system-prompts.md +++ b/modifying-system-prompts.md @@ -232,6 +232,40 @@ console.log(message.message.content); } } + +#### + +​ + +Improve prompt caching across users and machines + +By default, two sessions that use the same `claude_code` preset and `append` text still cannot share a prompt cache entry if they run from different working directories. This is because the preset embeds per-session context in the system prompt ahead of your `append` text: the working directory, platform and OS version, current date, git status, and auto-memory paths. Any difference in that context produces a different system prompt and a cache miss. To make the system prompt identical across sessions, set `excludeDynamicSections: true` in TypeScript or `"exclude_dynamic_sections": True` in Python. The per-session context moves into the first user message, leaving only the static preset and your `append` text in the system prompt so identical configurations share a cache entry across users and machines. + +`excludeDynamicSections` requires `@anthropic-ai/claude-agent-sdk` v0.2.98 or later, or `claude-agent-sdk` v0.1.58 or later for Python. It applies only to the preset object form and has no effect when `systemPrompt` is a string. + +The following example pairs a shared `append` block with `excludeDynamicSections` so a fleet of agents running from different directories can reuse the same cached system prompt: + +TypeScript + +Python + + import { query } from "@anthropic-ai/claude-agent-sdk"; + + for await (const message of query({ + prompt: "Triage the open issues in this repo", + options: { + systemPrompt: { + type: "preset", + preset: "claude_code", + append: "You operate Acme's internal triage workflow. Label issues by component and severity.", + excludeDynamicSections: true + } + } + })) { + // ... + } + +**Tradeoffs:** the working directory, git status, and memory location still reach Claude, but as part of the first user message rather than the system prompt. Instructions in the user message carry marginally less weight than the same text in the system prompt, so Claude may rely on them less strongly when reasoning about the current directory or auto-memory paths. Enable this option when cross-session cache reuse matters more than maximally authoritative environment context. For the equivalent flag in non-interactive CLI mode, see [`--exclude-dynamic-system-prompt-sections`](</docs/en/cli-reference>). ###
added
Show diff (420 lines)
--- a/modifying-system-prompts.md +++ b/modifying-system-prompts.md @@ -0,0 +1,417 @@ +System prompts define Claude’s behavior, capabilities, and response style. The Claude Agent SDK provides three ways to customize system prompts: using output styles (persistent, file-based configurations), appending to Claude Code’s prompt, or using a fully custom prompt. + +## + +​ + +Understanding system prompts + +A system prompt is the initial instruction set that shapes how Claude behaves throughout a conversation. + +**Default behavior:** The Agent SDK uses a **minimal system prompt** by default. It contains only essential tool instructions but omits Claude Code’s coding guidelines, response style, and project context. To include the full Claude Code system prompt, specify `systemPrompt: { type: "preset", preset: "claude_code" }` in TypeScript or `system_prompt={"type": "preset", "preset": "claude_code"}` in Python. + +Claude Code’s system prompt includes: + + * Tool usage instructions and available tools + * Code style and formatting guidelines + * Response tone and verbosity settings + * Security and safety instructions + * Context about the current working directory and environment + +## + +​ + +Methods of modification + +### + +​ + +Method 1: CLAUDE.md files (project-level instructions) + +CLAUDE.md files provide project-specific context and instructions that are automatically read by the Agent SDK when it runs in a directory. They serve as persistent “memory” for your project. + +#### + +​ + +How CLAUDE.md works with the SDK + +**Location and discovery:** + + * **Project-level:** `CLAUDE.md` or `.claude/CLAUDE.md` in your working directory + * **User-level:** `~/.claude/CLAUDE.md` for global instructions across all projects + +**IMPORTANT:** The SDK only reads CLAUDE.md files when you explicitly configure `settingSources` (TypeScript) or `setting_sources` (Python): + + * Include `'project'` to load project-level CLAUDE.md + * Include `'user'` to load user-level CLAUDE.md (`~/.claude/CLAUDE.md`) + +The `claude_code` system prompt preset does NOT automatically load CLAUDE.md - you must also specify setting sources. **Content format:** CLAUDE.md files use plain markdown and can contain: + + * Coding guidelines and standards + * Project-specific context + * Common commands or workflows + * API conventions + * Testing requirements + +#### + +​ + +Example 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` + +#### + +​ + +Using CLAUDE.md with the SDK + +TypeScript + +Python + + import { query } from "@anthropic-ai/claude-agent-sdk"; + + // IMPORTANT: You must specify settingSources to load CLAUDE.md + // The claude_code preset alone does NOT load CLAUDE.md files + const messages = []; + + for await (const message of query({ + prompt: "Add a new React component for user profiles", + options: { + systemPrompt: { + type: "preset", + preset: "claude_code" // Use Claude Code's system prompt + }, + settingSources: ["project"] // Required to load CLAUDE.md from project + } + })) { + messages.push(message); + } + + // Now Claude has access to your project guidelines from CLAUDE.md + +#### + +​ + +When to use CLAUDE.md + +**Best for:** + + * **Team-shared context** \- Guidelines everyone should follow + * **Project conventions** \- Coding standards, file structure, naming patterns + * **Common commands** \- Build, test, deploy commands specific to your project + * **Long-term memory** \- Context that should persist across all sessions + * **Version-controlled instructions** \- Commit to git so the team stays in sync + +**Key characteristics:** + + * ✅ Persistent across all sessions in a project + * ✅ Shared with team via git + * ✅ Automatic discovery (no code changes needed) + * ⚠️ Requires loading settings via `settingSources` + +### + +​ + +Method 2: Output styles (persistent configurations) + +Output styles are saved configurations that modify Claude’s system prompt. They’re stored as markdown files and can be reused across sessions and projects. + +#### + +​ + +Creating an output style + +TypeScript + +Python + + import { writeFile, mkdir } from "fs/promises"; + import { join } from "path"; + import { homedir } from "os"; + + async function createOutputStyle(name: string, description: string, prompt: string) { + // User-level: ~/.claude/output-styles + // Project-level: .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"); + } + + // Example: Create a code review specialist + 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)` + ); + +#### + +​ + +Using output styles + +Once created, activate output styles via: + + * **CLI** : `/output-style [style-name]` + * **Settings** : `.claude/settings.local.json` + * **Create new** : `/output-style:new [description]` + +**Note for SDK users:** Output styles are loaded when you include `settingSources: ['user']` or `settingSources: ['project']` (TypeScript) / `setting_sources=["user"]` or `setting_sources=["project"]` (Python) in your options. + +### + +​ + +Method 3: Using `systemPrompt` with append + +You can use the Claude Code preset with an `append` property to add your custom instructions while preserving all built-in functionality. + +TypeScript + +Python + + 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); + } + } + +### + +​ + +Method 4: Custom system prompts + +You can provide a custom string as `systemPrompt` to replace the default entirely with your own instructions. + +TypeScript + +Python + + 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); + } + } + +## + +​ + +Comparison of all four approaches + +Feature| CLAUDE.md| Output Styles| `systemPrompt` with append| Custom `systemPrompt` +---|---|---|---|--- +**Persistence**| Per-project file| Saved as files| Session only| Session only +**Reusability**| Per-project| Across projects| Code duplication| Code duplication +**Management**| On filesystem| CLI + files| In code| In code +**Default tools**| Preserved| Preserved| Preserved| Lost (unless included) +**Built-in safety**| Maintained| Maintained| Maintained| Must be added +**Environment context**| Automatic| Automatic| Automatic| Must be provided +**Customization level**| Additions only| Replace default| Additions only| Complete control +**Version control**| With project| Yes| With code| With code +**Scope**| Project-specific| User or project| Code session| Code session + +**Note:** “With append” means using `systemPrompt: { type: "preset", preset: "claude_code", append: "..." }` in TypeScript or `system_prompt={"type": "preset", "preset": "claude_code", "append": "..."}` in Python. + +## + +​ + +Use cases and best practices + +### + +​ + +When to use CLAUDE.md + +**Best for:** + + * Project-specific coding standards and conventions + * Documenting project structure and architecture + * Listing common commands (build, test, deploy) + * Team-shared context that should be version controlled + * Instructions that apply to all SDK usage in a project + +**Examples:** + + * “All API endpoints should use async/await patterns” + * “Run `npm run lint:fix` before committing” + * “Database migrations are in the `migrations/` directory” + +**Important:** To load CLAUDE.md files, you must explicitly set `settingSources: ['project']` (TypeScript) or `setting_sources=["project"]` (Python). The `claude_code` system prompt preset does NOT automatically load CLAUDE.md without this setting. + +### + +​ + +When to use output styles + +**Best for:** + + * Persistent behavior changes across sessions + * Team-shared configurations + * Specialized assistants (code reviewer, data scientist, DevOps) + * Complex prompt modifications that need versioning + +**Examples:** + + * Creating a dedicated SQL optimization assistant + * Building a security-focused code reviewer + * Developing a teaching assistant with specific pedagogy + +### + +​ + +When to use `systemPrompt` with append + +**Best for:** + + * Adding specific coding standards or preferences + * Customizing output formatting + * Adding domain-specific knowledge + * Modifying response verbosity + * Enhancing Claude Code’s default behavior without losing tool instructions + +### + +​ + +When to use custom `systemPrompt` + +**Best for:** + + * Complete control over Claude’s behavior + * Specialized single-session tasks + * Testing new prompt strategies + * Situations where default tools aren’t needed + * Building specialized agents with unique behavior + +## + +​ + +Combining approaches + +You can combine these methods for maximum flexibility: + +### + +​ + +Example: Output style with session-specific additions + +TypeScript + +Python + + import { query } from "@anthropic-ai/claude-agent-sdk"; + + // Assuming "Code Reviewer" output style is active (via /output-style) + // Add session-specific focus areas + 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); + } + +## + +​ + +See also + + * [Output styles](</docs/en/output-styles>) \- Complete output styles documentation + * [TypeScript SDK guide](</docs/en/agent-sdk/typescript>) \- Complete SDK usage guide + * [Configuration guide](</docs/en/settings>) \- General configuration options