Chapter 8

Tools

Complete reference for built-in tool interfaces. Use these when configuring tool permissions or building custom integrations.

Bash

Executes bash commands in a persistent shell session with optional timeout and background execution.

PropertyTypeRequiredDescription
commandstringYesThe command to execute
timeoutnumberNoOptional timeout in milliseconds (max 600000)
descriptionstringNoClear, concise description of what this command does in 5-10 words
run_in_backgroundbooleanNoSet to true to run this command in the background

BashOutput

Retrieves output from a running or completed background bash shell.

PropertyTypeRequiredDescription
bash_idstringYesThe ID of the background shell to retrieve output from
filterstringNoOptional regex to filter output lines

Edit

Performs exact string replacements in files.

PropertyTypeRequiredDescription
file_pathstringYesThe absolute path to the file to modify
old_stringstringYesThe text to replace
new_stringstringYesThe text to replace it with (must be different from old_string)
replace_allbooleanNoReplace all occurrences of old_string (default false)

Read

Reads files from the local filesystem, including text, images, PDFs, and Jupyter notebooks.

PropertyTypeRequiredDescription
file_pathstringYesThe absolute path to the file to read
offsetnumberNoThe line number to start reading from
limitnumberNoThe number of lines to read

Write

Writes a file to the local filesystem, overwriting if it exists.

PropertyTypeRequiredDescription
file_pathstringYesThe absolute path to the file to write
contentstringYesThe content to write to the file

Glob

Fast file pattern matching that works with any codebase size.

PropertyTypeRequiredDescription
patternstringYesThe glob pattern to match files against
pathstringNoThe directory to search in (defaults to cwd)

Grep

Powerful search tool built on ripgrep with regex support.

PropertyTypeRequiredDescription
patternstringYesThe regular expression pattern to search for
pathstringNoFile or directory to search in (defaults to cwd)
globstringNoGlob pattern to filter files (e.g. "*.js")
typestringNoFile type to search (e.g. "js", "py", "rust")
output_mode'content' | 'files_with_matches' | 'count'NoOutput mode: "content", "files_with_matches", or "count"
-ibooleanNoCase insensitive search
-nbooleanNoShow line numbers (for content mode)
-BnumberNoLines to show before each match
-AnumberNoLines to show after each match
-CnumberNoLines to show before and after each match
head_limitnumberNoLimit output to first N lines/entries
multilinebooleanNoEnable multiline mode

KillBash

Kills a running background bash shell by its ID.

PropertyTypeRequiredDescription
shell_idstringYesThe ID of the background shell to kill

NotebookEdit

Edits cells in Jupyter notebook files.

PropertyTypeRequiredDescription
notebook_pathstringYesThe absolute path to the Jupyter notebook file
new_sourcestringYesThe new source for the cell
cell_idstringNoThe ID of the cell to edit
cell_type'code' | 'markdown'NoThe type of the cell (code or markdown)
edit_mode'replace' | 'insert' | 'delete'NoThe type of edit (replace, insert, delete)

WebFetch

Fetches content from a URL and processes it with an AI model.

PropertyTypeRequiredDescription
urlstringYesThe URL to fetch content from
promptstringYesThe prompt to run on the fetched content

WebSearch

Searches the web and returns formatted results.

PropertyTypeRequiredDescription
querystringYesThe search query to use
allowed_domainsstring[]NoOnly include results from these domains
blocked_domainsstring[]NoNever include results from these domains

TodoWrite

Creates and manages a structured task list for tracking progress.

PropertyTypeRequiredDescription
todosTodoItem[]YesThe updated todo list

TodoItem structure:

PropertyTypeDescription
contentstringThe task description
status'pending' | 'in_progress' | 'completed'The task status
activeFormstringActive form of the task description

ExitPlanMode

Exits planning mode and prompts the user to approve the plan.

PropertyTypeRequiredDescription
planstringYesThe plan to run by the user for approval

ListMcpResources

Lists available MCP resources from connected servers.

PropertyTypeRequiredDescription
serverstringNoOptional server name to filter resources by

ReadMcpResource

Reads a specific MCP resource from a server.

PropertyTypeRequiredDescription
serverstringYesThe MCP server name
uristringYesThe resource URI to read

Tool Output Types

Documentation of output schemas for all built-in Claude Code tools. These types represent the actual response data returned by each tool.

ToolOutputUnion Type

This is a documentation-only type for clarity. It represents the union of all tool output types.

