Core File Index
Entry & Bootstrap
Section titled “Entry & Bootstrap”| Path | ~Lines | Responsibility |
|---|---|---|
cli/src/index.ts | 150 | CLI entry point, argument parsing, process setup |
cli/src/main.ts | 300 | Bootstrap sequence: config loading → auth → agent initialization |
cli/src/cli.ts | 250 | Commander.js command definitions, flag parsing |
cli/src/constants.ts | 200 | Global constants: model names, timeouts, limits |
Configuration
Section titled “Configuration”| Path | ~Lines | Responsibility |
|---|---|---|
cli/src/config/config.ts | 400 | Multi-source configuration merging (flags > env > project > user > defaults) |
cli/src/config/schema.ts | 350 | Zod schemas for all configuration options |
cli/src/config/claudeMd.ts | 200 | CLAUDE.md file discovery and parsing (project → user → enterprise hierarchy) |
cli/src/config/settings.ts | 250 | Settings persistence and .claude/settings.json management |
Agentic Loop
Section titled “Agentic Loop”| Path | ~Lines | Responsibility |
|---|---|---|
cli/src/agent/agent.ts | 500 | Core agent class: manages the conversation loop lifecycle |
cli/src/agent/agentLoop.ts | 600 | The async generator loop: LLM call → tool dispatch → result collection → repeat |
cli/src/agent/turn.ts | 400 | Single turn processing: stream handling, tool extraction, stop condition checking |
cli/src/agent/stopConditions.ts | 200 | Stop condition evaluation: end_turn, max_tokens, tool_use, error states |
cli/src/agent/costTracker.ts | 300 | Token counting, cost calculation, budget enforcement |
Tool System
Section titled “Tool System”| Path | ~Lines | Responsibility |
|---|---|---|
cli/src/tools/toolRegistry.ts | 350 | Central tool registry: registration, lookup, schema validation |
cli/src/tools/toolExecutor.ts | 400 | Tool execution orchestration: permission check → execute → format result |
cli/src/tools/streamingToolExecutor.ts | 500 | Streaming tool executor: parse partial JSON, execute before stream ends |
cli/src/tools/toolDefinitions.ts | 300 | Tool schema definitions for API (names, descriptions, input schemas) |
cli/src/tools/impl/readFile.ts | 250 | ReadFile tool: file reading with encoding detection, line limiting |
cli/src/tools/impl/writeFile.ts | 350 | WriteFile/Edit tool: file writing with diff generation, backup |
cli/src/tools/impl/bash.ts | 600 | Bash tool: shell command execution with streaming output |
cli/src/tools/impl/glob.ts | 200 | Glob tool: file pattern matching with gitignore respect |
cli/src/tools/impl/grep.ts | 250 | Grep tool: content search with regex support, context lines |
cli/src/tools/impl/webSearch.ts | 200 | WebSearch tool: web search integration |
cli/src/tools/impl/webFetch.ts | 250 | WebFetch tool: URL fetching with HTML-to-markdown conversion |
cli/src/tools/impl/todoWrite.ts | 200 | TodoWrite tool: structured task list management |
cli/src/tools/impl/notebookEdit.ts | 300 | NotebookEdit tool: Jupyter notebook cell manipulation |
Agent Coordination
Section titled “Agent Coordination”| Path | ~Lines | Responsibility |
|---|---|---|
cli/src/agent/fork.ts | 400 | Fork mechanism: spawn parallel independent sub-agents |
cli/src/agent/coordinator.ts | 500 | Coordinator pattern: task planning, worker management, replanning |
cli/src/agent/team.ts | 450 | Team/Swarm pattern: peer agents, mailbox communication |
cli/src/agent/subAgent.ts | 300 | Sub-agent factory: create child agents with shared context prefix |
cli/src/agent/worktree.ts | 250 | Git worktree management for agent isolation |
cli/src/agent/mailbox.ts | 200 | Shared message queue for team communication |
Context Engine
Section titled “Context Engine”| Path | ~Lines | Responsibility |
|---|---|---|
cli/src/context/systemPrompt.ts | 500 | System prompt assembly: identity + capabilities + project context |
cli/src/context/promptCache.ts | 300 | Prompt cache optimization: prefix ordering, cache breakpoint placement |
cli/src/context/compression.ts | 600 | Four-layer compression pipeline: snip → microcompact → auto compact → truncate |
cli/src/context/memory.ts | 350 | Memory system: conversation history management, message formatting |
cli/src/context/tokenCounter.ts | 200 | Token counting utilities: cl100k estimation, budget tracking |
Permission & Security
Section titled “Permission & Security”| Path | ~Lines | Responsibility |
|---|---|---|
cli/src/security/permissionManager.ts | 400 | Permission orchestration: check tool → apply rules → prompt user |
cli/src/security/bashSecurity.ts | 800 | Bash 27-layer security: AST analysis, semantic checks, path validation |
cli/src/security/ruleEngine.ts | 350 | Rule matching engine: pattern-based allow/deny rules from multiple sources |
cli/src/security/pathValidator.ts | 250 | Path validation: project boundary enforcement, symlink resolution |
cli/src/security/threatDetector.ts | 300 | Threat detection: obfuscation, injection, privilege escalation patterns |
Streaming Infrastructure
Section titled “Streaming Infrastructure”| Path | ~Lines | Responsibility |
|---|---|---|
cli/src/streaming/sseParser.ts | 300 | Server-Sent Events parser: raw bytes → typed stream events |
cli/src/streaming/apiStream.ts | 400 | API streaming client: connection management, reconnection, abort handling |
cli/src/streaming/jsonParser.ts | 250 | Incremental JSON parser: partial JSON → complete values for early tool execution |
UI Layer
Section titled “UI Layer”| Path | ~Lines | Responsibility |
|---|---|---|
cli/src/ui/App.tsx | 400 | Root Ink component: layout, theme, global state |
cli/src/ui/MessageDisplay.tsx | 350 | Message rendering: markdown, code blocks, tool results |
cli/src/ui/ToolOutput.tsx | 250 | Tool execution display: spinner, progress, result formatting |
cli/src/ui/PermissionPrompt.tsx | 200 | Permission dialog: tool details, allow/deny/always options |
cli/src/ui/InputArea.tsx | 300 | User input: multiline editing, history, slash commands |
MCP Integration
Section titled “MCP Integration”| Path | ~Lines | Responsibility |
|---|---|---|
cli/src/mcp/mcpClient.ts | 400 | MCP client: connection lifecycle, tool discovery, request routing |
cli/src/mcp/mcpToolAdapter.ts | 250 | Adapts MCP tool schemas to Claude Code’s internal tool format |
cli/src/mcp/mcpConfig.ts | 200 | MCP server configuration: discovery, connection settings |
Hooks & Extensions
Section titled “Hooks & Extensions”| Path | ~Lines | Responsibility |
|---|---|---|
cli/src/hooks/hookRunner.ts | 300 | Hook execution engine: event matching, script execution, timeout management |
cli/src/hooks/hookConfig.ts | 200 | Hook configuration loading from .claude/hooks.json |
cli/src/plugins/pluginLoader.ts | 250 | Plugin discovery and loading: dynamic import, registration |
Summary Statistics
Section titled “Summary Statistics”| Module | Files Listed | ~Total Lines | % of Core |
|---|---|---|---|
| Entry & Bootstrap | 4 | 900 | 3% |
| Configuration | 4 | 1,200 | 5% |
| Agentic Loop | 5 | 2,000 | 8% |
| Tool System | 13 | 4,200 | 16% |
| Agent Coordination | 6 | 2,100 | 8% |
| Context Engine | 5 | 1,950 | 7% |
| Permission & Security | 5 | 2,100 | 8% |
| Streaming | 3 | 950 | 4% |
| UI Layer | 5 | 1,500 | 6% |
| MCP | 3 | 850 | 3% |
| Hooks & Extensions | 3 | 750 | 3% |
| Total (top 56 files) | 56 | ~18,500 | ~4% of 512K |