What does Claude Code do by default when a fetched web page, a file or an MCP result carries injected instructions?
answer
- limit the action, not the reading
- WebFetch answers through a second model call
- network commands are not read-only
- unparseable commands fail closed
- starting mode changed in 2.1.283
basics
~20 sClaude Code gates what injected text can lead to: WebFetch returns a separate model call's extraction, not the raw page; Manual mode prompts for curl, wget and unparseable commands; auto mode's classifier judges actions with tool results stripped.
solid answer
~50 sInjected text arrives through any tool result: a WebFetch page, a repository file, command output or an MCP result. Claude Code's defaults work on what happens next. For most fetches, WebFetch runs your extraction prompt over the page in a separate model call and Claude receives that answer, not the raw page; a hostname blocklist check runs first. In Manual mode, `curl`, `wget` and other non-read-only commands prompt, a command the analysis can't fully parse prompts even when an allow rule like `Bash(git *)` covers part of it, and unmatched commands fail closed. Since 2.1.283 interactive terminal and VS Code sessions start in auto mode by default when it is available, where a classifier reviews actions with tool results stripped and a server-side probe flags suspicious tool results. None of it is a guarantee, so review commands before approving them.
go deeper
Recall that injected text can arrive in web pages, files and tool results, and that Claude Code's answer is to gate actions rather than filter reading.
Explain WebFetch's separate extraction call, why curl and wget prompt in Manual mode, and the command-analysis prompt that a partial allow rule can't skip.
Account for the starting mode: since 2.1.283 a fresh interactive session starts in auto mode by default, so know which protections then come from the classifier and the result-scanning probe.
Judge when per-action review is enough and when untrusted inputs justify heavier isolation, and say which layer enforces rather than which file asks nicely.
## Where untrusted text enters **Prompt injection** is hostile text placed where an AI assistant will read it, written to redirect it toward actions you never asked for. In Claude Code it can arrive through: - a page fetched with the **WebFetch** tool; - a file in the repository, such as a README, an issue export or a vendored dependency; - the output of a shell command, such as a failing test's log; - the result of an **MCP** tool call. To the model, all of these are ordinary input; a README carries no less weight than your own message unless something in the harness treats it differently. Claude Code does not try to promise the model will never read such text. Its defaults instead shape **what the text reaches** and **what an action it inspires must pass** before it runs. ## Layer 1: WebFetch's extraction step - WebFetch takes a URL and a prompt describing what to extract. It converts an HTML response to Markdown and, for most fetches, runs the prompt against it in a **separate model call**, and returns **that call's answer** to Claude rather than the raw page. - Large pages are truncated to a fixed character limit before processing, and the result is lossy by design: a reply saying a page "doesn't mention" something may only mean the prompt didn't ask. - Before fetching, the **WebFetch domain safety check** sends only the hostname to `api.anthropic.com` to test it against a blocklist Anthropic maintains; `skipWebFetchPreflight: true` turns that check off. - WebFetch refuses `localhost` and dotless hostnames, and returns a redirect to a different host as text instead of following it. - A file Claude reads or an MCP result has no such extraction step, so for those sources the action layer is what protects you. ## Layer 2: what an injected instruction must get past - **Network commands**: `curl`, `wget` and similar commands are not auto-approved. In Manual mode they prompt like any other non-read-only Bash command; you can approve once, add an allow rule such as `Bash(curl *)`, or put them in `permissions.deny`. - **Command injection detection**: in Manual mode, Claude Code asks before running a Bash command it can't fully analyze, and an allow rule for part of the command, such as `Bash(git *)`, doesn't skip that prompt. Commands longer than 10,000 characters always prompt. - **Fail-closed matching**: a command no rule matches requires approval. - **Network request approval**: in Manual and `acceptEdits` modes, WebFetch prompts unless a rule already covers the domain or it is in a small preapproved set of documentation domains. ## Which mode you are in decides who answers | Situation | Manual mode (`default`) | Auto mode | |---|---|---| | WebFetch to a new domain | Prompts you | No prompt, unless an explicit `ask` rule matches; the domain check still runs | | `curl` or `wget` | Prompts you | The classifier reviews it instead of you | | What the reviewer sees | You see the command | Tool results are stripped from what the classifier reads | | Tool results arriving | No result-scanning probe | A server-side probe scans them and flags suspicious content | With **Claude Code 2.1.283 or later**, auto mode is the built-in starting permission mode for interactive terminal and VS Code sessions whenever auto mode is available to the session, so the Manual-mode prompts above are what you get when a flag, a settings file or unavailability puts you in Manual mode. `claude -p` and SDK sessions follow their own starting-mode rules. How auto mode's classifier decides, and what it still asks about, is the permission-modes material. ## What none of this does 1. It does not detect every injection; the docs say plainly that no system is immune. 2. An instruction in CLAUDE.md telling Claude to ignore embedded instructions is guidance, not enforcement; permission rules, modes, hooks and the sandbox decide what can run. 3. A deny rule matches a command as written, so network enforcement that doesn't depend on command text is the sandbox's job. 4. The docs' own practices still apply: review commands before approval, avoid piping untrusted content straight to Claude, verify changes to critical files, and use a VM when working with external services.
- Why might WebFetch report that a page doesn't mention something the page actually contains?WebFetch is lossy by design: Claude receives a separate model call's answer to the extraction prompt, and large pages are truncated first. If the prompt didn't ask about the detail, the answer may omit it. Ask for a more specific fetch, or use `curl` through Bash for the unprocessed page.
- In Manual mode, does an allow rule such as `Bash(git *)` let any git command run without a prompt?No. Command injection detection asks before a Bash command Claude Code can't fully analyze, and an allow rule for part of the command doesn't skip that prompt. Commands over 10,000 characters always prompt. Sandboxed commands are the documented exception that can run without it.
- What does the WebFetch domain safety check send, and how do you turn it off?Only the requested hostname goes to `api.anthropic.com`, checked against an Anthropic blocklist; a passing hostname is cached for five minutes. It runs whatever model provider you use. `skipWebFetchPreflight: true` disables it, and then `WebFetch(domain:...)` rules are what restrict which domains Claude can reach.
- WebFetch passes a page's raw HTML straight into Claude's context.
- curl and wget count as read-only, so Claude Code runs them without asking.
- An allow rule like Bash(git *) skips every prompt for any git command.
- Auto mode's classifier reads the fetched page to judge whether it is hostile.
- A CLAUDE.md line saying to ignore embedded instructions blocks prompt injection.
- Every new interactive session still starts in Manual mode and prompts for curl.
Assumes Claude Code 2.1.286; since 2.1.283 auto mode is the built-in starting mode for interactive terminal and VS Code sessions, so Manual-mode prompts apply when a flag, settings or unavailability selects Manual.