type ToolOutput =
  | TaskOutput
  | AskUserQuestionOutput
  | BashOutput
  | BashOutputToolOutput
  | EditOutput
  | ReadOutput
  | WriteOutput
  | GlobOutput
  | GrepOutput
  | KillBashOutput
  | NotebookEditOutput
  | WebFetchOutput
  | WebSearchOutput
  | TodoWriteOutput
  | ExitPlanModeOutput
  | ListMcpResourcesOutput
  | ReadMcpResourceOutput;

TaskOutput

Returns the final result from the subagent after completing the delegated task.

PropertyTypeDescription
resultstringFinal result message from the subagent
usageUsageStats?Token usage statistics (input_tokens, output_tokens, cache tokens)
total_cost_usdnumber?Total cost in USD
duration_msnumber?Execution duration in milliseconds

AskUserQuestionOutput

Returns the questions asked and the user's answers.

PropertyTypeDescription
questionsQuestion[]The questions that were asked
answersRecord<string, string>Maps question text to answer string. Multi-select answers are comma-separated.

BashOutput

Returns command output with exit status. Background commands return immediately with a shellId.

PropertyTypeDescription
outputstringCombined stdout and stderr output
exitCodenumberExit code of the command
killedboolean?Whether the command was killed due to timeout
shellIdstring?Shell ID for background processes

BashOutputToolOutput

Returns incremental output from background shells.

PropertyTypeDescription
outputstringNew output since last check
status'running' | 'completed' | 'failed'Current shell status
exitCodenumber?Exit code (when completed)

EditOutput

Returns confirmation of successful edits with replacement count.

PropertyTypeDescription
messagestringConfirmation message
replacementsnumberNumber of replacements made
file_pathstringFile path that was edited

ReadOutput

Returns file contents in format appropriate to file type.

Union type based on file type:

type ReadOutput =
  | TextFileOutput
  | ImageFileOutput
  | PDFFileOutput
  | NotebookFileOutput;

TextFileOutput

PropertyTypeDescription
contentstringFile contents with line numbers
total_linesnumberTotal number of lines in file
lines_returnednumberLines actually returned

ImageFileOutput

PropertyTypeDescription
imagestringBase64 encoded image data
mime_typestringImage MIME type
file_sizenumberFile size in bytes

PDFFileOutput

PropertyTypeDescription
pagesPageContent[]Array of page contents (page_number, text, images)
total_pagesnumberTotal number of pages

NotebookFileOutput

PropertyTypeDescription
cellsCell[]Jupyter notebook cells (cell_type, source, outputs, execution_count)
metadataRecord?Notebook metadata

WriteOutput

Returns confirmation after successfully writing the file.

PropertyTypeDescription
messagestringSuccess message
bytes_writtennumberNumber of bytes written
file_pathstringFile path that was written

GlobOutput

Returns file paths matching the glob pattern, sorted by modification time.

PropertyTypeDescription
matchesstring[]Array of matching file paths
countnumberNumber of matches found
search_pathstringSearch directory used

GrepOutput

Returns search results in the format specified by output_mode.

Union type based on output_mode:

type GrepOutput =
  | GrepContentOutput
  | GrepFilesOutput
  | GrepCountOutput;

GrepContentOutput (output_mode: "content")

PropertyTypeDescription
matchesMatch[]Matching lines with context (file, line_number, line, before/after_context)
total_matchesnumberTotal number of matches

GrepFilesOutput (output_mode: "files_with_matches")

PropertyTypeDescription
filesstring[]Files containing matches
countnumberNumber of files with matches

GrepCountOutput (output_mode: "count")

PropertyTypeDescription
countsFileCount[]Match counts per file (file, count)
totalnumberTotal matches across all files

KillBashOutput

Returns confirmation after terminating the background shell.

PropertyTypeDescription
messagestringSuccess message
shell_idstringID of the killed shell

NotebookEditOutput

Returns confirmation after modifying the Jupyter notebook.

PropertyTypeDescription
messagestringSuccess message
edit_type'replaced' | 'inserted' | 'deleted'Type of edit performed
cell_idstring?Cell ID that was affected
total_cellsnumberTotal cells in notebook after edit

WebFetchOutput

Returns the AI's analysis of the fetched web content.

PropertyTypeDescription
responsestringAI model's response to the prompt
urlstringURL that was fetched
final_urlstring?Final URL after redirects
status_codenumber?HTTP status code

WebSearchOutput

Returns web search results with titles, URLs, and snippets.

PropertyTypeDescription
resultsSearchResult[]Search results (title, url, snippet, metadata)
total_resultsnumberTotal number of results
querystringThe query that was searched