Orientation
| What | Where |
|---|---|
| CLI entrypoint | src/main.tsx |
| Core LLM engine | src/QueryEngine.ts (~46K lines) |
| Tool definitions | src/Tool.ts (~29K lines) |
| Command registry | src/commands.ts (~25K lines) |
| Tool registry | src/tools.ts |
| Context collection | src/context.ts |
| All tool implementations | src/tools/ (40 subdirectories) |
| All command implementations | src/commands/ (~85 subdirectories + 15 files) |
Finding things
How does tool X work?
Every tool lives undersrc/tools/{ToolName}/ and follows a consistent internal layout:
- Go to
src/tools/{ToolName}/ - Open
{ToolName}.tsor{ToolName}.tsxfor the main implementation - Open
UI.tsxfor terminal rendering - Open
prompt.tsfor the system prompt contribution
How does command X work?
- Check
src/commands/{command-name}/(directory) orsrc/commands/{command-name}.ts(file) - Look for
getPromptForCommand()forPromptCommands, or a direct implementation forLocalCommands
How does feature X work?
| Feature | Start here |
|---|---|
| Permissions | src/hooks/toolPermission/ |
| IDE bridge | src/bridge/bridgeMain.ts |
| MCP client | src/services/mcp/ |
| Plugin system | src/plugins/ + src/services/plugins/ |
| Skills | src/skills/ |
| Voice input | src/voice/ + src/services/voice.ts |
| Multi-agent | src/coordinator/ |
| Memory | src/memdir/ |
| Authentication | src/services/oauth/ |
| Config schemas | src/schemas/ |
| State management | src/state/ |
API call flow
Trace from user input through to tool execution and back:Code patterns
Recognizing these recurring patterns speeds up reading unfamiliar files.buildTool() — tool factory
Every tool is constructed through the buildTool factory defined in src/Tool.ts:
Feature flag gates
Build-time feature flags strip code from the bundle when a feature is disabled:Anthropic-internal gates
Some features are only enabled for Anthropic employees:Index re-exports
Most directories expose a public API viaindex.ts:
Lazy dynamic imports
Heavy modules are loaded only when needed to keep startup fast:ESM .js extensions
Bun convention — all imports use .js extensions even when the source file is .ts:
Key files by size
The largest files contain the most logic and are worth prioritizing:| File | Lines | What’s inside |
|---|---|---|
src/QueryEngine.ts | ~46K | Streaming, tool loops, retries, token counting |
src/Tool.ts | ~29K | Tool types, buildTool, permission models |
src/commands.ts | ~25K | Command registry, conditional loading |
src/main.tsx | — | CLI parser, startup optimization |
src/context.ts | — | OS, shell, git, user context assembly |
Study paths
Path 1: How does a tool work end-to-end?
Path 1: How does a tool work end-to-end?
- Read
src/Tool.ts— understand thebuildToolinterface and permission model - Pick a simple tool like
FileReadToolinsrc/tools/FileReadTool/ - Trace how
src/QueryEngine.tscalls tools during the tool-call loop - See how permissions are checked in
src/hooks/toolPermission/
Path 2: How does the UI work?
Path 2: How does the UI work?
- Read
src/screens/REPL.tsx— the main screen component - Explore
src/components/— pick a few components to read - See
src/hooks/useTextInput.ts— how user input is captured - Check
src/ink/— the Ink renderer wrapper
Path 3: How does the IDE integration work?
Path 3: How does the IDE integration work?
- Start at
src/bridge/bridgeMain.ts - Follow
src/bridge/bridgeMessaging.tsfor the message protocol - See
src/bridge/bridgePermissionCallbacks.tsfor how permissions route to the IDE - Check
src/bridge/replBridge.tsfor REPL session bridging
Path 4: How do plugins extend Claude Code?
Path 4: How do plugins extend Claude Code?
- Read
src/types/plugin.ts— the plugin API surface - See
src/services/plugins/— how plugins are loaded - Check
src/plugins/builtinPlugins.ts— built-in examples - Look at
src/plugins/bundled/— bundled plugin code
Path 5: How does MCP work?
Path 5: How does MCP work?
- Read
src/services/mcp/— the MCP client implementation - See
src/tools/MCPTool/— how MCP tools are invoked - Check
src/entrypoints/mcp.ts— Claude Code running as an MCP server - Look at
src/skills/mcpSkillBuilders.ts— skills sourced from MCP
Grep patterns
Usefulripgrep commands for finding things across the codebase:
MCP server for exploration
The repo includes a standalone MCP server inmcp-server/ that lets any MCP-compatible client explore the source code. See the MCP server README for setup instructions.
Once connected, you can ask an AI assistant questions such as:
- “How does the BashTool work?”
- “Search for where permissions are checked”
- “List all files in the bridge directory”
- “Read QueryEngine.ts lines 1–100”
See also
Architecture overview
The full pipeline from CLI entrypoint to terminal UI.
Query Engine
Deep dive into streaming, tool loops, and session management.
MCP
Claude Code as both MCP client and MCP server.
Contributing
How to improve the docs, MCP server, and exploration tooling.