DEV Community

김이더
김이더

Posted on

I Tore Apart the Claude Code Source Code

More posts at radarlog.kr.


The Claude Code source code leaked. 1,884 TypeScript files, 31MB total.

Someone already built a clean Mintlify documentation site from it. That site documents about 30 environment variables. The source code has 195. The official docs list maybe 20 slash commands. The source code has over 80.

What's in the rest? I went through it myself.

The Overall Structure

Unzip it and everything sits under src/. The folder structure is cleanly separated by responsibility — like an Unreal Engine project.

src/
├── tools/          (2.8MB) — 40 tool definitions
├── components/     (9.5MB) — Ink-based terminal UI
├── commands/       (2.8MB) — 80+ slash commands
├── services/       (1.9MB) — API, MCP, analytics, compact
├── hooks/          (1.3MB) — React hooks (for terminal UI)
├── utils/          (6.7MB) — utility collection
├── constants/      (122KB) — system prompts, constants
├── coordinator/    (23KB)  — coordinator mode
├── buddy/          (79KB)  — virtual pet system (!?)
└── voice/          (6.5KB) — voice mode
Enter fullscreen mode Exit fullscreen mode

It feels like looking at UE5's Source/ folder. Clean module separation, each tool isolated in its own directory. The tools/ folder has 40 directories, one per tool. Familiar pattern.

The runtime is Bun, not Node. There's a feature() function for build-time feature toggling — dead code elimination, exactly like UE5's WITH_EDITOR compile flag.

const buddy = feature('BUDDY')
  ? require('./commands/buddy/index.js').default
  : null
Enter fullscreen mode Exit fullscreen mode

If feature('BUDDY') evaluates to false at build time, the entire code block gets stripped from the bundle.

Undocumented Slash Commands

The official docs mention /help, /compact, /config, /mcp. The source code reveals many more. Here are the ones that actually work.

/btw — Side question. Ask a quick question without interrupting the main conversation. It's immediate: true, meaning it doesn't pollute the conversation context. Perfect for "btw what does this function do?" while in the middle of a task.

const btw = {
  type: 'local-jsx',
  name: 'btw',
  description: 'Ask a quick side question without interrupting the main conversation',
  immediate: true,
}
Enter fullscreen mode Exit fullscreen mode

/rewind — Roll back code. Restores conversation and code to an earlier checkpoint. Aliased as /checkpoint. This isn't git — Claude Code maintains its own checkpoint system. When things go sideways, you don't restart from scratch. You restart from "here."

/compact — Context summary. This one is documented, but what isn't documented is that it takes arguments. /compact summarize focusing on code changes lets you control the summarization direction. The source code passes user args directly as customInstructions to the summary prompt.

/review — PR code review. Uses the gh CLI to fetch PR diffs and performs a code review. Without a PR number, it lists open PRs.

/advisor — Set an advisor model. You can attach a secondary model as an "advisor" alongside the main model. /advisor opus sets it up. /advisor unset removes it.

/stickers — Order stickers. Opens stickermule.com/claudecode in your browser. Yes, really. It's an easter egg sitting right there in the source.

/sandbox — Sandbox toggle. Controls sandboxed bash execution. On macOS, combined with auto-allow mode, it enables safe "approve everything."

/fast — Fast mode. Switches to a faster model. Only available for Claude AI subscribers and API key users.

/effort — Effort level. low, medium, high, max, auto. Low for simple questions, max for complex refactoring. Direct API cost control.

/passes — Referral system. Share a free week with friends, earn extra usage yourself. Gated by checkCachedPassesEligibility().

/mobile — Mobile app QR. Aliased as /ios, /android. Renders a QR code in the terminal.

195 Environment Variables — The Hidden Surface

Mintlify documented about 30. I grep'd the source and found 195 prefixed with CLAUDE_CODE_.

I won't list them all, but several are genuinely useful in practice.

CLAUDE_CODE_DISABLE_MOUSE — Turns off mouse input entirely. Fixes mouse event conflicts inside tmux.

CLAUDE_CODE_SCROLL_SPEED — Adjusts scroll speed for terminal environments where it's too fast or too slow.

CLAUDE_CODE_TMUX_PREFIX — Resolves tmux prefix key conflicts with Claude Code keybindings.

CLAUDE_CODE_COORDINATOR_MODE — Enables coordinator mode. Claude stops writing code and only orchestrates worker agents. More on this in Part 2.

CLAUDE_CODE_STREAMLINED_OUTPUT — Simplifies output by hiding intermediate tool calls.

CLAUDE_CODE_DISABLE_FILE_CHECKPOINTING — Turns off the file checkpoint system used by /rewind. Useful when disk I/O is a concern.

# Practical combo — lightweight use inside tmux
export CLAUDE_CODE_DISABLE_MOUSE=1
export CLAUDE_CODE_STREAMLINED_OUTPUT=1
export DISABLE_AUTO_COMPACT=1
Enter fullscreen mode Exit fullscreen mode

Keybindings — They're Customizable

Almost nobody knows Claude Code keybindings are fully customizable. There's a defaultBindings.ts and it reads user overrides from keybindings.json.

// Global
'ctrl+t': 'app:toggleTodos',      // Toggle todo list
'ctrl+o': 'app:toggleTranscript',  // View full transcript
'ctrl+r': 'history:search',        // History search

// Chat
'shift+tab': 'chat:cycleMode',     // Cycle mode (plan/code)
'meta+p': 'chat:modelPicker',      // Model picker
'ctrl+s': 'chat:stash',            // Stash current input
'ctrl+g': 'chat:externalEditor',   // Open in external editor

// Tasks
'ctrl+b': 'task:background',       // Background current task
Enter fullscreen mode Exit fullscreen mode

ctrl+b sends the current running task to background. When an agent is doing a long operation, you don't have to wait. You can start typing other input. In tmux, press ctrl+b twice since it conflicts with the tmux prefix.

ctrl+s is stash — like git stash for your current input. Save it now, retrieve it later.

Windows gets different defaults based on VT mode support. The source code literally checks Bun and Node version numbers for VT mode compatibility.

Why Your Mac Doesn't Sleep During Claude Code

It's not luck. There's a caffeinate call in the source.

const CAFFEINATE_TIMEOUT_SECONDS = 300 // 5 minutes
const RESTART_INTERVAL_MS = 4 * 60 * 1000

export function startPreventSleep(): void {
  refCount++
  if (refCount === 1) {
    spawnCaffeinate()
  }
}
Enter fullscreen mode Exit fullscreen mode

Reference counting. Tasks increment on start, decrement on finish. When the count hits zero, the caffeinate process is killed. The 5-minute timeout with 4-minute restarts handles orphan cleanup — if the Node process gets SIGKILL'd, the orphaned caffeinate self-terminates after the timeout.

Same pattern as keepalive checks in game servers. Make sure the child doesn't outlive the parent.

Next — System Prompts and Coordinator Mode

Part 1 covered the surface-level hidden features. Part 2 goes deeper. How the system prompt is assembled, how prompt cache is protected, how coordinator mode orchestrates worker agents. The internal architecture of "AI managing AI."

"The Mintlify docs list 30 environment variables. The source code has 195."

Top comments (0)