How Claude Code Builds a System Prompt

Open the original

Short summary

This article examines how Claude Code constructs its system prompts by analyzing recently leaked source code. It highlights the dynamic nature of these prompts, which are built from various components based on conditional statements. The author also outlines additional elements that contribute to context, like tool definitions and conversation history.

  • Claude Code's system prompt isn't static text—it's dynamically assembled at runtime from conditional components, revealed by a recent source code leak.
  • The prompt mixes always-included elements (like core instructions) with conditional ones (like tool-specific guidance) that only appear based on context.
  • Beyond the system prompt itself, the full context sent to the model includes tool definitions, conversation history, attachments, and skills—all engineered together to shape responses.

Full summary

The article breaks down how Claude Code constructs its system prompts, revealing the complexity behind their assembly. It highlights that system prompts are not simply static text but rather dynamically created contexts, determined by various conditional statements. This nuance becomes clearer thanks to a recent leak of Claude Code's source code, allowing for an unprecedented look into how these prompts are built. The author outlines specific components that make up the system prompt, distinguishing between components that are always included (solid blue dots) and those that depend on certain conditions (hollow blue dots). For instance, the “Using Your Tools” section is tailored to include only relevant tools. Beyond just the system prompts, the article touches on additional elements like tool definitions, user content, conversation history, attachments, and skills, all of which contribute to the overall context used when a user issues commands. The piece emphasizes the role of context engineering in enhancing the effectiveness of responses generated by Claude Code, specifically when interacting with models like Opus or Sonnet. By detailing how instructions are processed and contextualized, it illustrates that the agents are more than mere models; they rely heavily on sophisticated context management to deliver accurate and relevant results.

Ask about this article