# One question, one bounded context

An agent usually has one question and one budget, not a browsing session. `snapshot_context` is
the one-call answer: give it a question, files, symbols or explicit line ranges, and it returns the
smallest redacted, line-numbered context that fits the token ceiling. Every planned file that did
not fit is named in `omitted[]`, hidden instructions are removed, and the response carries the same
`trust` envelope as every other read-only tool plus a verifiable context receipt.

```json
{
  "name": "snapshot_context",
  "arguments": {
    "question": "how does redaction decide what to mask?",
    "maxTokens": 20000
  }
}
```

`planOnly: true` returns the ranked reading plan without bodies. Use it when you want to choose
what to open yourself; use the default when you want the context in one call. With `files`,
`symbols` and `ranges`, the planner is skipped and those targets are assembled directly, still
under the same budget and with the same omission list. A symbol target starts at its declaration
span, not line 1; a range target is numbered from the requested start line.

The live index is used by default, so uncommitted edits and new files are visible without running
generate. live: false requires the persisted snapshot.

## When to use snapshot_context

- **An agent has one question and a token budget.** The tool returns a reading set, not a
  repository. It is the difference between "here is the codebase" and "here is what answers this".
- **You want the plan before the bodies.** planOnly returns ranked files and token costs without
  spending the budget on content. A caller can show the plan, ask a human to approve it, then fetch
  the bodies.
- **You already know the files or symbols.** Pass files or symbols directly; the planner is skipped,
  and the same budget and omission accounting still apply.

It is not the right tool for "review this whole pull request" (use a brief), "what does this change
break" (use impact), or "find a string" (use locate).

## What the planner does

The planner scores files from the question terms against paths, symbol names, layers and kinds. It
adds importer centrality, then pulls in the imports of the strongest matches and a bounded number of
their callers. It takes whole files while they fit, halves a large file when its head is affordable,
and stops when the budget is exhausted. Every file it did not take is named in omitted.

The scoring is deliberately simple and inspectable. It is not an embedding search and does not
claim semantic understanding; a question whose terms do not appear in a path or symbol will fall
back to the most-imported files, and the response says so in trust.reasons.

## What comes back

The structured response contains:

| Field | Meaning |
| :-- | :-- |
| budgetTokens | The ceiling the caller asked for. |
| usedTokens | The estimate actually spent on the returned bodies. |
| files | The chosen files, each with its part, layer, kind, `fromLine`/`toLine`, symbol (if any) and why it was chosen. |
| omitted | Every planned file that did not fit, with the reason. |
| security | Hidden-instruction comments and invisible characters removed from the returned bodies. |
| receipt | SHA-256 digest of the canonical response chunks, omissions, security findings and trust. Optional Ed25519 signature. |
| trust | Index source, freshness, coverage, redaction count and named partial reasons. |

A file in files may be a window rather than the whole body. The window is line-numbered with the
real source line numbers and states whether more remains, so an agent can ask for the next page
instead of assuming it has the file. Hidden HTML comments that look like instructions, zero-width
characters and bidi controls are removed before the body is returned; the security array names what
was removed without echoing the payload.

## A worked example

    {
      "name": "snapshot_context",
      "arguments": {
        "question": "how does redaction decide what to mask?",
        "maxTokens": 12000,
        "linesPerFile": 120
      }
    }

A run on this repository typically selects the redaction engine, its pattern catalogue, the tests
that exercise span masking and the scanner that decides which files are eligible. The response
names the files that did not fit; if the redaction tests are omitted, the trust envelope still says
coverage is complete for the plan, because the plan itself is what was bounded. Read omitted before
concluding that the answer is complete.

## Line targeting and receipts

Pass `symbols` when you know the declaration; the tool uses the parsed `declarationSpans` and
returns the span, with `fromLine`/`toLine` and `symbol`. Pass `ranges` when you already know the
lines:

```json
{
  "name": "snapshot_context",
  "arguments": {
    "ranges": [{ "path": "src/mcp/retrieval.ts", "startLine": 96, "endLine": 135 }],
    "maxTokens": 4000
  }
}
```

The receipt is deterministic for the same index and inputs. `digest` covers the canonical chunk
metadata, omission list, security findings and trust envelope; each chunk also has its own
`sha256`. Set `signReceipt: true` with `SNAPSHOT_SIGNING_KEY` configured to add an Ed25519
signature over the same canonical payload. A receipt proves what was returned; it does not prove
the code was correct.

## Limits

- **Terms, not intent.** Synonyms the planner does not know are missed. Pass files, symbols or
  ranges when you know the target.
- **Token estimates, not tokenizer counts.** The estimate is useful for choosing a budget; it is not
  a model's exact count.
- **No write access.** The tool never edits or runs code. It returns context.
- **No guarantee of completeness.** A small budget can omit the one file that mattered; the omission
  list is the honest part of the answer.

## The old tools

`snapshot_answer`, `snapshot_plan_for` and `snapshot_budget` were folded into
`snapshot_context` in 0.21.0. The plan/budget distinction is now `planOnly: true`; a multi-budget
comparison is a sequence of calls, which is cheaper than a tool that exists only to repeat the
planner.

→ [CLI reference](cli.md) · [MCP tools](tools.md) · [Impact](impact.md)

## Related

- [MCP tools](tools.md) — the other six tools and their schemas.
- [MCP server for a codebase](mcp-server-for-codebase.md) — setup and security.
- [LLM codebase context](llm-codebase-context.md) — the broader guide.
