---
description: "Post-mortem of a run from its session transcripts: loops, stalls, root-cause hypotheses on file:line, fixes. Read-only, redacted. Use when a run went wrong or ran far too long."
description-tr: "Bir koşunun oturum transkriptlerinden post-mortem'i: ne oldu, nerede döngüye girdi veya takıldı, file:line'a dayalı kök-neden hipotezleri, önerilen düzeltmeler. Salt-okunur; gösterilmeden önce redakte edilir."
argument-hint: "[#id | transcript.jsonl] [--audit]  -  a run (task id or #N) or a session file; no argument means the most recent run. --audit re-checks the draft against the index"
parameters: [{"name":"target","kind":"text"},{"name":"--audit","kind":"flag"}]
gui: button
destructive: false
confirm: none
---

# multi-agent postmortem  -  Run Post-Mortem

**Input**: $ARGUMENTS

Explains what a run actually did, read from the session transcripts it ran in,
not from what the run log says it decided. The evidence comes from a
deterministic indexer; the model only interprets it.

The indexer reads all three hosts and detects the format per file:

| Host | Session files |
|------|---------------|
| Claude Code | `~/.claude/projects/<dir>/<session>.jsonl` plus its subagent files |
| Copilot CLI | `~/.copilot/session-state/<session>/events.jsonl` (cited as `<first 8 of session>/events.jsonl`) |
| Codex | `~/.codex/sessions/YYYY/MM/DD/rollout-*.jsonl` (cited as `rollout-<first 8 of session>.jsonl`) |

Copilot CLI reports tokens per session, so its turns carry output tokens only
and the totals come from the session's shutdown record; Codex reports them per
request.

**Read-only.** Nothing is sent anywhere: no issue comment, no PR, no channel.
The one write is the report itself, saved under the run's log directory.

## Steps

1. **Resolve the target.**
   - A path ending in `.jsonl` (any of the three hosts): index that file
     (Claude Code subagent files beside it are included). There is no run directory, so nothing is saved unless the user
     names one.
   - A task id or `#N`: locate the run and its transcripts:
     ```bash
     node "$HOME/.claude/scripts/transcript-index.mjs" --run "<id>" --locate
     ```
     `matchedBy: "session"` means the run recorded its session id and the match
     is exact. `"time-window"` means it did not (attended runs record none), so
     the files are the sessions, on any host, that ran in the run's worktree or
     checkout while it was active; say that this match is a heuristic. Exit 3 with a `reason`:
     report the reason, and offer to take a transcript path instead.
   - No argument: take the most recent run from
     `node "$HOME/.claude/scripts/runs-index.mjs" --json` (latest `startedAt`)
     and continue as above.

2. **Index.**
   ```bash
   node "$HOME/.claude/scripts/transcript-index.mjs" --run "<id>"         # or: <file.jsonl>
   ```
   The output lists turns, loops (identical tool calls repeated), stalls (gaps
   while a tool or the model was working), compactions, subagents with their
   results, errors and denials, skill and command invocations, the slowest tool
   calls and a timeline. Every item carries `file:line`, the line of the JSONL
   it came from. Exit 4 means the redaction guard found a credential left in the
   output and printed nothing: report that and stop; never fall back to reading
   the transcript directly.

   Read only the index. Do not open the transcript files: the index is the
   redacted view, the files are not.

3. **Write the post-mortem** in `prefs.global.outputLanguage`, short:
   - **What happened**: the run in five lines or fewer, from the turns and
     timeline.
   - **Where it looped or stalled**: each loop and stall that matters, with its
     citations.
   - **Root-cause hypotheses**: each one a hypothesis, not a verdict, and each
     anchored to at least one `file:line` from the index. A hypothesis with no
     citation is left out.
   - **Suggested fixes**: concrete and tied to a hypothesis (a prompt rule, a
     guard, a timeout, a tool to use instead).
   - **Evidence limits**: the matching method (`session` / `time-window`),
     malformed or truncated lines, and the redaction count the index reported.

   Quote only excerpts the index already shows; they are redacted.

4. **Audit pass** (`--audit`): re-read the draft against the index. Every cited
   `file:line` must exist in the index and say what the draft claims; every
   count must match the index's counts. Correct or drop what does not hold, and
   add one line: `audit: N claims checked, M corrected`.

5. **Save.** With a run directory, write the report to
   `<runDir>/postmortem.md` (`runDir` from step 1, `~` expanded) and give the
   path. That file is the only write this command makes.
