Initial commit to new repository
This commit is contained in:
225
docs/claude-code-docs-main/en/reference/tools/agent.md
Normal file
225
docs/claude-code-docs-main/en/reference/tools/agent.md
Normal file
@@ -0,0 +1,225 @@
|
||||
> ## Documentation Index
|
||||
> Fetch the complete documentation index at: https://vineetagarwal-code-claude-code.mintlify.app/llms.txt
|
||||
> Use this file to discover all available pages before exploring further.
|
||||
|
||||
# Agent & Task Tools
|
||||
|
||||
> Spawn sub-agents for complex tasks and track work with a structured todo list.
|
||||
|
||||
Claude Code has two meta-tools for managing complex, multi-step work: `Task` (also called the Agent tool) for launching autonomous sub-agents, and `TodoWrite` for maintaining a structured task list within a session.
|
||||
|
||||
***
|
||||
|
||||
## Task (Agent tool)
|
||||
|
||||
Launches a specialized sub-agent to handle a complex task autonomously. The sub-agent runs independently, uses its own set of tools, and returns a single result message when it finishes.
|
||||
|
||||
### Parameters
|
||||
|
||||
<ParamField body="prompt" type="string" required>
|
||||
The full task description for the agent. Since sub-agents start with no knowledge of the parent conversation, the prompt must be self-contained — include relevant file paths, line numbers, context, and any constraints. Terse command-style prompts produce shallow results.
|
||||
</ParamField>
|
||||
|
||||
<ParamField body="description" type="string" required>
|
||||
A short (3–5 word) label describing what the agent will do. Shown in the UI.
|
||||
</ParamField>
|
||||
|
||||
<ParamField body="subagent_type" type="string">
|
||||
The type of specialized agent to use (e.g., `"code-reviewer"`, `"test-runner"`). When omitted, the general-purpose agent is used. Available agent types are listed in the system prompt.
|
||||
</ParamField>
|
||||
|
||||
<ParamField body="model" type="string">
|
||||
Optional model override: `"sonnet"`, `"opus"`, or `"haiku"`. Takes precedence over the agent definition's configured model. Omit to inherit from the agent definition or parent.
|
||||
</ParamField>
|
||||
|
||||
<ParamField body="run_in_background" type="boolean">
|
||||
When `true`, the agent runs in the background. Claude is notified when it completes and should not poll or sleep while waiting. Use background mode when you have genuinely independent work to continue in the meantime.
|
||||
</ParamField>
|
||||
|
||||
<ParamField body="isolation" type="string">
|
||||
Isolation mode for the agent's filesystem context:
|
||||
|
||||
* `"worktree"` — agent runs in a temporary git worktree (isolated copy of the repo). The worktree is cleaned up automatically if the agent makes no changes; otherwise the path and branch are returned.
|
||||
</ParamField>
|
||||
|
||||
<ParamField body="cwd" type="string">
|
||||
Absolute path to use as the working directory for all filesystem and shell operations inside the agent. Mutually exclusive with `isolation: "worktree"`.
|
||||
</ParamField>
|
||||
|
||||
<ParamField body="name" type="string">
|
||||
A name for the spawned agent. Makes it addressable via `SendMessage({ to: name })` while it is running.
|
||||
</ParamField>
|
||||
|
||||
### How sub-agents work
|
||||
|
||||
Each agent invocation starts with zero conversation context. The agent:
|
||||
|
||||
1. Receives its own system prompt and the `prompt` you provide
|
||||
2. Has access to a tool set defined by its `subagent_type` (or all tools for the general-purpose agent)
|
||||
3. Runs autonomously until the task is complete
|
||||
4. Returns a single result message back to the parent
|
||||
|
||||
The result is **not** shown directly to the user — Claude summarizes it in a follow-up message.
|
||||
|
||||
<Warning>
|
||||
Never write "based on your findings, fix the bug" or similar delegation phrases. Prompts that push synthesis back onto the agent produce generic work. Include concrete file paths, line numbers, and specific instructions in the prompt.
|
||||
</Warning>
|
||||
|
||||
### When to use the Task tool
|
||||
|
||||
<Tabs>
|
||||
<Tab title="Good use cases">
|
||||
* Open-ended research that requires multiple rounds of searching and reading
|
||||
* Running a test suite and analyzing failures after code changes
|
||||
* Independent code review by a fresh agent with no prior context bias
|
||||
* Long-running operations that can proceed while Claude handles other requests
|
||||
* Tasks that would generate noisy intermediate output you don't need in the main context
|
||||
</Tab>
|
||||
|
||||
<Tab title="When NOT to use it">
|
||||
* Reading a specific file — use the `Read` tool directly
|
||||
* Searching for a class definition — use `Grep` directly
|
||||
* Searching within 2–3 known files — use `Read` directly
|
||||
* Simple tasks unrelated to the available agent types
|
||||
</Tab>
|
||||
</Tabs>
|
||||
|
||||
### Parallel agents
|
||||
|
||||
When tasks are independent, Claude launches multiple agents in a single message:
|
||||
|
||||
```
|
||||
Task({ description: "Run tests", prompt: "Run the full test suite..." })
|
||||
Task({ description: "Check types", prompt: "Run tsc --noEmit and report errors..." })
|
||||
```
|
||||
|
||||
Both agents run concurrently. When both complete, Claude synthesizes the results.
|
||||
|
||||
### Resuming agents
|
||||
|
||||
To send a follow-up message to a running or completed agent, use `SendMessage` with the agent's `name` as the `to` field. The agent resumes with its full context preserved.
|
||||
|
||||
### Writing effective prompts
|
||||
|
||||
<Accordion title="Brief like a colleague joining mid-task">
|
||||
The agent knows nothing about your session. Treat the prompt like a complete briefing for a smart colleague who just arrived:
|
||||
|
||||
* What you're trying to accomplish and why
|
||||
* What you've already tried or ruled out
|
||||
* The specific files, functions, or systems involved
|
||||
* What form the result should take ("report in under 200 words", "make the fix directly", etc.)
|
||||
</Accordion>
|
||||
|
||||
<Accordion title="Lookups vs. investigations">
|
||||
* **Lookups**: hand over the exact command or query. The agent should not need to figure out what to run.
|
||||
* **Investigations**: hand over the question, not prescribed steps. Over-specifying steps for open-ended problems causes the agent to waste effort on a wrong path.
|
||||
</Accordion>
|
||||
|
||||
***
|
||||
|
||||
## TodoWrite
|
||||
|
||||
Maintains a structured task list for the current session. Claude uses this tool proactively to track progress, organize multi-step work, and provide visibility into what it is doing.
|
||||
|
||||
### Parameters
|
||||
|
||||
<ParamField body="todos" type="TodoItem[]" required>
|
||||
The complete, updated todo list. Each call **replaces** the entire list — there is no incremental add or remove.
|
||||
</ParamField>
|
||||
|
||||
### TodoItem schema
|
||||
|
||||
Each item in the `todos` array has the following fields:
|
||||
|
||||
<ParamField body="content" type="string" required>
|
||||
The task description in imperative form — what needs to be done. Example: `"Run tests"`, `"Fix authentication bug"`.
|
||||
</ParamField>
|
||||
|
||||
<ParamField body="activeForm" type="string" required>
|
||||
The present-continuous form of the task description, shown while the task is in progress. Example: `"Running tests"`, `"Fixing authentication bug"`.
|
||||
</ParamField>
|
||||
|
||||
<ParamField body="status" type="string" required>
|
||||
The current state of the task. One of:
|
||||
|
||||
| Value | Meaning |
|
||||
| ------------- | ------------------------- |
|
||||
| `pending` | Not yet started |
|
||||
| `in_progress` | Currently being worked on |
|
||||
| `completed` | Finished successfully |
|
||||
|
||||
Exactly one task should be `in_progress` at any time.
|
||||
</ParamField>
|
||||
|
||||
### How Claude uses TodoWrite
|
||||
|
||||
Claude calls `TodoWrite` proactively when:
|
||||
|
||||
* A task requires **3 or more distinct steps**
|
||||
* Work is non-trivial and benefits from structured tracking
|
||||
* The user provides a list of multiple things to do
|
||||
* New sub-tasks are discovered mid-implementation
|
||||
|
||||
Claude does **not** use `TodoWrite` for:
|
||||
|
||||
* Single-step tasks
|
||||
* Trivial operations (e.g., adding a comment, running one command)
|
||||
* Purely informational or conversational responses
|
||||
|
||||
### Task lifecycle
|
||||
|
||||
<Accordion title="Starting work">
|
||||
Claude marks a task `in_progress` **before** beginning, not after. This ensures the UI reflects what is actively happening.
|
||||
|
||||
```json theme={null}
|
||||
{ "content": "Add dark mode toggle", "activeForm": "Adding dark mode toggle", "status": "in_progress" }
|
||||
```
|
||||
</Accordion>
|
||||
|
||||
<Accordion title="Completing work">
|
||||
Claude marks a task `completed` immediately when it finishes — it does not batch completions. A task is only marked complete when:
|
||||
|
||||
* Implementation is fully done
|
||||
* No tests are failing
|
||||
* No unresolved errors remain
|
||||
</Accordion>
|
||||
|
||||
<Accordion title="Handling blockers">
|
||||
If a task cannot be completed (missing file, failing test, unresolved error), Claude keeps it `in_progress` and creates a new `pending` task describing what needs to be resolved first.
|
||||
</Accordion>
|
||||
|
||||
<Accordion title="Clearing the list">
|
||||
When all tasks are marked `completed`, Claude clears the list automatically. An empty list signals that all requested work is done.
|
||||
</Accordion>
|
||||
|
||||
### Example list
|
||||
|
||||
```json theme={null}
|
||||
{
|
||||
"todos": [
|
||||
{
|
||||
"content": "Add dark mode CSS variables",
|
||||
"activeForm": "Adding dark mode CSS variables",
|
||||
"status": "completed"
|
||||
},
|
||||
{
|
||||
"content": "Implement theme context provider",
|
||||
"activeForm": "Implementing theme context provider",
|
||||
"status": "in_progress"
|
||||
},
|
||||
{
|
||||
"content": "Update existing components to use theme",
|
||||
"activeForm": "Updating existing components to use theme",
|
||||
"status": "pending"
|
||||
},
|
||||
{
|
||||
"content": "Run tests and build",
|
||||
"activeForm": "Running tests and build",
|
||||
"status": "pending"
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
Built with [Mintlify](https://mintlify.com).
|
||||
170
docs/claude-code-docs-main/en/reference/tools/bash.md
Normal file
170
docs/claude-code-docs-main/en/reference/tools/bash.md
Normal file
@@ -0,0 +1,170 @@
|
||||
> ## Documentation Index
|
||||
> Fetch the complete documentation index at: https://vineetagarwal-code-claude-code.mintlify.app/llms.txt
|
||||
> Use this file to discover all available pages before exploring further.
|
||||
|
||||
# Bash
|
||||
|
||||
> Execute shell commands in a persistent bash session.
|
||||
|
||||
The `Bash` tool runs shell commands and returns their output. Commands execute in a persistent bash session — the working directory is preserved between calls, though the shell state (variables, aliases, functions) is re-initialized from the user's profile on each invocation.
|
||||
|
||||
<Note>
|
||||
Claude prefers dedicated tools (`Read`, `Edit`, `Glob`, `Grep`) over Bash equivalents for file operations. Bash is reserved for tasks where no purpose-built tool applies.
|
||||
</Note>
|
||||
|
||||
## Parameters
|
||||
|
||||
<ParamField body="command" type="string" required>
|
||||
The shell command to execute. Supports all standard bash syntax including pipes, redirections, and compound operators (`&&`, `||`, `;`).
|
||||
</ParamField>
|
||||
|
||||
<ParamField body="timeout" type="number">
|
||||
Maximum execution time in milliseconds. Defaults to **120,000 ms (2 minutes)**. Maximum allowed value is **600,000 ms (10 minutes)**.
|
||||
|
||||
Both values can be overridden at runtime via `BASH_DEFAULT_TIMEOUT_MS` and `BASH_MAX_TIMEOUT_MS` environment variables.
|
||||
</ParamField>
|
||||
|
||||
<ParamField body="description" type="string">
|
||||
A short human-readable description of what the command does. Shown in the UI when Claude explains its actions.
|
||||
</ParamField>
|
||||
|
||||
<ParamField body="run_in_background" type="boolean">
|
||||
When `true`, the command runs in the background. Claude is notified when it completes and does not need to poll for results. Do not append `&` to the command when using this parameter — background execution is handled internally.
|
||||
</ParamField>
|
||||
|
||||
## Session behavior
|
||||
|
||||
The bash session persists working directory across calls but does **not** persist:
|
||||
|
||||
* Shell variables set in previous commands
|
||||
* Aliases or functions
|
||||
* `cd` changes (Claude uses absolute paths instead)
|
||||
|
||||
Claude initializes each session from the user's shell profile (`bash` or `zsh`).
|
||||
|
||||
## Timeouts
|
||||
|
||||
| Setting | Default | Max |
|
||||
| --------------- | ------------------- | --- |
|
||||
| Default timeout | 120,000 ms (2 min) | — |
|
||||
| Maximum timeout | 600,000 ms (10 min) | — |
|
||||
|
||||
Pass a `timeout` value (in milliseconds) to override the default for a specific command.
|
||||
|
||||
## Permission model
|
||||
|
||||
Every Bash command passes through a permission check before execution. The outcome is one of:
|
||||
|
||||
* **Allow** — command matches an existing allow rule or is classified as read-only
|
||||
* **Ask** — command requires user approval before running
|
||||
* **Deny** — command matches an explicit deny rule and is blocked
|
||||
|
||||
### Allow rules
|
||||
|
||||
Rules are matched by exact command, prefix (`git commit:*`), or wildcard pattern. Safe wrapper commands (`timeout`, `time`, `nice`, `nohup`) and safe environment variable assignments (`NODE_ENV=prod`, `GOARCH=arm64`) are stripped before matching so prefix rules work correctly.
|
||||
|
||||
### Read-only auto-allow
|
||||
|
||||
Commands that only read state (e.g., `ls`, `cat`, `git log`, `grep`) are automatically allowed without a prompt.
|
||||
|
||||
### Security restrictions
|
||||
|
||||
Claude's security layer checks each command for patterns that commonly indicate injection or obfuscation attempts. Commands containing the following require explicit user approval:
|
||||
|
||||
* Command substitution: `` `...` ``, `$()`, `${}`
|
||||
* Process substitution: `<()`, `>()`
|
||||
* Input/output redirections (`<`, `>`) in suspicious contexts
|
||||
* Zsh-specific constructs: `zmodload`, `emulate -c`, `ztcp`, `zsocket`
|
||||
* ANSI-C quoting (`$'...'`) or locale quoting (`$"..."`)
|
||||
* IFS variable manipulation (`$IFS`)
|
||||
* Access to `/proc/*/environ`
|
||||
* Newlines or carriage returns in non-quoted positions
|
||||
|
||||
<Warning>
|
||||
Commands are split into subcommands before permission checking. A rule like `Bash(ls:*)` will **not** match `ls /tmp && rm -rf /` — the `rm -rf /` subcommand is checked separately.
|
||||
</Warning>
|
||||
|
||||
## Background execution
|
||||
|
||||
<Tabs>
|
||||
<Tab title="Foreground (default)">
|
||||
```json theme={null}
|
||||
{
|
||||
"command": "npm run build",
|
||||
"description": "Build the project"
|
||||
}
|
||||
```
|
||||
|
||||
Claude waits for the command to finish and receives its output immediately.
|
||||
</Tab>
|
||||
|
||||
<Tab title="Background">
|
||||
```json theme={null}
|
||||
{
|
||||
"command": "npm run dev",
|
||||
"description": "Start dev server",
|
||||
"run_in_background": true
|
||||
}
|
||||
```
|
||||
|
||||
The command starts and Claude continues without blocking. A notification arrives when the process finishes.
|
||||
</Tab>
|
||||
</Tabs>
|
||||
|
||||
## Examples
|
||||
|
||||
<Accordion title="Running tests">
|
||||
```bash theme={null}
|
||||
pytest tests/ -x --tb=short
|
||||
```
|
||||
|
||||
Run a test suite and stop on the first failure.
|
||||
</Accordion>
|
||||
|
||||
<Accordion title="Git operations">
|
||||
```bash theme={null}
|
||||
git status && git diff --staged
|
||||
```
|
||||
|
||||
Check working tree status and staged changes in a single compound command.
|
||||
|
||||
<Note>
|
||||
Claude follows a strict protocol for `git commit` and `git push` — it never amends pushed commits, never skips hooks with `--no-verify`, and never force-pushes to `main`/`master` without explicit user instruction.
|
||||
</Note>
|
||||
</Accordion>
|
||||
|
||||
<Accordion title="Installing dependencies">
|
||||
```bash theme={null}
|
||||
npm install
|
||||
```
|
||||
|
||||
Standard package installation. Claude stages related commands in parallel when they are independent.
|
||||
</Accordion>
|
||||
|
||||
<Accordion title="Long-running server with timeout override">
|
||||
```json theme={null}
|
||||
{
|
||||
"command": "cargo build --release",
|
||||
"timeout": 300000,
|
||||
"description": "Release build (up to 5 min)"
|
||||
}
|
||||
```
|
||||
|
||||
Override the 2-minute default for commands known to take longer.
|
||||
</Accordion>
|
||||
|
||||
## Tool preference
|
||||
|
||||
Claude uses Bash only when no purpose-built tool is available:
|
||||
|
||||
| Task | Preferred tool |
|
||||
| ----------------------------- | -------------- |
|
||||
| Find files by name | `Glob` |
|
||||
| Search file contents | `Grep` |
|
||||
| Read a file | `Read` |
|
||||
| Edit a file | `Edit` |
|
||||
| Write a new file | `Write` |
|
||||
| Shell commands, builds, tests | **Bash** |
|
||||
|
||||
|
||||
Built with [Mintlify](https://mintlify.com).
|
||||
157
docs/claude-code-docs-main/en/reference/tools/file-operations.md
Normal file
157
docs/claude-code-docs-main/en/reference/tools/file-operations.md
Normal file
@@ -0,0 +1,157 @@
|
||||
> ## Documentation Index
|
||||
> Fetch the complete documentation index at: https://vineetagarwal-code-claude-code.mintlify.app/llms.txt
|
||||
> Use this file to discover all available pages before exploring further.
|
||||
|
||||
# File Operations
|
||||
|
||||
> Read, edit, and write files on the local filesystem.
|
||||
|
||||
Claude Code has three dedicated tools for working with files: `Read` for reading content, `Edit` for precise in-place edits, and `Write` for creating or fully rewriting files.
|
||||
|
||||
<Tip>
|
||||
Prefer `Edit` over `Write` when modifying existing files — `Edit` sends only the changed fragment, saving context and reducing the chance of unintended overwrites.
|
||||
</Tip>
|
||||
|
||||
***
|
||||
|
||||
## Read
|
||||
|
||||
Reads a file from the local filesystem and returns its contents with line numbers.
|
||||
|
||||
### Parameters
|
||||
|
||||
<ParamField body="file_path" type="string" required>
|
||||
Absolute path to the file. Relative paths are not accepted.
|
||||
</ParamField>
|
||||
|
||||
<ParamField body="offset" type="number">
|
||||
Line number to start reading from (1-indexed). Use this with `limit` to read a specific section of a large file.
|
||||
</ParamField>
|
||||
|
||||
<ParamField body="limit" type="number">
|
||||
Maximum number of lines to return. Defaults to **2,000** lines. For files longer than this, call `Read` again with a higher `offset` to page through the content.
|
||||
</ParamField>
|
||||
|
||||
### Output format
|
||||
|
||||
Results use `cat -n` style formatting: each line is prefixed with its 1-indexed line number.
|
||||
|
||||
```
|
||||
1 import { z } from 'zod'
|
||||
2
|
||||
3 export const schema = z.object({
|
||||
4 name: z.string(),
|
||||
5 })
|
||||
```
|
||||
|
||||
Claude preserves exact indentation from this output when constructing `Edit` calls.
|
||||
|
||||
### Supported file types
|
||||
|
||||
| Type | Behavior |
|
||||
| ---------------------------- | ------------------------------------------------------------------------------------------------------------------------------ |
|
||||
| Text files | Returns raw text with line numbers |
|
||||
| Images (PNG, JPG, etc.) | Displayed visually — Claude is multimodal |
|
||||
| PDF files | Returned as document content. For PDFs over 10 pages, use the `pages` parameter (e.g., `"1-5"`). Maximum 20 pages per request. |
|
||||
| Jupyter notebooks (`.ipynb`) | All cells and outputs are returned, combining code, text, and visualizations |
|
||||
|
||||
<Note>
|
||||
`Read` cannot list directories. To inspect a directory's contents, use `ls` via the `Bash` tool.
|
||||
</Note>
|
||||
|
||||
### Caching
|
||||
|
||||
If a file has not changed since the last `Read` call in the same conversation, Claude receives a cached stub instead of re-reading the file. This avoids redundant reads on unchanged files.
|
||||
|
||||
***
|
||||
|
||||
## Edit
|
||||
|
||||
Performs exact string replacement within a file.
|
||||
|
||||
### Parameters
|
||||
|
||||
<ParamField body="file_path" type="string" required>
|
||||
Absolute path to the file to modify.
|
||||
</ParamField>
|
||||
|
||||
<ParamField body="old_string" type="string" required>
|
||||
The exact string to find and replace. Must match the file content character-for-character, including whitespace and indentation.
|
||||
</ParamField>
|
||||
|
||||
<ParamField body="new_string" type="string" required>
|
||||
The replacement string. Use an empty string to delete `old_string`.
|
||||
</ParamField>
|
||||
|
||||
<ParamField body="replace_all" type="boolean">
|
||||
When `true`, replaces every occurrence of `old_string` in the file instead of only the first. Useful for renaming variables or symbols that appear multiple times.
|
||||
</ParamField>
|
||||
|
||||
### How Edit works
|
||||
|
||||
`Edit` finds the literal text in `old_string` inside the file and substitutes it with `new_string`. No regex interpretation occurs — the match is a plain string comparison.
|
||||
|
||||
<Warning>
|
||||
The tool **fails** if `old_string` appears more than once in the file and `replace_all` is not set. Provide enough surrounding context in `old_string` to make it unique, or set `replace_all: true` to update all occurrences.
|
||||
</Warning>
|
||||
|
||||
### Pre-read requirement
|
||||
|
||||
Claude must call `Read` on a file at least once in the conversation before calling `Edit` on it. The tool enforces this to prevent edits based on stale or assumed content.
|
||||
|
||||
### Indentation matching
|
||||
|
||||
When Claude derives `old_string` from `Read` output, it uses the content that appears **after** the line-number prefix. For example, given:
|
||||
|
||||
```
|
||||
12 const x = 1
|
||||
```
|
||||
|
||||
The `old_string` is ` const x = 1` (six leading spaces), not ` 12 const x = 1`.
|
||||
|
||||
***
|
||||
|
||||
## Write
|
||||
|
||||
Creates a new file or fully overwrites an existing one.
|
||||
|
||||
### Parameters
|
||||
|
||||
<ParamField body="file_path" type="string" required>
|
||||
Absolute path to the file to create or overwrite.
|
||||
</ParamField>
|
||||
|
||||
<ParamField body="content" type="string" required>
|
||||
The complete content to write to the file. If the file already exists, it is replaced entirely.
|
||||
</ParamField>
|
||||
|
||||
### When to use Write vs Edit
|
||||
|
||||
<Tabs>
|
||||
<Tab title="Use Edit">
|
||||
* Modifying one or more sections of an existing file
|
||||
* Renaming a variable or symbol across the file
|
||||
* Adding or removing a block of code
|
||||
|
||||
Edit is preferred because it transmits only the changed fragment.
|
||||
</Tab>
|
||||
|
||||
<Tab title="Use Write">
|
||||
* Creating a new file from scratch
|
||||
* Completely rewriting a file (e.g., regenerating a config from new requirements)
|
||||
* When the new content is entirely different from the original
|
||||
|
||||
Write replaces the entire file in one call.
|
||||
</Tab>
|
||||
</Tabs>
|
||||
|
||||
### Pre-read requirement
|
||||
|
||||
When overwriting an existing file, Claude must call `Read` first. Write enforces this to prevent unintentional data loss.
|
||||
|
||||
<Warning>
|
||||
Claude does not proactively create documentation files (`*.md`, `README.*`) unless explicitly instructed. Write follows the same principle.
|
||||
</Warning>
|
||||
|
||||
|
||||
Built with [Mintlify](https://mintlify.com).
|
||||
187
docs/claude-code-docs-main/en/reference/tools/search.md
Normal file
187
docs/claude-code-docs-main/en/reference/tools/search.md
Normal file
@@ -0,0 +1,187 @@
|
||||
> ## Documentation Index
|
||||
> Fetch the complete documentation index at: https://vineetagarwal-code-claude-code.mintlify.app/llms.txt
|
||||
> Use this file to discover all available pages before exploring further.
|
||||
|
||||
# Search
|
||||
|
||||
> Find files by name pattern and search file contents with regular expressions.
|
||||
|
||||
Claude Code has two dedicated search tools: `Glob` for finding files by name and `Grep` for searching file contents. Both are preferred over running `find` or `grep` as Bash commands — they have correct permission integration, return results sorted by modification time, and produce structured output Claude can act on directly.
|
||||
|
||||
***
|
||||
|
||||
## Glob
|
||||
|
||||
Finds files whose paths match a glob pattern. Results are sorted by modification time (most recently modified first).
|
||||
|
||||
### Parameters
|
||||
|
||||
<ParamField body="pattern" type="string" required>
|
||||
A glob pattern to match file paths against. Supports `*` (any characters within a path segment), `**` (any number of path segments), and `?` (single character).
|
||||
</ParamField>
|
||||
|
||||
<ParamField body="path" type="string">
|
||||
The directory to search in. Defaults to the current working directory. Must be an existing directory path — omit the parameter entirely to use the default; do not pass `null` or `"undefined"`.
|
||||
</ParamField>
|
||||
|
||||
### Output
|
||||
|
||||
Returns a list of matching file paths, relative to the working directory, sorted by modification time. Results are capped at **100 files**. If the result is truncated, consider narrowing the pattern or specifying a more specific `path`.
|
||||
|
||||
### Pattern examples
|
||||
|
||||
| Pattern | Matches |
|
||||
| ---------------------------- | ----------------------------------------------- |
|
||||
| `**/*.ts` | All TypeScript files anywhere in the tree |
|
||||
| `src/**/*.tsx` | All TSX files under `src/` |
|
||||
| `*.json` | JSON files in the current directory only |
|
||||
| `**/{package,tsconfig}.json` | `package.json` and `tsconfig.json` at any depth |
|
||||
| `tools/*/prompt.ts` | `prompt.ts` one level inside `tools/` |
|
||||
|
||||
<Tip>
|
||||
Use `Glob` when you know the filename or extension you're looking for. For open-ended exploration that requires multiple rounds of searching, use the `Task` (Agent) tool instead.
|
||||
</Tip>
|
||||
|
||||
***
|
||||
|
||||
## Grep
|
||||
|
||||
Searches file contents using regular expressions, powered by ripgrep. Returns matching file paths, line numbers, and (optionally) matching lines.
|
||||
|
||||
### Parameters
|
||||
|
||||
<ParamField body="pattern" type="string" required>
|
||||
A regular expression to search for in file contents. Supports full regex syntax: character classes, quantifiers, lookaheads, alternation, etc.
|
||||
|
||||
Ripgrep syntax differs from POSIX `grep` in one notable way: literal braces must be escaped. Use `interface\{\}` to find `interface{}` in Go code.
|
||||
</ParamField>
|
||||
|
||||
<ParamField body="path" type="string">
|
||||
File or directory to search in. Defaults to the current working directory. Can be a single file path to restrict the search.
|
||||
</ParamField>
|
||||
|
||||
<ParamField body="glob" type="string">
|
||||
Glob pattern to filter which files are searched (e.g., `"*.js"`, `"*.{ts,tsx}"`). Maps to `rg --glob`.
|
||||
</ParamField>
|
||||
|
||||
<ParamField body="type" type="string">
|
||||
Ripgrep file type to restrict the search (e.g., `"js"`, `"py"`, `"rust"`, `"go"`, `"java"`). More efficient than `glob` for standard file type filtering. Maps to `rg --type`.
|
||||
</ParamField>
|
||||
|
||||
<ParamField body="output_mode" type="string">
|
||||
Controls what is returned. Options:
|
||||
|
||||
* `"files_with_matches"` *(default)* — returns file paths only
|
||||
* `"content"` — returns matching lines with context support
|
||||
* `"count"` — returns match counts per file
|
||||
</ParamField>
|
||||
|
||||
<ParamField body="-i" type="boolean">
|
||||
Case-insensitive search. Maps to `rg -i`.
|
||||
</ParamField>
|
||||
|
||||
<ParamField body="-n" type="boolean">
|
||||
Show line numbers in output. Applies to `output_mode: "content"` only. Defaults to `true`.
|
||||
</ParamField>
|
||||
|
||||
<ParamField body="-A" type="number">
|
||||
Lines of context to show after each match. Applies to `output_mode: "content"` only. Maps to `rg -A`.
|
||||
</ParamField>
|
||||
|
||||
<ParamField body="-B" type="number">
|
||||
Lines of context to show before each match. Applies to `output_mode: "content"` only. Maps to `rg -B`.
|
||||
</ParamField>
|
||||
|
||||
<ParamField body="context" type="number">
|
||||
Lines of context to show before and after each match (equivalent to `rg -C`). Takes precedence over `-A` and `-B`. Applies to `output_mode: "content"` only.
|
||||
</ParamField>
|
||||
|
||||
<ParamField body="multiline" type="boolean">
|
||||
Enable multiline mode where `.` matches newlines and patterns can span multiple lines (`rg -U --multiline-dotall`). Default: `false`.
|
||||
</ParamField>
|
||||
|
||||
<ParamField body="head_limit" type="number">
|
||||
Limit output to the first N lines or entries (equivalent to `| head -N`). Applies across all output modes. Defaults to **250**. Pass `0` for unlimited results.
|
||||
</ParamField>
|
||||
|
||||
<ParamField body="offset" type="number">
|
||||
Skip the first N entries before applying `head_limit` (equivalent to `| tail -n +N`). Useful for paginating large result sets. Defaults to `0`.
|
||||
</ParamField>
|
||||
|
||||
### Output modes
|
||||
|
||||
<Tabs>
|
||||
<Tab title="files_with_matches (default)">
|
||||
Returns a list of file paths that contain at least one match, sorted by modification time.
|
||||
|
||||
```
|
||||
Found 3 files
|
||||
src/utils/permissions/bashClassifier.ts
|
||||
src/tools/BashTool/BashTool.tsx
|
||||
src/tools/BashTool/bashPermissions.ts
|
||||
```
|
||||
</Tab>
|
||||
|
||||
<Tab title="content">
|
||||
Returns the matching lines themselves, with optional surrounding context.
|
||||
|
||||
```
|
||||
src/utils/permissions/bashClassifier.ts:42:export function classifyBashCommand(
|
||||
src/utils/permissions/bashClassifier.ts:43: command: string,
|
||||
```
|
||||
</Tab>
|
||||
|
||||
<Tab title="count">
|
||||
Returns match counts per file.
|
||||
|
||||
```
|
||||
src/utils/permissions/bashClassifier.ts:7
|
||||
src/tools/BashTool/bashPermissions.ts:3
|
||||
|
||||
Found 10 total occurrences across 2 files.
|
||||
```
|
||||
</Tab>
|
||||
</Tabs>
|
||||
|
||||
### Pattern syntax notes
|
||||
|
||||
<Accordion title="Escaping braces for Go / TypeScript">
|
||||
Ripgrep treats `{` and `}` as literal characters by default, unlike some regex engines that use them for quantifiers. To search for literal braces, escape them:
|
||||
|
||||
```
|
||||
interface\{\} → finds interface{}
|
||||
map\[string\] → finds map[string]
|
||||
```
|
||||
</Accordion>
|
||||
|
||||
<Accordion title="Multiline patterns">
|
||||
By default, `.` does not match newlines. To search across line boundaries:
|
||||
|
||||
```json theme={null}
|
||||
{
|
||||
"pattern": "struct \\{[\\s\\S]*?field",
|
||||
"multiline": true
|
||||
}
|
||||
```
|
||||
</Accordion>
|
||||
|
||||
<Accordion title="Combining glob and type filters">
|
||||
`glob` and `type` can be used independently or together:
|
||||
|
||||
```json theme={null}
|
||||
{ "pattern": "TODO", "type": "ts" }
|
||||
```
|
||||
|
||||
```json theme={null}
|
||||
{ "pattern": "TODO", "glob": "src/**/*.ts" }
|
||||
```
|
||||
|
||||
Use `type` for standard language types; use `glob` when the file set doesn't align with a named type.
|
||||
</Accordion>
|
||||
|
||||
### Excluded directories
|
||||
|
||||
Grep automatically excludes version-control metadata directories: `.git`, `.svn`, `.hg`, `.bzr`, `.jj`, `.sl`.
|
||||
|
||||
|
||||
Built with [Mintlify](https://mintlify.com).
|
||||
154
docs/claude-code-docs-main/en/reference/tools/web.md
Normal file
154
docs/claude-code-docs-main/en/reference/tools/web.md
Normal file
@@ -0,0 +1,154 @@
|
||||
> ## Documentation Index
|
||||
> Fetch the complete documentation index at: https://vineetagarwal-code-claude-code.mintlify.app/llms.txt
|
||||
> Use this file to discover all available pages before exploring further.
|
||||
|
||||
# Web
|
||||
|
||||
> Fetch web pages and search the internet for current information.
|
||||
|
||||
Claude Code has two web tools: `WebFetch` for retrieving and analyzing specific URLs, and `WebSearch` for querying the web when information may be beyond Claude's training cutoff.
|
||||
|
||||
***
|
||||
|
||||
## WebFetch
|
||||
|
||||
Fetches a URL, converts the HTML to markdown, and then processes the content using a small fast model with a prompt you provide. Returns the model's response — not the raw page content.
|
||||
|
||||
### Parameters
|
||||
|
||||
<ParamField body="url" type="string" required>
|
||||
A fully-formed, valid URL. HTTP URLs are automatically upgraded to HTTPS.
|
||||
</ParamField>
|
||||
|
||||
<ParamField body="prompt" type="string" required>
|
||||
A natural-language prompt describing what to extract or analyze from the page content. The fetched content is passed to a secondary model along with this prompt, and the model's response is returned.
|
||||
</ParamField>
|
||||
|
||||
### Behavior
|
||||
|
||||
1. Claude fetches the URL and converts HTML to markdown.
|
||||
2. The markdown and the `prompt` are sent to a small, fast model.
|
||||
3. That model's response is returned as the tool result.
|
||||
|
||||
Because a secondary model processes the content, the result is always a synthesized answer — not a raw dump of the page. If the content is very large, it may be summarized automatically.
|
||||
|
||||
<Info>
|
||||
WebFetch includes a 15-minute in-memory cache. Repeated calls to the same URL within that window return cached content without a network request.
|
||||
</Info>
|
||||
|
||||
### Redirects
|
||||
|
||||
When a URL redirects to a different host, the tool returns a special message indicating the redirect destination rather than following it automatically. Claude then makes a new `WebFetch` call with the redirect URL.
|
||||
|
||||
### Limitations
|
||||
|
||||
* Read-only — does not submit forms or interact with pages
|
||||
* Not suitable for pages requiring authentication (login walls, paywalls)
|
||||
* For GitHub resources, prefer the `gh` CLI via `Bash` (e.g., `gh pr view`, `gh issue view`, `gh api`)
|
||||
|
||||
<Tip>
|
||||
If an MCP-provided web fetch tool is available in your environment, it may have fewer restrictions and should be preferred over this built-in tool.
|
||||
</Tip>
|
||||
|
||||
### Example usage
|
||||
|
||||
<Tabs>
|
||||
<Tab title="Extract API details">
|
||||
```json theme={null}
|
||||
{
|
||||
"url": "https://docs.example.com/api/authentication",
|
||||
"prompt": "What authentication methods are supported and what headers are required?"
|
||||
}
|
||||
```
|
||||
</Tab>
|
||||
|
||||
<Tab title="Check library version">
|
||||
```json theme={null}
|
||||
{
|
||||
"url": "https://github.com/some-org/some-lib/blob/main/CHANGELOG.md",
|
||||
"prompt": "What changed in the latest version?"
|
||||
}
|
||||
```
|
||||
</Tab>
|
||||
|
||||
<Tab title="Read documentation">
|
||||
```json theme={null}
|
||||
{
|
||||
"url": "https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API",
|
||||
"prompt": "Summarize the Fetch API and show a basic usage example."
|
||||
}
|
||||
```
|
||||
</Tab>
|
||||
</Tabs>
|
||||
|
||||
***
|
||||
|
||||
## WebSearch
|
||||
|
||||
Searches the web and returns results including titles, URLs, and a model-synthesized summary. Useful when information may be newer than Claude's training data.
|
||||
|
||||
<Info>
|
||||
Web search is only available in the United States. It requires a compatible API provider (Anthropic first-party, Vertex AI with Claude 4.0+ models, or Foundry).
|
||||
</Info>
|
||||
|
||||
### Parameters
|
||||
|
||||
<ParamField body="query" type="string" required>
|
||||
The search query to execute. Minimum length: 2 characters.
|
||||
</ParamField>
|
||||
|
||||
<ParamField body="allowed_domains" type="string[]">
|
||||
When set, only return results from these domains. Cannot be combined with `blocked_domains` in the same request.
|
||||
|
||||
Example: `["docs.python.org", "peps.python.org"]`
|
||||
</ParamField>
|
||||
|
||||
<ParamField body="blocked_domains" type="string[]">
|
||||
Exclude results from these domains. Cannot be combined with `allowed_domains` in the same request.
|
||||
|
||||
Example: `["w3schools.com"]`
|
||||
</ParamField>
|
||||
|
||||
### Output
|
||||
|
||||
The tool returns search results as structured blocks containing:
|
||||
|
||||
* Result titles and URLs
|
||||
* A synthesized summary produced by a model that has access to the search results
|
||||
|
||||
Claude is required to cite sources from web searches by appending a `Sources:` section with markdown hyperlinks to its response.
|
||||
|
||||
### Domain filtering
|
||||
|
||||
<Accordion title="Restricting to specific domains (allowed_domains)">
|
||||
Use `allowed_domains` when you want results exclusively from trusted or authoritative sources:
|
||||
|
||||
```json theme={null}
|
||||
{
|
||||
"query": "Python asyncio best practices 2024",
|
||||
"allowed_domains": ["docs.python.org", "realpython.com"]
|
||||
}
|
||||
```
|
||||
</Accordion>
|
||||
|
||||
<Accordion title="Excluding domains (blocked_domains)">
|
||||
Use `blocked_domains` to suppress low-quality or paywalled sources:
|
||||
|
||||
```json theme={null}
|
||||
{
|
||||
"query": "React server components tutorial",
|
||||
"blocked_domains": ["medium.com"]
|
||||
}
|
||||
```
|
||||
</Accordion>
|
||||
|
||||
### Search limits
|
||||
|
||||
Each `WebSearch` invocation performs up to **8 individual web searches** internally. Claude automatically refines queries as needed within that budget.
|
||||
|
||||
### Current date awareness
|
||||
|
||||
When searching for recent information, Claude includes the current year in search queries to avoid returning outdated results — for example, appending the year when searching for library documentation or current events.
|
||||
|
||||
|
||||
Built with [Mintlify](https://mintlify.com).
|
||||
Reference in New Issue
Block a user