src/tools.ts. Claude decides which tool to call, the permission layer checks whether to allow it, and the result is fed back into the next API turn.
How the tool loop works
Tool anatomy
Every tool is a TypeScript module that exports an object conforming to theTool interface defined in src/Tool.ts. The three required parts are:
1. Input schema (Zod)
Tools declare their inputs using Zod v4 schemas. The schema is compiled to JSON Schema and sent to the Anthropic API so Claude knows what arguments are valid.2. Permission declaration
Each tool declares whether it is read-only, mutating, or dangerous. This declaration is used by the permission layer to decide the default behavior before prompting the user.3. Execute function
The execute function receives validated input and aToolUseContext (working directory, abort signal, permission mode, etc.) and returns a result that Claude can read.
Tool registration
All tools are registered insrc/tools.ts. Some tools are always included; others are conditionally loaded based on feature flags or environment variables:
Built-in tools
File tools
File tools
Tools for reading, writing, and editing files on disk.
File read and write operations are subject to the permission model. Write and edit tools require explicit user approval in default mode.See File tools reference for full input schemas.
Search tools
Search tools
Tools for finding files and content across the codebase.
GrepTool shells out to rg for performance. It supports full regex syntax and file-type filters.See Search tools reference for full input schemas.Shell tools
Shell tools
Tools for executing shell commands and running processes.
BashTool is the most permissive built-in tool. It runs arbitrary shell commands and is classified as dangerous — it will always prompt for approval in default mode unless you have added an allow rule.Agent tools
Agent tools
Tools for spawning sub-agents and coordinating multi-agent work.
See Agent tools reference for full input schemas and the Agent swarms guide.
Web tools
Web tools
MCP tools
MCP tools
Tools exposed by connected Model Context Protocol servers.
MCP tools are registered dynamically when servers connect and are namespaced by server name to avoid collisions. See MCP servers.
Tool permission levels
Tools declare one of three permission levels that determine the default approval behavior:
The permission level is a default. You can override it for specific tools or patterns using allow/deny rules in your settings. See Permission model.
Related pages
Permission model
How every tool call is checked before execution.
File tools
Full reference for file read, write, and edit tools.
Search tools
Full reference for glob and grep tools.
MCP servers
Connect external tools via the Model Context Protocol.