How Claude Code Builds a System Prompt
中文 | English
Source URL: https://www.dbreunig.com/2026/04/04/how-claude-code-builds-a-system-prompt.html Captured: 2026-04-16
Summary
This article explains Claude Code's system prompt as a dynamically assembled context rather than a single static string. Using an accidental source-code leak as evidence, it maps the component sections that can enter the prompt, including global instructions, coding philosophy, tool-use policy, communication rules, subagent guidance, skills, memory behavior, MCP instructions, scratchpad rules, git context, and other conditional suffixes.
Key Points
- System prompts in serious agent products are assembled from many conditional sections, not authored as one constant paragraph.
- Claude Code's prompt builder includes both always-on sections and conditionally injected sections.
- The article treats system prompts as one layer inside a larger harness context that also includes tool definitions, user content, conversation history, attachments, and skills.
- The assembly logic itself is important product evidence because it shows how much context engineering happens outside the base model.
- The article does not republish the leaked source code, but it distills its structure into a visualization and descriptive breakdown.
Notable Components Mentioned
- Global system framing and response style
- Tool-use policy and preference for dedicated tools
- Coding philosophy and minimal-change norms
- Risk confirmation guidance for destructive or external actions
- Communication and verbosity rules
- Dynamic cache boundary markers
- Clarification and user-question rules
- Interactive-shell guidance
- Subagent and fork guidance
- Skills discovery and invocation
- Independent verification requirements
- Auto-memory behavior
- Runtime / model / environment suffixes
- User language preference and output style
- MCP server instructions
- Scratchpad and function-result clearing behavior
- Git status context and appended system-prompt suffixes
Extracted Excerpt
System prompts generally aren’t static strings; they’re dynamically assembled contexts with many conditional statements determining what makes it in the prompt.
When you type instructions and hit ‘Enter’, Claude Code assembles a rich context to increase the odds that it obtains a successful response from Opus or Sonnet. As we can see, agents are more than just models. Context engineering is critical.
Practical Notes For This Vault
- This source complements reverse-extracted prompt inventories by explaining how a harness decides which prompt fragments appear at runtime.
- It is especially useful beside sources that catalog Claude Code prompt fragments, because it adds assembly logic and conditional structure rather than only prompt contents.
- The article strengthens the case that prompt/control surfaces, skills, memory systems, MCP instructions, and tool definitions should be treated as one interconnected operating layer.