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.

Full source code
Actionable insights
KAIROS — Background Agent
// src/commands/assistant.ts
export const KAIROS = "kairos"
// persistent daemon, survives terminal close
// push notifications, GitHub webhooks
featureFlag: "KAIROS"

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:

~/.claude/CLAUDE.md— global (your coding style, preferences)
./CLAUDE.md— project level (architecture decisions, conventions)
.claude/rules/*.md— modular rules (scoped instructions)
CLAUDE.local.md— private notes (gitignored)

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.

// The compaction prompt literally says:
"Do NOT call any tools. Tool calls will be REJECTED."
// Because Sonnet 4.6+ sometimes tries to call tools
// during the compaction summary. Anthropic had to
// add this explicitly to stop it.

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:

PreToolUse

Runs before any tool executes

PostToolUse

Runs after any tool completes

UserPromptSubmit

Runs when you send a message

SessionStart

Session lifecycle start

TaskCreated

When a task is spawned

StopHook

After model completes a turn

With 5 types of hooks:

command — run a shell command
prompt — inject context via LLM
agent — run a full agent verification loop
HTTP — call a webhook
function — run JavaScript

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 05

What's coming next.

Nine features hidden behind feature flags. None of these are documented. All of them are partially or fully implemented in the codebase.

KAIROS — Persistent Background Agent

featureFlag: "KAIROS" | "KAIROS_BRIEF" | "KAIROS_PUSH_NOTIFICATION" | "KAIROS_GITHUB_WEBHOOKS"

Claude Code is building a mode where Claude runs persistently in the background. Activated via claude assistant.

  • Suggests actions proactively without you asking
  • Send push notifications to your device
  • Subscribe to GitHub PR events (review comments, CI results)
  • Manage teams of sub-agents
  • Survives terminal closure
  • Maintains daily memory logs

Voice Mode — Push to Talk

featureFlag: "VOICE_MODE"

Push-to-talk voice input using Anthropic's voice_stream WebSocket STT endpoint.

  • Uses native audio capture (cpal) on macOS/Linux/Windows
  • Hold Space to talk
  • Fallback to SoX for unsupported platforms
  • STT provider: Deepgram Nova 3

Background Sessions

featureFlag: "BG_SESSIONS"

Run sessions in tmux with claude --bg. List with claude ps. View logs with claude logs. Reconnect with claude attach. Stop with claude kill.

Ultraplan — 30-Minute Deep Planning

featureFlag: "ULTRAPLAN"

Sends your task to a remote Claude Code Remote instance running Opus for up to 30 minutes of deep planning. Multi-agent exploration with full context.

SSH Remote

featureFlag: "SSH_REMOTE"

claude ssh <host> [dir] — deploys the Claude Code binary to a remote host and tunnels API auth back. No remote setup needed.

Daemon Mode

featureFlag: "DAEMON"

claude daemon — a long-running supervisor process that manages background workers. The foundation for persistent agent infrastructure.

Computer Use MCP (codename "Chicago")

Chicago
featureFlag: "CHICAGO_MCP"

Built-in computer use via MCP server. Enabled with the --computer-use-mcp flag. Claude can see your screen and interact with your desktop.

Coordinator Mode — Multi-Agent Orchestration

featureFlag: "COORDINATOR_MODE" | CLAUDE_CODE_COORDINATOR_MODE=1

Claude becomes a multi-agent orchestrator spawning parallel workers. Workers run independently and report back. Shared scratchpad for coordination.

Fork Subagent

featureFlag: "FORK_SUBAGENT"

/fork creates a subagent that inherits your full conversation context. Runs in background, reports back in under 500 words. Children can't spawn sub-forks.

Section 06

Commands nobody told you about.

13 undocumented slash commands available to all users, plus 5 internal-only commands for Anthropic employees.

Available to all users
/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
Anthropic internal only
/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 pipeline

Section 07

Environment variables that change everything.

Copy-paste these into your shell to unlock hidden behavior.

# Kill switches
CLAUDE_CODE_DISABLE_THINKING=1# Disable extended thinking
DISABLE_AUTO_COMPACT=1# Stop automatic context compaction
CLAUDE_CODE_DISABLE_AUTO_MEMORY=1# Stop auto memory extraction
CLAUDE_CODE_DISABLE_BACKGROUND_TASKS=1# No background processing
CLAUDE_CODE_DISABLE_CLAUDE_MDS=1# Ignore all CLAUDE.md files
# Tuning
BASH_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 limit
CLAUDE_CODE_SCROLL_SPEED=3# Fix scroll speed for some terminals
# Power user
CLAUDE_CODE_ABLATION_BASELINE=1# Disable ALL smart features at once
CLAUDE_CODE_SIMPLE=1# Bare minimum mode

Section 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.

ModelInput/1MOutput/1MCache WriteCache 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.

undercover_mode.ts
// src/permissions/undercover.ts
if (isAnthropicEmployee && isPublicRepo) {
mode = "UNDERCOVER"
// You are operating UNDERCOVER in a
// PUBLIC/OPEN-SOURCE repository.
// Do not blow your cover.
}

What gets stripped:

Co-Authored-By: Claude <claude@anthropic.com>
(removed entirely)
Model codenames: Capybara, Tengu
(scrubbed from output)
"Fixed by Claude Opus 4.6"
"Fix race condition in file watcher initialization"
Internal repo names, Claude Code mentions
(all references removed)

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.

[Claude Opus 4.6] Refactored file watcher with enhanced race condition handling — Co-Authored-By: Claude

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

duckgooseblobcatdragonoctopusowlpenguinturtlesnailghostaxolotlcapybaracactusrobotrabbitmushroomchonk
Common
60%
Uncommon
25%
Rare
10%
Epic
4%
Legendary
1%
👀

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:

Boondoggling...
BoondogglingCanoodlingFlibbertigibbetingDiscombobulatingShenaniganingLollygaggingBamboozlingSnorkelingGallivantingWibble-wobblingPerambulatingRazzle-dazzlingCattywampusingSkedaddlingHornswogglingRigamarolingBallyhoo-ingWhatchamacallitingGobsmackingLickety-splittingTopsy-turvyingKerfufflingCodswallopingHiggledy-pigglingFiddle-faddlingWilly-nillyingArgle-barglingNamby-pambyingFlim-flammingPitter-patteringRiff-raffingHobnobbingMish-mashingHelter-skelteringWishy-washyingDilly-dallyingShilly-shallyingPell-mellingRoly-polyingHurly-burlyingHumdrum-drummingHubbub-bubblingJiggery-pokeryingMumbo-jumboingHokey-pokeyingHanky-pankyingHocus-pocusingItsy-bitsyingToing-and-froingZig-zagging

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.