This page covers the built-in tool framework: registration, schema injection, permission checks, and execution flow. The per-tool catalog belongs on separate reference pages.
What a tool is in Claude Code
In this codebase, a tool is not just a callable function. It is a typed runtime object with:- A stable name exposed to the model
- A Zod input schema
- A JSON schema projection for model context
- Validation and permission hooks
- Optional UI rendering and progress updates
- Execution behavior such as concurrency and interruption rules
src/Tool.ts. Execution happens in src/services/tools/toolExecution.ts and src/services/tools/StreamingToolExecutor.ts.
High-level architecture
Tool definition pattern
Claude Code uses a common tool contract rather than ad hoc function calls. The important shared concepts visible insrc/Tool.ts are:
ToolInputJSONSchema: the JSON-schema-like shape handed to the modelToolPermissionContext: permission mode plus allow, deny, and ask rulesToolUseContext: the per-turn execution context, including app state, abort signals, tools, commands, MCP clients, and thinking config
ToolUseContext is load-bearing. It is how tools reach session state without owning global state directly.
What the model actually sees
Tools are injected into the prompt as schemas, not as source code. The model gets:- The tool name
- The description
- The input schema
- Any prompt-side guidance specific to the tool
Main tool categories
The source tree groups tools by capability. The major categories are:- File and code editing: read, write, edit, notebook tools
- Shell execution:
BashTool,PowerShellTool - Web access: fetch and search
- Agent orchestration: subagents and task-oriented tools
- MCP bridge tools: remote server tools, MCP auth, resource listing, resource reads
- Meta and output tools: synthetic output, structured output, brief, skill tool
Execution lifecycle
The common execution path insrc/services/tools/toolExecution.ts is:
- Find the tool by name.
- Parse input with the tool’s Zod schema.
- Resolve permission behavior.
- Run pre-tool hooks and safety checks.
- Execute the tool and stream progress messages.
- Convert the result into assistant-visible
tool_resultmessages. - Feed those results back into the main query loop.
Permissions and approvals
Permission logic is split between shared infrastructure and tool-specific behavior. Shared layer:- Permission mode is carried through
ToolPermissionContext - Rules can come from session state, user settings, local settings, policy settings, CLI args, or managed config
- The framework records why a decision happened, not just the decision itself
- A tool can define extra checks after validation
- Some tools reason about command prefixes, paths, domains, or content before approval
- Some tools can be auto-approved in specific contexts
Concurrency model
Claude Code can execute some tools while the model is still streaming more output.StreamingToolExecutor manages this.
- Concurrency-safe tools may run in parallel
- Non-concurrent tools require exclusive access
- Results are buffered so the model still sees them in arrival order
- A sibling error can cancel parallel tools to avoid inconsistent state
Interrupt behavior
Tools are not all interruptible in the same way.- Some tools can be cancelled when the user interrupts the turn
- Others are treated as blocking and must finish or fail explicitly
- Parallel tool cancellation uses a child abort controller, so one failed tool does not automatically terminate the whole query loop
Deferred and dynamically loaded tools
Not every tool is loaded eagerly.- The code distinguishes always-loaded versus deferred tools
- MCP tools are registered dynamically as servers connect
- Skills can surface model-invocable functionality through the skill tool path
MCP tools are normalized into the same model
External MCP tools are adapted into Claude Code’s internal tool format rather than handled as a separate execution universe. That means MCP tools participate in:- Name normalization
- Permission routing
- Progress reporting
- Error shaping
- Result injection back into the loop
Design takeaways
The tool system is built around a few consistent constraints:- Tool calls must be serializable into model context
- Execution must survive partial failures
- Permissions must remain explainable
- Streaming must not reorder semantic results
- External integrations must fit the same contract as built-ins