Skip to content

Tool System

This page answers “what can Claude Code do” — and more importantly — “why it does it that way.” 43 tool entities form the system’s capability surface, organized with a unified governance layer, fail-safe defaults, and OS-level sandboxing.

Docs + Visualization side by side: This document explains why things are designed this way. The Tools visualization lets you click any tool card to verify source paths, parameters, and mechanics.

Overview

MetricValue
Total tools43
Groups6
Governance files216 (permissions, hooks, sandbox)
Contract sourcesdk-tools.d.ts (116KB type definitions)

Tool System Overview

    flowchart TD
  subgraph Model
    M[LLM requests tool_use]
  end
  subgraph Filtering
    FF[Feature Flag] --> DR[Deny Rules] --> MC[MCP Merge]
  end
  subgraph Governance
    PM[PermissionMode] --> RL[Rule Matching] --> HK[toolPermission Hook] --> SB[Sandbox]
  end
  subgraph Execution
    SE[StreamingToolExecutor]
    RO[Read-only tools · parallel]
    RW[Write tools · serial]
    SE --> RO
    SE --> RW
  end
  M --> FF
  MC --> PM
  SB --> SE
  

Core Design: Tool-First Architecture

Claude Code adopts a Tool-First architecture — the model never executes operations directly; it calls standardized tools. This is a deliberate engineering decision with major consequences:

Traditional HardcodedTool-First
Capabilities tightly coupled to AI logicEach capability independently encapsulated
Adding features = modifying core codeAdding features = registering a new tool
Coarse-grained access controlPer-tool permissions, sandboxing, concurrency
Hard to test in isolationEach tool independently unit-testable
Model sees a fixed function setModel sees a dynamically computed tool set

Source evidence: src/Tool.ts (tool base class) and src/services/tools/toolOrchestration.ts (orchestration layer).

Tool Groups

File Operations (8 tools, 32 files)

ToolCapabilityKey Design
FileReadToolRead file content with line rangesmaxResultSizeChars = Infinity — no truncation
FileWriteToolWrite files, create or overwriteFull replacement, no merge
FileEditToolold_string/new_string surgical editingFails if old_string is not unique
NotebookEditToolJupyter notebook cell editingDeferred loading
GlobToolFile pattern matchingreadonly + parallel-safe
GrepToolripgrep-powered content searchreadonly + parallel-safe
ToolSearchToolDiscover available toolsOnly entry point for deferred tools
BriefToolSwitch to brief output modeRender-stage tool

Execution & Shell (4 tools, 35 files)

ToolCapabilitySecurity
BashToolShell command executionOnly sandboxed tool — macOS sandbox-exec / Linux bubblewrap
PowerShellToolWindows PowerShellSame security model
REPLToolInteractive REPL sessionDeferred
SleepToolWait for durationreadonly

BashTool: Four-Layer Security Deep Dive

BashTool has the most complex security design because it directly faces command injection risks:

  • Layer 1 — Command Parsing: Extracts actual program names and arguments before execution
  • Layer 2 — Pattern Matching: Built-in dangerous pattern library (rm -rf, fork bombs, Zsh bypass tricks)
  • Layer 3 — Semantic Analysis: Understands intent (force push = destructive, echo $API_KEY = data leak)
  • Layer 4 — OS-Level Sandbox: macOS sandbox-exec / Linux bubblewrap + seccomp, filesystem and network allow-lists

Agents & Teams (5 tools, 36 files)

ToolCapabilityDesign
AgentToolSpawn sub-agents6 built-in agent types
SendMessageToolInter-agent messagingUDS IPC
TeamCreateToolCreate persistent teamsIsolated git worktree
TeamDeleteToolRemove teamsDestructive
SkillToolSkill installationSKILL.md from registry

Sub-Agent Type System

TypeToolsModelDesign Metaphor
ExploreRead-only (Read, Glob, Grep, Bash)Haiku (fastest)Scout — light, fast
PlanRead-onlyPrimary modelStrategist — observe only
VerifyRead-onlyPrimary modelAuditor — independent validation
GeneralPurposeAllPrimary modelFull operator

Key isolation: each sub-agent gets its own ID, AbortController, and tool whitelist. Explore Agent sets omitClaudeMd: true to save tokens. Permission requests bubble up to the parent via permissionMode: 'bubble'.

Planning & Workflows (13 tools, 44 files)

Plan mode, task management, cron scheduling, and worktree isolation.

External Systems (10 tools, 33 files)

Web, MCP, LSP, and user interaction tools for bridging to external systems.

Infrastructure (3 modules, 4 files)

Shared utilities, testing framework, and helper functions for the tool system.

Unified Tool Contract

All tools register through a unified type defined in Tool.ts:

PropertyDefaultDesign Intent
isReadOnly()falseAssumes writes — fail-safe
isConcurrencySafe()falseAssumes not parallel-safe — avoids races
interruptBehavior()blockOn new user message: cancel or wait
maxResultSizeChars—Oversize results persisted to disk

Key Philosophy: All safety-related defaults are false (most restrictive). If a tool developer forgets to set a property, the system runs in the most conservative mode. Better slow than sorry.

Three-Layer Tool Filtering

Tools are not all exposed to the model. Each query loop iteration filters the tool list:

  1. Feature Flag: isEnabled() === false → silently removed
  2. Permission Deny rules: Explicitly disabled tools removed before reaching the model
  3. MCP Merge: External MCP server tools dynamically merged

The filtered list is serialized as the tools parameter in the API request.

Lessons for Agent Builders

PrincipleClaude Code PracticeTakeaway
Default strictestAll safety properties default falseStart conservative, relax incrementally
Composable toolsModel freely combines toolsDesign small-grained tools, let AI orchestrate
Dynamic tool setTool list computed per queryAdjust capabilities by context and permissions
Agent specializationExplore uses fast model, Plan is read-onlyMatch model + permissions to task type
OS-level sandboxShell execution sandboxedHigh-risk operations need isolation