CC
Claude Code
v2.1.88

Tools

43 tools

Claude Code has 43 built-in tools, each implementing a unified Tool<Input, Output, Progress> interface. Tools are built via the buildTool() factory and validated with Zod schemas at runtime.

TL;DR — Key Takeaways
  • All 43 tools implement the same Tool<Input, Output, Progress> interface and are built via buildTool() — same pattern whether it's Bash, FileEdit, or MCP.
  • Read-only tools (FileRead, Grep, Glob) run up to 10 in parallel. Write tools serialize. This split is why reading feels fast but edits are sequential.
  • The Agent tool spawns a full isolated sub-agent with zero-cost cache sharing — the child inherits the exact same system prompt bytes, auto-hitting the parent's prompt cache.

Tool Interface (Tool.ts)

Start here if you want the mental model that unifies Bash, Edit, MCP, Agent, and the rest.

typescript
interface Tool<Input, Output, Progress> {
  name: string
  aliases?: string[]              // backwards compatibility
  searchHint?: string             // for ToolSearch keyword matching
  inputSchema: ZodSchema          // validated at runtime
  strict?: boolean                // strict API mode

  // Core execution
  call(args, context, canUseTool, parentMessage, onProgress): Promise<ToolResult>

  // Metadata
  description(input, options): Promise<string>
  prompt(): string                // system prompt instructions
  userFacingName(): string        // display name for UI

  // Security
  validateInput(): ValidationResult
  checkPermissions(): PermissionResult
  isReadOnly(): boolean
  isDestructive(): boolean
  isConcurrencySafe(): boolean

  // Rendering
  renderToolUseMessage(): ReactNode
  renderToolResultMessage(): ReactNode
  getToolUseSummary(): string     // compact status display
  getActivityDescription(): string // "Reading src/foo.ts"

  // Limits
  maxResultSizeChars?: number     // triggers disk persistence if exceeded
}

Built-in Tools (43 total)

This section helps you orient which tools are for reading, writing, searching, spawning, or protocol bridging.

ExecutionFile I/OSearchAgentsProtocolInfra
BashExecution

Shell commands with AST security analysis, sandbox, ML classifier

FileEditModification

String find/replace with fuzzy matching and unified diff

FileWriteModification

Full content atomic file replacement

FileReadRead

Read files with PDF, notebook, image handling

GrepSearch

Ripgrep-based content search with permission filtering

GlobSearch

Fast file pattern matching, mod-time sorted

AgentSpawning

Isolated sub-agents with zero-cost cache sharing

SkillInvocation

User-defined prompt templates from .md files

MCPProxy

Wraps external tools via Model Context Protocol

WebSearchSearch

Web search integration

WebFetchRead

Fetch web page content

NotebookEditModification

Jupyter notebook cell editing

WorktreeIsolation

Git worktree creation and cleanup

SendMessageComms

Inter-agent messaging

Task*Management

Create, get, update, stop tracked subtasks

ToolSearchDiscovery

Deferred tool loading for large tool sets

LSPIntegration

Language Server Protocol queries

PowerShellExecution

Windows PowerShell execution

SleepUtility

Async wait/delay

Exit*Cleanup

Exit worktree/plan with safety checks

BashTool Deep Dive

Read this if you want to understand why shell execution in Claude Code is so heavily guarded.

The BashTool is the largest and most complex tool (~300KB across 5 files). It has multi-layered security to prevent dangerous command execution.

1
AST-based Parsing (tree-sitter)

Detects dangerous patterns: redirections, pipes, subshells

2
ML Classifier (opt-in)

AI evaluates command safety with confidence scoring, can auto-approve safe patterns

3
Permission Rule Matching

Exact, prefix (*), and wildcard (*test*) patterns

4
Semantic Analysis

Detects dangerous redirections to system files, blocks shell config modifications

5
Read-only Constraints

Blocks write commands in non-privileged sessions, prevents privilege escalation

typescript
// Execution flow:
Input → validateInput()
     → checkPermissions() [bashToolHasPermission]
     → shouldUseSandbox()?
     → exec() via SandboxManager
     → Output parsing + image detection
     → Result persistence if >100K chars

// Key files:
bashPermissions.ts  — 98KB — Permission rules + classifier
bashSecurity.ts     — 102KB — Dangerous pattern detection
readOnlyValidation.ts — 68KB — Privilege escalation prevention
sedValidation.ts    — 21KB — Sed command validation
shouldUseSandbox.ts — Sandbox decision logic

FileEditTool

This section explains why edits are more than a simple string replace.

typescript
// Input schema:
{
  file_path: string    // absolute path
  old_string: string   // text to find
  new_string: string   // replacement text
  replace_all?: boolean // global replace
}

// Key features:
1. findActualString() — fuzzy matching
   → Quote-style preservation
   → Whitespace/indentation variations
   → Multiple match handling via exact-position lookup

2. Validation
   → File must exist or be newly created
   → File must have been read first (tracked via readFileState)
   → File timestamp must not have changed since read
   → Blocks team memory files with secrets

3. Side effects
   → Notifies LSP servers (triggers diagnostics)
   → Notifies VSCode SDK MCP
   → Updates file modification tracking
   → Discovers conditional skills by path pattern
   → Fires fileHistoryTrackEdit for versioning

Tool Orchestration Strategy

Use this section to understand how many tool calls can happen in one turn without corrupting shared state.

Read-only (parallel, up to 10)

Grep
Glob
FileRead

Write (serial)

FileEdit
FileWrite
Bash

Tools declare isConcurrencySafe() to enable parallel execution. The orchestrator partitions tool calls into batches.

typescript
// toolOrchestration.ts — runTools() generator

1. Partition by concurrency safety:
   → Group consecutive read-only tools (Grep, Glob, Read)
   → Isolate write tools (Edit, Write, Bash)

2. Read-only batch: parallel execution
   → Up to 10 concurrent tool calls
   → No state interference between reads

3. Write batch: serial execution
   → One tool at a time
   → Context modifiers applied between calls
   → File state cache updated after each

4. Result collection:
   → Each tool returns ToolResult<Output>
   → data, newMessages, contextModifier, mcpMeta
   → Wrapped in tool_result block with tool_use_id pairing