Skip to main content
Every action Claude Code can perform — reading a file, running a shell command, searching the web — is implemented as a tool. Tools are self-contained modules registered in 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

This loop repeats until Claude returns a plain text response with no tool calls.

Tool anatomy

Every tool is a TypeScript module that exports an object conforming to the Tool 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 a ToolUseContext (working directory, abort signal, permission mode, etc.) and returns a result that Claude can read.

Tool registration

All tools are registered in src/tools.ts. Some tools are always included; others are conditionally loaded based on feature flags or environment variables:
MCP tools are registered dynamically at runtime when an MCP server connects.

Built-in 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.
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.
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.
Granting BashTool broad allow rules or running with bypassPermissions gives Claude unrestricted shell access. Only do this in isolated environments you control.
Tools for spawning sub-agents and coordinating multi-agent work.See Agent tools reference for full input schemas and the Agent swarms guide.
Tools for fetching content from the web.See Web tools reference.
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.

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.