Quick Reference

All in one page: core concepts, common tools, key source code entry points.

Core Concepts Quick Reference

ConceptOne-Sentence ExplanationDetails
Agent LoopA cycle of user input → model decision → tool execution → result injection, until the model returns plain textChapter 2
query()The async generator implementation of the core loop, containing 7 continue sites handling different resume strategiesSection 2.4
QueryEngineA session-level manager that drives query() and handles budgets, permissions, and structured outputSection 2.3
AutocompactAn automatic compaction mechanism triggered when token usage approaches the context window (~93.5% utilization)Section 3.6
Context CollapseA projection-based read-only context folding mechanism that doesn’t modify original messages and can safely roll backSection 3.7
CLAUDE.mdA project-level instruction file, discovered by traversing the directory tree upward from CWD, supporting multiple levelsSection 3.2
buildTool()A tool factory function that merges TOOL_DEFAULTS (fail-closed defaults) with tool definitionsSection 4.1
MCPModel Context Protocol, an external tool extension protocol supporting 7 transport mechanismsSection 4.9
ToolSearchA lazy-loading mechanism that loads only needed tools on demand from 50+, reducing prompt size per API callSection 4.10
search-and-replaceThe editing strategy of FileEditTool, requiring old_string to match uniquely within the fileChapter 10
Defense in Depth7 independent security check layers, where bypassing any single layer is not fatalChapter 12
Plan ModeTwo-phase execution: read-only exploration → user approval → writable implementationSection 8.6
Coordinator ModeThe main Agent only orchestrates without executing, completing actual tasks through WorkersSection 8.3
HooksAn event-driven extension mechanism that injects custom logic at key points in the tool execution lifecycleChapter 7

Common Tools List

File Operations

ToolRead-OnlyConcurrency-SafeDescription
Read (FileReadTool)Read files, supports line ranges, PDF, images
Write (FileWriteTool)Write/create files
Edit (FileEditTool)search-and-replace editing, requires unique match
NotebookEditJupyter Notebook editing

Search and Navigation

ToolRead-OnlyConcurrency-SafeDescription
Glob (GlobTool)Filename pattern matching search
Grep (GrepTool)File content regex search (based on ripgrep)
ToolSearch (ToolSearchTool)Dynamically discover lazily-loaded tools

Execution and System

ToolRead-OnlyConcurrency-SafeDescription
Bash (BashTool)Execute shell commands, 7-layer security validation
Agent (AgentTool)Spawn sub-Agents to execute independent tasks
SendMessageSend messages to existing Agents or teammates
TaskStopTerminate a sub-Agent

Mode Control

ToolDescription
EnterPlanModeEnter Plan mode (read-only exploration phase)
ExitPlanModeExit Plan mode and submit the plan for approval

Key Source Code Entry Points

ModuleEntry FileLinesResponsibility
CLI Entrysrc/main.tsx~4,700Commander.js argument parsing, run mode dispatching
Agent Loopsrc/query.ts~1,730Async generator implementation of the core loop
Session Managementsrc/QueryEngine.ts~1,160Conversation lifecycle management
Tool Interfacesrc/Tool.ts~200Tool type definitions and buildTool factory
System Promptssrc/constants/prompts.ts~2,400Complete system prompt templates
Permission Systemsrc/utils/permissions/~multiple filesMulti-layer permission checks and rule matching
Bash Securitysrc/tools/BashTool/bashSecurity.ts~1,20023 static security validators
Context Assemblysrc/context.ts~190System/user context construction
Compaction Servicesrc/services/compact/~multiple filesAutocompact, Snip, Context Collapse
MCP Clientsrc/services/mcp/client.ts~3,350MCP connection management and tool registration
Hooks Enginesrc/hooks/~multiple filesHook event dispatching and execution
Multi-Agentsrc/coordinator/~multiple filesCoordinator mode implementation
Swarm Backendsrc/utils/swarm/backends/~multiple filesTmux/iTerm2/InProcess execution backends

Key Thresholds and Constants

ConstantValueSourcePurpose
AUTOCOMPACT_BUFFER_TOKENS13,000autoCompact.tsAuto-compaction trigger buffer
MAX_CONSECUTIVE_AUTOCOMPACT_FAILURES3autoCompact.tsCompaction circuit breaker threshold
CAPPED_DEFAULT_MAX_TOKENS8,000context.tsDefault output token cap (saves slots)
ESCALATED_MAX_TOKENS64,000context.tsEscalated output cap after truncation
MAX_OUTPUT_TOKENS_FOR_SUMMARY20,000autoCompact.tsReserved output space for compaction summary
DEFAULT_MAX_RESULT_SIZE_CHARS50,000toolLimits.tsMaximum characters for tool results
MAX_TOOL_RESULT_TOKENS100,000toolLimits.tsMaximum tokens for tool results
DENIAL_LIMITS.maxConsecutive3denialTracking.tsFall back to interactive confirmation after consecutive denials
DENIAL_LIMITS.maxTotal20denialTracking.tsUpper limit on total denials
WARNING_THRESHOLD0.7 (70%)rateLimitMessages.tsRate limit warning threshold
POST_MAX_RETRIES10SSETransport.tsMaximum retry count for POST requests
RECONNECT_GIVE_UP_MS600,000 (10min)SSETransport.tsSSE reconnection give-up time
LIVENESS_TIMEOUT_MS45,000SSETransport.tsHeartbeat timeout (server sends every 15s)

Back to: Quick Start | Home