claude code source analysis
We read
every line.
So you don't have to.
Claude Code's entire source code leaked. Thousands of files. An agent orchestration platform disguised as a terminal chat. We read all of it. Here's what the source code reveals about how to actually use this thing.
Contents
Everything we found — from practical tips to hidden features.
Section 01
CLAUDE.md is loaded every single turn.
This is the single highest leverage thing you can do and almost nobody does it properly.
The source code shows that Claude Code reads your CLAUDE.md files on every query iteration. Not at session start. Every turn. That means every time you send a message, it re-reads your instructions.
There's a whole hierarchy:
You get 40,000 characters. That's a LOT. Most people use maybe 200. Put your architecture decisions in there. Your file conventions. Your testing patterns. Your "never do this" rules. The model reads them every single turn.
This is the difference between Claude Code being a generic assistant and Claude Code being your assistant that knows your codebase.
💡 If you do one thing after reading this:
Write a real CLAUDE.md for your project. Architecture, conventions, testing patterns, file structure. 40K chars. Loaded every turn. Highest leverage config you have.
Section 02
Subagents share the prompt cache.
Parallelism is basically free. This blew our minds.
When Claude Code forks a subagent, it creates a byte-identical copy of the parent context. The API caches this. So spawning 5 agents to work on different parts of your codebase costs barely more than 1 agent doing it sequentially.
Read that again. 5 agents. Same cost as 1. Because they all hit the prompt cache.
The source code has three execution models for subagents:
Fork
Inherits parent context. Cache-optimized. Max 200 turns. Reports back in under 500 words. Can't spawn sub-forks.
Teammate
Separate pane in tmux/iTerm. Communicates via file-based mailbox. Full tool access. Runs in parallel.
Worktree
Gets its own git worktree. Isolated branch per agent. No merge conflicts between parallel workers.
There are also 5 built-in agent types: general-purpose, Explore (read-only search, uses Haiku), Plan (architect, read-only), Verification (adversarial — tries to break your code), and Guide (help with Claude Code itself).
💡 Stop using Claude Code single-threaded.
Tell it to spin up 5 agents: one doing a security audit, one refactoring, one writing tests, one updating docs, one fixing bugs. All at the same time. All sharing the cache. The architecture is built for this.
Section 03
5 compaction strategies. Context is everything.
The source has FIVE different ways to compress your conversation when it gets too long. This tells you context overflow is a central problem the engineers spent a LOT of time on.
What this means for you: use /compact proactively. Don't wait for the system to auto-compact and lose context you care about. The default window is 200K tokens, but you can opt into 1M with the [1m] model suffix.
Long sessions accumulate "session memory" — structured summaries of task specs, file lists, workflow state, errors, and learnings. This is why resuming a session is better than starting fresh. Use --continue. Always.
💡 After compaction, Claude can re-read its own transcript to recover context it needs.
Section 04
The hook system is the real extension API.
25+ lifecycle events. 5 hook types. Almost nobody knows about this.
The source code reveals 25+ lifecycle events you can hook into:
PreToolUseRuns before any tool executes
PostToolUseRuns after any tool completes
UserPromptSubmitRuns when you send a message
SessionStartSession lifecycle start
TaskCreatedWhen a task is spawned
StopHookAfter model completes a turn
With 5 types of hooks:
The UserPromptSubmit hook is especially powerful. You can inject additionalContext into every single message. Automatically attach test output, recent git diffs, or project state to every prompt — without typing it.
💡 Real examples of what you can build:
Auto-run linting before every file write. Run tests after every edit. Inject relevant docs into every prompt. Send Slack notifications when tasks complete. Validate security patterns before code ships. This is how you build a custom dev environment on top of Claude Code — not by prompting better, by hooking into the system.
Section 06
Commands nobody told you about.
13 undocumented slash commands available to all users, plus 5 internal-only commands for Anthropic employees.
/btwAsk a side question without interrupting main conversation/contextVisualize context usage as a colored grid/diffView uncommitted changes and per-turn diffs/stickersOrder physical Claude Code stickers (stickermule.com)/insightsGenerate comprehensive session analysis report (3,200-line module!)/advisor opusEnable a second model that watches and advises/desktopHand off session to Claude Desktop app/mobileQR code to download Claude mobile app/think-back"Your 2025 Claude Code Year in Review" animation/ultraplan30-min deep planning with remote Opus agent/buddyYour virtual companion pet/forkFork conversation into background subagent/bridgeRemote control mode/break-cacheForce invalidate prompt cache/good-claudeGood Claude mode (stubbed)/dump-system-promptPrint full system prompt/bughunterBug hunter tool/commit-push-prFull commit → push → PR → Slack pipelineSection 07
Environment variables that change everything.
Copy-paste these into your shell to unlock hidden behavior.
CLAUDE_CODE_DISABLE_THINKING=1# Disable extended thinkingDISABLE_AUTO_COMPACT=1# Stop automatic context compactionCLAUDE_CODE_DISABLE_AUTO_MEMORY=1# Stop auto memory extractionCLAUDE_CODE_DISABLE_BACKGROUND_TASKS=1# No background processingCLAUDE_CODE_DISABLE_CLAUDE_MDS=1# Ignore all CLAUDE.md filesBASH_DEFAULT_TIMEOUT_MS=600000# 10min bash timeout (default 2min)CLAUDE_CODE_MAX_TOOL_USE_CONCURRENCY=20# Max parallel tool calls (default 10)CLAUDE_CODE_FILE_READ_MAX_OUTPUT_TOKENS=50000# Double the default file read limitCLAUDE_CODE_SCROLL_SPEED=3# Fix scroll speed for some terminalsCLAUDE_CODE_ABLATION_BASELINE=1# Disable ALL smart features at onceCLAUDE_CODE_SIMPLE=1# Bare minimum modeSection 08
The real cost math.
Per-million-token pricing pulled directly from the source. These are the rates hardcoded into Claude Code's cost calculator.
| Model | Input/1M | Output/1M | Cache Write | Cache Read |
|---|---|---|---|---|
| Sonnet 4/4.5/4.6 | $3 | $15 | $3.75 | $0.30 |
| Opus 4.5/4.6 | $5 | $25 | $6.25 | $0.50 |
| Opus 4.6 (fast) | $30 | $150 | $37.50 | $3.00 |
| Haiku 4.5 | $1 | $5 | $1.25 | $0.10 |
| Opus 4/4.1 | $15 | $75 | $18.75 | $1.50 |
Output capped at 8K tokens
Not 32K as docs suggest. Default maxOutputTokens is 16,384 but effective is 8,192 per turn.
Cache expires in 5 minutes
Prompt cache TTL is 300s. Auto-compact triggers at ~87% of context window. Unknown models default to $5/$25 tier.
Section 09
Every tool's real limits.
The actual constraints hardcoded into each tool. These determine what Claude Code can and can't do per turn.
Bash
- 2-minute default timeout (max 10 minutes with env var)
- 30K character inline output limit
- 64MB persisted output to file
- Auto-backgrounds after 120 seconds
File Read
- 2,000 lines max per read
- 256KB default file size limit
- 25K tokens output limit
- Deduplicates unchanged files (saves ~18% tokens)
File Edit
- Must read file first (enforced by runtime)
- Max 1GiB file size
- Fuzzy quote matching for edit anchors
- Blocks editing binary files
Web Search
- Max 8 searches per tool call
- US region only
- Uses Haiku internally for result processing
- Not available in all plans
Web Fetch
- 10MB max response
- 60-second timeout
- 15-minute URL cache
- 125-char quote limit for non-preapproved domains
- ~130 preapproved domains (GitHub, npm, MDN, etc.)
Agent / Subagent
- 5 built-in types: general, explore, plan, verification, guide
- Max 200 turns for fork subagents
- Report-back limit: 500 words
- Children cannot spawn sub-forks
Section 10
Undercover Mode.
When Anthropic hides Claude.
When Anthropic employees contribute to open-source repos, undercover mode activates automatically. Claude is told to hide all traces of its involvement.
What gets stripped:
Can force ON, but NEVER force OFF
Safety net against leaks. Once undercover mode activates for a repository, there's no way to disable it.
Internal codenames revealed
Capybara = model codename. Tengu = Claude Code's internal project codename. Shows "undercover" in the status bar on internal builds.
Section 11
Buddy. The virtual pet nobody expected.
Yes, really. Claude Code has a fully implemented virtual pet system buried in its source. Your pet is deterministically generated from your user ID — you can't change or cheat it.
18 Species
6 Eye Styles
8 Hats
Commons get no hat. Uncommon+ only. Crown, tophat, propeller, halo, wizard, beanie, tinyduck.
1% Shiny Chance
Your buddy has a 1% chance of being shiny. Deterministic — same ID, same result.
🔍 The species "capybara" collides with an internal model codename, so ALL species names are hex-encoded in the source to avoid build-time string checks. Teaser window: April 1-7, 2026.
What's your buddy?
Section 09
204 things Claude Code says while thinking.
The thinking spinner isn't random. There are exactly 204 verbs hardcoded into the source. Here are some highlights:
One more thing
Now imagine controlling
all of this from your phone.
Broski gives you a native iOS interface to manage Claude Code sessions, approve permissions, browse files, and chat — all from your pocket. KAIROS running in the background? Monitor it. Session costs piling up? Track them. Permissions pending? Approve from the bus.