# Briefs

`codebase-snapshot brief` packs one reviewer-ready Markdown document: a question or a change, the
impact it reaches, the candidate tests, and bounded redacted source windows. It is the formatting
layer over `impact` and `context`; it does not invent a second graph.

## Run it

```bash
codebase-snapshot brief "how does authentication work?"
codebase-snapshot brief --diff origin/main
codebase-snapshot brief --paths src/router.ts --out notes/review.md
codebase-snapshot brief --diff HEAD --copy
codebase-snapshot brief --diff HEAD --format json
```

With neither a question nor `--diff`/`--paths`, the change is the working tree against `HEAD`.
The brief uses the live index by default and writes nothing into the repository; `--no-live`
requires the persisted snapshot.

## What it contains

1. A trust stamp: index source, freshness, coverage, redaction count, omitted count, and any named
   partial reason.
2. The question or impact summary.
3. For a change: changed files, symbol-pruned affected files, routes, candidate tests and warnings.
4. For a diff: the diff hunks, passed through the same span-masking redaction as every other artifact.
   No raw credential excerpt is copied into the brief.
5. Bounded source windows for the files that matter, until `--max-tokens` is reached.
6. A named list of files that did not fit or are unavailable. Nothing is dropped silently.

`--format pr-comment` renders the affected-file list and details as a collapsible GitHub comment.
`--out` writes inside the repository only; a path that escapes through `..` or a link is refused.
`--copy` uses the platform clipboard command (`clip`, `pbcopy`, `wl-copy` or `xclip`) with
`shell: false`.

## Options

| Option | Meaning |
| :-- | :-- |
| `--diff <ref>` | Compare the working tree with a git ref. |
| `--paths <a,b>` | Treat repository-relative paths as the change. |
| `--max-tokens <n>` | Token budget for the assembled brief (default 12000, minimum 500). |
| `--lines-per-file <n>` | Line window per file (default 80). |
| `--include-tests` | Include candidate tests, not only production impact. |
| `--copy` | Copy the finished brief to the clipboard. |
| `--out <path>` | Write the brief to a repository-relative path. |
| `--format json` | Return `{ markdown, usedTokens, files, omitted, trust }` and keep stdout parseable. |
| `--format pr-comment` | Render collapsible PR-comment sections. |
| `--no-cache` | Bypass the OS live-index summary cache. |
| `--no-live` | Require the generated snapshot. |

## When a brief is the right tool

- **A pull request needs one review artefact.** The brief puts the change, its affected files, the
  candidate tests and bounded source windows in one Markdown document a reviewer can paste into a
  comment or a model.
- **The reviewer is not the author.** A trust stamp and an explicit omission list let someone who
  did not write the code judge whether the context is complete.
- **You need a redacted diff.** The diff is masked with the same span rules as every other artifact;
  a credential in the hunk does not reach the brief.

Use a snapshot instead when the task is "explain this repository"; use impact when the task is
"tell me what this change reaches" and you do not need prose.

## What a review looks like

    codebase-snapshot brief --diff origin/main --format pr-comment

```text
# Change brief

Trust: source=live-overlay · freshness=live-computed · coverage=complete · redacted=0 · omitted=0

**Changed:** 3 · **Affected:** 7 · **Tests:** 2

<details><summary>Affected files</summary>
...
</details>

### `src/auth/session.ts` — changed
...
```

The exact headings depend on the format. In every format the same three facts are present: what
changed, what the tool believes it reaches, and what it could not include.

## What it does not do

- It does not run the tests it names; it selects candidates.
- It does not prove runtime reachability; the impact report is a static, conservative analysis.
- It does not silently fill a budget with unrelated files. A file that does not fit is named in the
  omission list.
- It does not edit the repository unless --out names a path; that write is confined to the repository.

## Why it exists

A review starts with a diff, but the diff is not the change: the call sites, the route and the test
that will fail are elsewhere. The brief puts those on one page, marks what is evidence and what is a
candidate, and stamps the trust envelope so a reader can tell a complete answer from a partial one.

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

## Related

- [Impact reports](impact.md) — the analysis a brief is built from.
- [MCP server for a codebase](mcp-server-for-codebase.md) — the same tools over MCP.
- [LLM codebase context](llm-codebase-context.md) — the broader guide.
