claude-code-source-analysis (JimmyWangJimmy)
Smaller independent analysis 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.
Claude Code's read-before-edit prompt rules
"Do not propose changes to code you haven't read." "If a user asks about or wants you to modify a file, read it first." "Understand existing code before suggesting modifications."
Verbatim system-prompt lines that suppress hallucinated edits by forcing the model to build context before touching a file.
chapters/04-system-prompt.md
Claude Code's over-engineering suppression rules
"Avoid over-engineering. Only make changes that are directly requested." "Don't add features, refactor code, or make 'improvements' beyond what was asked." "Don't add docstrings, comments, or type annotations to code you didn't change." "Three similar lines of code is better than a premature abstraction."
Anthropic observed LLMs habitually gold-plate code, so the prompt explicitly forbids it - the last line is a design principle worth stealing.
chapters/04-system-prompt.md
MEMORY.md limits and the memory taxonomy
Entry file MEMORY.md: always loaded into session context; hard limit 200 lines / 25KB; overflow is truncated. Design intent: MEMORY.md is an index, details live in sub-files. Memory file frontmatter types: user (always private: role, goals, preferences), feedback (method guidance, style), project (work, goals, events), reference (pointers to external systems). Drift protection, verbatim from the system prompt: "Memories are snapshots - must verify against current state", "Read before recommending from memory".
The complete recipe for file-based agent memory: a size-capped always-loaded index, typed memory files, and explicit staleness warnings.
chapters/08-memory-context.md
Fork agents share the parent's prompt cache
Pattern 8: Fork Agent Prompt Cache sharing Parent Agent Prompt = P Fork Agent Prompt = P (byte-identical) -> Anthropic API prompt cache hit! Problem: child-agent API calls waste prompt tokens on repetition Solution: fork agents keep their prompt exactly identical to the parent Key point: this is not about optimizing transfer - it exploits the API-side cache. Pattern 7: permission fatigue - a consecutive-denial counter escalates to a batch permission request instead of asking one-by-one.
[translated] Two production patterns rarely written down: byte-identical fork prompts for cache hits, and detecting permission fatigue before users rage-quit.
chapters/11-design-patterns.md