Tier 1 · Claude Code internals Claude Code internals · fetched 2026-07-02
Claude-Code-Source-Study
Smaller independent study of the Claude Code source; skimmed for unique observations to cross-check the major bundles.
View source on GitHubKey takeaways
- 01
Use as a cross-check witness against the book-length analyses
From the archive
Verbatim excerpts mined from our local archive of this repository — the prompts, schemas, and patterns worth stealing.
Memory
Load order is reversed because of recency bias
// Files are loaded in the following order: // 1. Managed memory (eg. /etc/claude-code/CLAUDE.md) - Global instructions for all users // 2. User memory (~/.claude/CLAUDE.md) - Private global instructions // 3. Project memory (CLAUDE.md, .claude/CLAUDE.md, .claude/rules/*.md) // 4. Local memory (CLAUDE.local.md) - Private project-specific instructions // Files are loaded in reverse order of priority, i.e. the latest files are highest priority The subtle design: LLMs attend more to content that appears LATER in the message (recency bias), so the highest-priority memory is deliberately placed last.
[translated] Priority in prompt design isn't metadata - it's position. The loader exploits recency bias by putting what matters most at the end.
docs/23-Memory系统.md
Insight
One env var away from a minimal agent
// Minimal mode: return only the smallest possible prompt
if (isEnvTruthy(process.env.CLAUDE_CODE_SIMPLE)) {
return [
`You are Claude Code, Anthropic's official CLI for Claude.\n\nCWD: ${getCwd()}\nDate: ${getSessionStartDate()}`,
]
}
// ...then parallel prefetch:
const [skillToolCommands, outputStyleConfig, envInfo] = await Promise.all([...])
Internal/external split: process.env.USER_TYPE === 'ant' produces different behavioral guidance from the same code. [translated] The 915-line prompt assembly keeps an escape hatch: identity + cwd + date is the irreducible minimum a coding agent needs to function.
docs/04-System-Prompt-工程.md