CHAPTER 03 — SOURCE ANALYSIS
The Hidden Instructions
Every time you talk to Claude Code, it reads a secret playbook first — 15,000 characters of rules, memory, and context, assembled in real-time. This chapter shows you exactly what's inside, layer by layer.
What is a system prompt?
Before Claude Code sees your message, it receives a set of hidden instructions from Anthropic. Think of it like a briefing document that a new employee reads on their first day — it tells the AI who it is, what it can do, what to be careful about, and everything it knows about you and your project.
The clever engineering: this briefing is split into two halves. The top half is identical for every user in the world and is cached (shared) — saving 10x on cost. The bottom half is unique to you — your memory, your environment, your tools.
The 7 Layers
Click any layer to explore what’s inside. Layers above the green boundary are cached globally.
Who the AI is and how it should behave
How to approach tasks, use tools, and communicate
utils/api.tsEverything Claude Code remembers about you across sessions
CWD, git branch, OS, model, knowledge cutoff
The only section that recomputes on every single turn
Injected into the user message — NOT the system prompt
How Claude Code Assembles the Prompt
Every time you send a message:
Deep Dive
How the system works under the hood — click to expand
Source Files
constants/prompts.tsSection functions, assembly, boundary markerconstants/systemPromptSections.tsSection registry, memoized vs uncachedutils/claudemd.tsCLAUDE.md discovery, @include, conditional rulesmemdir/memdir.tsMEMORY.md loading, truncation (200 lines / 25KB)context.tsgetSystemContext, getUserContextservices/api/claude.tsbuildSystemPromptBlocks, cache control