---
description: "Pick up unfinished work: a pipeline run that stopped mid-phase, or work already written on the current branch that never went through the pipeline. Use when a task stopped or failed, or when hand-written local work needs review, build, PR and reporting."
description-tr: "Yarım kalan işi sürdürür: ortada duran bir pipeline koşusu ya da mevcut branch'te elle yazılmış, pipeline'dan hiç geçmemiş iş."
argument-hint: "[#id | PROJ-12345] [--base <branch>] [--answer <option-id>] [autopilot]  -  no argument: pick from the list"
parameters: [{"name":"task","kind":"run-id"},{"name":"--base","kind":"branch"},{"name":"--answer","kind":"text"},{"name":"autopilot","kind":"flag"}]
gui: form
destructive: false
confirm: none
allowed-tools: Agent, Bash, Read, Write, Edit, Glob, Grep, TaskCreate, TaskUpdate, TaskList, TaskGet, AskUserQuestion, WebFetch, WebSearch, Skill
---

# multi-agent resume  -  Continue Unfinished Work

**Input**: $ARGUMENTS

> **Language (read FIRST)**: read `prefs.global.outputLanguage` before any output; chat, `AskUserQuestion` `question` / `label` / `description` and payload bodies follow it, `header` (<=12 chars), identifiers, commit messages and branch names stay English (`$HOME/.claude/multi-agent-refs/rules.md` "Language Application").

Unfinished work arrives two ways, decided by the repository:

- **A tracked run stopped.** It has an `agent-state.json`, a phase, maybe a worktree. It resumes where it stopped.
- **Work on the current branch with no run behind it.** The **pipeline tail** runs over the diff: Review (with its build gate) → Commit/PR → Report. Plan and Dev never run; the diff is the Dev output.

Examples, when NOT to use it and modes: `$HOME/.claude/multi-agent-refs/resume/details.md` "Usage".

**Access check, before anything else.** A resumed run skips Phase 0, so it asks here:

```bash
ACCESS_LINE=$(node "$HOME/.claude/scripts/usage-access.mjs"); ACCESS_RC=$?
```

`ACCESS_RC` 3: print `$ACCESS_LINE` as written and stop. No list, no state change, no question, attended or unattended. Any other exit continues (the check fails open). Contract: `features/usage-reporting.md` "The access check".

## Steps

### Step 1  -  Build the resumable list, then ask

Collect both sources before rendering. An argument naming a run (`#N`, a Jira id, an issue number) selects it and skips the question; an argument naming nothing resumable is an error, never a silent fall-through to the tail.

**Source A  -  tracked runs**: each `agent-state.json` under `$HOME/.claude/logs/multi-agent/{project}/` with `status != "done"` (id, phase, workspace, idle time, `haltReason`).

**Source B  -  untracked work**: base = `--base` → `figma-config.project.baseBranch` → `develop` → upstream/merge-base; work = `git diff <base>...HEAD` plus uncommitted changes. Shown only when non-empty **and** no Source A run owns this branch.

**Ask** per `$HOME/.claude/multi-agent-refs/picker-contract.md`: breadcrumb `Step 1/1: which unfinished work to pick up`, `header` `Resume what`, Source A rows first (newest first), Source B last; branch on the selected row, never on label text. **One candidate is still a question**, with a genuine escape as the second option: read `resume/details.md` "Single-candidate escape" before Step 1. Zero rows: do not ask; stop with `ERR: nothing to resume  -  no stopped run for this project and no local changes on {branch} vs {base}`.

A Source A row runs Steps 2-5 only; a Source B row runs Steps 6-7 only. Never both.

### Step 2  -  Tracked run: read and validate state

- `node $HOME/.claude/scripts/validate-state.mjs <state-file>`. Non-zero: do NOT guess a phase; stop with `ERR: agent-state.json is unsafe to resume; inspect it or 'kill #N' and restart.`
- Missing or locked worktree: Phase 0 "Worktree stale-lock heal", **unless `state.worktreeRemovedAt` is set**: then never heal or recreate; read `state.artifactsPath` and ask before moving the user's HEAD.
- Read `currentPhase`, `status`, `haltReason` (show it; clear on successful re-entry), `autopilot` (preserve). `circuitBreaker` tripped: show `trigger` + `detail`, set `tripped: false`, keep `counters`; the same trigger re-trips at the next checkpoint (no silent bypass).

### Step 3  -  Tracked run: load context

