# Feature: Session Brief (plain sessions, opt-in)

**Off by default.** Turn it on with `prefs.global.sessionBrief.enabled: true`. Claude Code only: the hook is `session-brief.sh` on SessionStart (`startup|resume|clear|compact`), so the block is shown again after a compaction. The installer registers the hook; with the setting off it prints nothing, starts nothing and returns in a few milliseconds.

A pipeline run loads the learnings ledger in Phase 0. An ordinary session would start knowing none of it. The brief is an index, not the memory: every ledger line carries its pointer, and the detail is one call away (`learnings_get`, `learnings_search`, or `learnings-ledger.mjs show --id <id>`).

## What each setting injects

| Setting | Injects | Default |
| --- | --- | --- |
| `enabled` | the ledger layer: counts by kind and up to `maxEntries` standing entries, best first, as many as fit, inside an `<untrusted-data>` block; plus one line about the code graph when one exists | false |
| `maxEntries`, `maxChars`, `kinds` | bound the block (0 to 10 entries, 400 to 4000 characters, which ledger kinds) | 5, 2400, all |
| `discipline` | a few working notes: lead with the answer; ask one question about why only when the goal is genuinely unclear; name 2-3 options and recommend one for an open choice; give each step a check; say so when a simpler route exists; give time in minutes or hours | false |
| `prefs.global.codeGraph.enabled false` | removes the graph line | |

The skill-routing line (the `index` skill of each enabled toolkit) rides along whenever the ledger or graph layer prints. A repository with no standing ledger entries and no code graph gets nothing at all, no routing line and no status line, and so does a repository in `memory.excludeProjects`. The user sees one status line (`systemMessage`) in the output language when something was injected.

Standing means: not superseded, not suppressed by feedback, and passing the secret scan. Ranking is confidence, then repository-wide before path-scoped, then kind (security notes and decisions first), then newest. The header counts only entries the scan did not refuse.

## What is printed and how it is made safe

Each entry line is built from the kind, statement and scope. Every field is cleaned: control, bidi and zero-width characters removed; home paths masked to `~`; ticket-key-shaped tokens (capitals, a dash, digits, so `UTF-8` too) masked; markup tags and tool-call words defused; whitespace folded; clipped by code point. The cleaned line and the unclipped fields are both secret-scanned, and a refused entry is left out.

Files are read only when they are regular files reached without a final symlink and under a size cap (ledger and feedback 4 MiB, preferences 1 MiB, graph 128 MiB). A FIFO, directory or link is skipped, so none of them can block a session. The builder exits after 10 seconds regardless.

## Silence

The hook prints nothing and builds nothing when any of these holds: `MULTI_AGENT_UNATTENDED` is set and not `0`; `MULTI_AGENT_TASK_ID` or `MULTI_AGENT_PHASE` is set; `CLAUDE_CODE_SESSION_ATTENDED` is set and not `1`; `CLAUDE_CODE_ENTRYPOINT` starts with `sdk`; `MULTI_AGENT_SESSION_BRIEF=0`; `HOME` is unset; the directory is not a repository.

What could and could not be detected: the SessionStart payload carries no field that tells a `claude -p` session apart, so non-interactive detection rests on the two host environment variables above. Their values were observed only in an interactive session (`CLAUDE_CODE_ENTRYPOINT=cli`, `CLAUDE_CODE_SESSION_ATTENDED=1`); that a `claude -p` run sets different values is expected and not verified.

## Cost

Measured by review at the defaults with a populated ledger: about 350 tokens per session, paid again after each compaction. Warm hook about 31 ms; a cold build about 3 s, in a background process, never on the session's critical path. The status line the user sees states the token estimate of what was injected (bytes divided by four).

## How the cache works

`session-brief.sh` runs builtins and one `git rev-parse`, then prints a cached file. The cache is `~/.claude/memory/multi-agent/_session-brief/<repo>-<hash>.json` (directory 0700, file 0600), named from the repository's common directory (djb2 hash, computed alike in bash and node). Its first line is `#sb1|<common dir>|<HEAD>`. The hook prints the cache only when that header equals this repository and this HEAD, the file is a regular file under 16,000 characters, and the body is one line with no control characters. Otherwise it prints nothing this session and starts a rebuild: a detached `session-brief.mjs build`, guarded by a lock directory (a lock older than five minutes is ignored).

With the header matching, the old cache is still printed while a rebuild runs after any of these files is newer than the cache: the repo's `learnings-ledger.jsonl` and `learnings-feedback.jsonl`; the cross-repo `_global/learnings-ledger.jsonl`; the repo's `code-graph.json`; the preferences file; `~/.claude/settings.json` and `settings.local.json`; the repo's `.claude/settings.json` and `settings.local.json`; `~/.claude/plugins/installed_plugins.json`.

The cache sits under the memory root, so `uninstall --all-data` removes it with the ledger it was built from.
