Skip to content
Flows
Tier 1 · Claude Code internals Claude Code internals · fetched 2026-07-02

claudecode-source (annotated bundle)

Packages a deep source-level analysis of a Claude Code snapshot (~1,900 files) with HTML reports, architecture visuals, and walkthrough guides, plus an independently written source-analysis report in Chinese and English. One of the most complete single bundles for studying the tool definitions, main agent loop, and edit-validation path.

View source on GitHub

Key takeaways

  • 01

    Study the tool definition modules to see how schemas constrain model behavior

  • 02

    The main loop folds tool results back into context in a strict sequence

  • 03

    Edits are validated (read-before-write, diff checks) before hitting disk

Flows built on this research

From the archive

Verbatim excerpts mined from our local archive of this repository — the prompts, schemas, and patterns worth stealing.

Prompt

The companion (BUDDY) easter-egg prompt

# Companion

A small ${species} named ${name} sits beside the user's input box and occasionally comments in a speech bubble. You're not ${name} - it's a separate watcher.

When the user addresses ${name} directly (by name), its bubble will answer. Your job in that moment is to stay out of the way: respond in ONE line or less, or just answer any part of the message meant for you. Don't explain that you're not ${name} - they know. Don't narrate what ${name} might say - the bubble handles that.

From the most complete restored Claude Code source tree: even an easter egg gets careful identity-boundary prompting so two AI personas never talk over each other.

src/buddy/prompt.ts

Insight

A 54KB prompts.ts is the heart of the harness

src/constants/prompts.ts (54,320 bytes) imports from: git state, cwd, worktree session, session start date, settings, AgentTool constants, FileWrite/FileRead/FileEdit/TodoWrite/TaskCreate/Bash/Skill/Glob/Grep/AskUserQuestion tool names, model marketing names, MCP server types, output styles, Explore agent config, scratchpad permissions, REPL mode...

// biome-ignore-all assist/source/organizeImports: ANT-ONLY import markers must not be reordered

The system prompt is assembled from the live state of nearly every subsystem - prompt engineering at production scale is state management, not copywriting.

src/constants/prompts.ts