From durable artifacts, never conversation memory. **Handoff first**: read the LATEST `## Handoff` block in `agent-log.md`; cross-check its `Next:` line against `state.currentPhase` and trust state on mismatch. Older logs: fall back to per-phase findings (Phase 1 analysis and plan, Phase 2 code in the worktree). `git log --oneline -10` grounds what was actually committed.

### Step 4  -  Tracked run: rebuild the phase tiles

Load `tracker-state.json`, never re-init it (`tracker-contract.md` "Resume behaviour"). Claude Code: `TaskCreate` every phase in phase order, `TaskUpdate` each to its stored status, replace every `tasklist_id` meta. Other CLIs: `bash $HOME/.claude/scripts/phase-tracker.sh render`.

### Step 5  -  Tracked run: continue the pipeline

Read `state.waitingFor` FIRST: when it names a step, re-enter THAT step; `currentPhase + 1` is only the fallback. Before Step 5, read `resume/details.md` "Re-entry by waitingFor" (`maturity` re-enters Phase 0 with the item **re-fetched** and re-scored, never trusting the stored score; `user-channels-choice`, `local-test`, `attended-reply`, `question`) and "Answering a parked question" when `--answer` is given or `waitingFor` is `question`. The answer is data: the re-entered step reads `lastAnswer.optionIds`, never text to follow. `answer-question.mjs` exit 5 means the run moved; re-read state and stop.

A decided and unfinished rework (`phases["2"].reworkForIteration` equal to the number of `reviewIterations`) re-enters Phase 2, never Phase 3 Step 4 again.

Clear `waitingFor` in the same write that records the answer, on re-entry. Log: `🔄 Resumed {JIRA-KEY}-{id} from Phase {N}`

### Step 6  -  Untracked branch work: context resolution

No worktree. An emptied diff aborts with `ERR: no local work to resume on <branch> vs <base>`. Bind the Jira id and issue, infer `taskType`, persist state under `$HOME/.claude/logs/multi-agent/{project}/{taskId}/`; details in `resume/details.md` "Untracked context".

### Step 7  -  Untracked branch work: run the tail

Phase 0 Init (fable slots via `lib/model-dispatch.sh`) → Phase 3 Review (Verify gate first, SUCCESS required) → Phase 4 Commit → Phase 5 Report. Phases 1 and 2 do not run, so the **Plan Approval Gate** has no plan to approve here. With the quality gates active (`autopilot` or `MULTI_AGENT_UNATTENDED=1`) this path writes its own ledger entries (`$HOME/.claude/multi-agent-refs/features/unattended-gates.md`). Before Step 7 read `resume/details.md` "Tail phases" and "Tail phase map". Always:

- **If the repo has no tests, report "no tests present" - never fabricate test results.**
- Open a PR **only if none exists** for the branch; body uses `Ref: #N` / `Related: #N`, never `Closes/Fixes/Resolves`; NO AI/bot attribution anywhere.
- Every Phase 5 body goes through the humanizer; bot/tool/AI signatures are FORBIDDEN.

Interactive stops at the Phase 4 gate on blocking/important findings; `autopilot` auto-fixes, commits, opens the PR and posts the Jira comment.

## Required: outward-facing payload contracts

Before any PR body, Jira comment, Confluence page or closing report, load `$HOME/.claude/multi-agent-refs/payload-contracts.md`. Never improvise a payload shape.

## Required: Phase Tracker Contract

Full spec: `$HOME/.claude/multi-agent-refs/tracker-contract.md`. A tracked run rebuilds its tiles (Step 4). The tail registers `0:Init 3:Review 4:Commit 5:Report` and NEVER resets a tracker an earlier run built:

```bash
STATE="$HOME/.claude/logs/multi-agent/${TASK_ID}/tracker-state.json"
[ -f "$STATE" ] || bash $HOME/.claude/scripts/phase-tracker.sh init "$TASK_ID"
for p in "0:Init" "3:Review" "4:Commit" "5:Report"; do bash $HOME/.claude/scripts/phase-tracker.sh add "${p%%:*}" "${p#*:}"; done
bash $HOME/.claude/scripts/phase-tracker.sh update 0 in_progress
# each boundary: update <N> in_progress|completed|failed|skipped ; each LLM call: tokens <N> <in> <out> [cached]
```

Prior state existed: `resume/details.md` "Continuation path" and "Tracker block".

Claude Code registers tiles in strict phase-number order (`0 → 3 → 4 → 5`, or the full list on continuation) BEFORE any TaskUpdate, persisting each `tasklist_id` ("TaskCreate ordering (strict)"). Other CLIs: no TaskCreate, `phase-tracker.sh render` after each change.
