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.

15KB
total size
7
layers
10x
cost savings
1
uncached section

The 7 Layers

Click any layer to explore what’s inside. Layers above the green boundary are cached globally.

1
Core Identity

Who the AI is and how it should behave

2
Coding Philosophy & Rules

How to approach tasks, use tools, and communicate

Above: $0.50/MTok cached
10xsavings
__SYSTEM_PROMPT_DYNAMIC_BOUNDARY__
utils/api.ts
Below: $5.00/MTok freshper-session, unique to you
3
Your Memory (MEMORY.md)

Everything Claude Code remembers about you across sessions

4
Environment Info

CWD, git branch, OS, model, knowledge cutoff

5
MCP Server Instructionsuncached

The only section that recomputes on every single turn

6
CLAUDE.md (Project Instructions)user message

Injected into the user message — NOT the system prompt

How Claude Code Assembles the Prompt

Every time you send a message:

1Load static rules (cached, ~8KB)$0.50/MTok
2Add your MEMORY.mdunique to you
3Add environment infoyour CWD, OS, model
4Check MCP serversrecomputed every turn
5Inject CLAUDE.md into user messagenot in system prompt!
6Send to APItotal ~15KB of context

Deep Dive

How the system works under the hood — click to expand

Source Files

constants/prompts.tsSection functions, assembly, boundary marker
constants/systemPromptSections.tsSection registry, memoized vs uncached
utils/claudemd.tsCLAUDE.md discovery, @include, conditional rules
memdir/memdir.tsMEMORY.md loading, truncation (200 lines / 25KB)
context.tsgetSystemContext, getUserContext
services/api/claude.tsbuildSystemPromptBlocks, cache control