Recover the sub-agents of this session that died at an API usage limit (or the auth error a limit hit cascades into) — detect them from their transcripts, decide per agent between resuming it and seating a FRESH agent over a digest of its work, dispatch, and record what was done so the detector stops naming them. Auto-directed by the UserPromptSubmit hook whenever an unrecovered death exists; owner-invoked as `/limit-recovery` after a limit reset or a re-login. Use when a limit, a logout or a...
Installs into .claude/skills of the current project.
Sponsors
SSkills DirectorySkills Directory
Know which skills are safe — weekly.
SSkills DirectorySkills Directory
Is that skill safe to install?
Are you the author of Limit Recovery?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/brkomir-limit-recovery)
---
name: limit-recovery
description: Recover the sub-agents of this session that died at an API usage limit (or the auth error a limit hit cascades into) — detect them from their transcripts, decide per agent between resuming it and seating a FRESH agent over a digest of its work, dispatch, and record what was done so the detector stops naming them. Auto-directed by the UserPromptSubmit hook whenever an unrecovered death exists; owner-invoked as `/limit-recovery` after a limit reset or a re-login. Use when a limit, a logout or a revoked token stopped background agents mid-work.
---
# /limit-recovery — take over the work of agents that died at a usage limit
The procedure: a death at a limit is detected automatically, and when the session resumes the dead work is picked up from the point where it left off. A RESUME is the rule; a fresh seat over a digest of the dead agent's transcript follows only a model change, a failed resume, a context that no longer fits, or a Fable agent at Fable's own limit (on Opus, at once), and a death at any other model's own limit waits for that limit's reset. It began the other way round (a cold seat with a large context was replaced rather than resumed, because a resume re-writes its whole cache); the measurement below reversed that. The founding run: four of ten readers died within five minutes (two at the session limit, one at the Fable limit, one on a revoked token); 9-14 minutes later, cold and at 2.4-4.4 MB each, four fresh readers took over from digests of their transcripts.
**Marker:** `[limit-recovery]`. **Writes:** the digest files (scratchpad), `.claude/state/limit-recovery-<sid8>.json` (what was handled), the working plan. Never a commit, never a push, never a tracker edit. Under a `/pause` it still DISPATCHES — the owner's recovery order is the resume signal for the dead work, and a fresh seat reading a digest is the paused builder's own continuation, not new work — and says so in the readout.
## The instrument — `scripts/limit-recovery.py`
```bash
python3 scripts/limit-recovery.py scan [--sid SID] [--json] [--all] # the unrecovered deaths, one decision each
python3 scripts/limit-recovery.py digest <agent-id> --out <path> # the takeover digest for one dead agent
python3 scripts/limit-recovery.py mark <agent-id>... --as fresh|dropped|resumed [--note TEXT]
python3 scripts/limit-recovery.py --self-test
```
A death is a transcript (`~/.claude/projects/<key>/<sid>/subagents/agent-<id>.jsonl`) whose LAST assistant record carries `isApiErrorMessage` and no `SubagentHandback` tool_use anywhere. `.claude/hooks/limit-recovery-check.sh` (UserPromptSubmit, warn-mode) runs `scan --hook` on every prompt and names what is unrecovered; a resume self-clears (new records land after the error), a fresh seat or a drop is recorded by `mark`. **The detector has a start, `DETECTION_EPOCH` (set in the script):** a death before it is not named, because it was handled by hand or not at all and nothing records which; `scan --all` lists those too, flagged `pre-epoch`, for a seat that wants to look. Without the cutoff the hook named every old death on every prompt of every session that had one, fleet-wide, the hour it went live. The scan row carries what the decision reads: the cache age against `CACHE_WARM_MINUTES` (the sub-agent prompt-cache window, the same figure `review-hub/references/pause-and-limits.md` § Near the 5-hour limit keys on), the context the dead agent's last live call recorded (reported, never decisive), the model it last ran on, the model its dispatch named (`dispatched`, from its meta.json) and its definition's pin (`pinned`), the session's current model (`session_model()`: the newest real model in the session's own transcript), whether the death was that model's own limit, and whether an earlier resume failed.
**The resume rule: always resume, except for a model change or a failed resume.** It replaced a room rule (resume a cold agent unless it sat within 300,000 tokens of its compaction point), which had replaced an earlier rule that a cold agent with 400k+ of context is cheaper to replace than to resume. The room line went because all four measured fresh takers ended LARGER than the agent they replaced (378k → 486k, 714k → 719k, 450k → 487k, 399k → 450k; all eight on Fable 5.1 at effort high), so a fresh seat buys no room, only cost. The cost measurement: two live cold resumes each rewrote the agent's whole context once and read none; the four fresh readers that had taken over dead ones spent 1.75-2.2 cost units per token of their predecessor's context re-reading their way back, against 1.25 for the rewrite, so a resume came out roughly 30-45% cheaper at a 0.1 cache-read weight (a write at 1.25; per token the dead agent carried, about 10-45%; at a 0.05 read weight, the read price recorded for Opus 5.5, about 17-34% per token of the predecessor's context and from about break-even to a third per token the dead agent carried; the subscription meter's weights are unmeasured). Quality was not compared. **A resume runs on the model the Agent call named, if it named one; else on the model the agent's definition pins, if it pins one; else on the model the session runs now.** The second and third were measured live (a Sonnet-pinned expert in an Opus session answered on Sonnet before and after a resume; an unpinned Fable 5.1 reader, dispatched with no model (its meta.json carries no `model` field), came back on Opus 5.5). The first was read from older transcripts on this machine, not run live: two security seats dispatched on Fable, whose definition then pinned opus, died at the session limit and were resumed while their session ran Opus (every session reply that hour), and both resumed answers came back on Fable 5.1, so the dispatch's model won over both the pin and the session. The harness records the dispatch's model in each agent's meta.json, which matched the first answering model in 13,604 of the 13,606 helpers compared; `scan` reads it as the row's `dispatched`. That is why a model change is an exception: `scan` compares the agent's model with the dispatch's, else the pin, else the session's model.
**A death at a logout is never a failed resume:** a logout happens during an account switch while the agent is running. Neither is a death again at a limit or on a server-side transient, an overload or a 500: dying of those says nothing about whether the resume works; each resumes after the re-login, the reset or the overload. **The model-limit rule:** when a helper on Opus hits a limit, there is no other model with room, so it waits for the reset; when a helper on Fable hits Fable's own weekly limit, which is not a session limit, it moves straight to Opus. So an Opus agent at its own limit is the WAIT row below, and a Fable agent at Fable's own limit is FRESH on Opus at once, with no word from the owner needed; `MODEL_LIMIT_MOVES` in the script is the one place that rule lives. A death at the session limit is never a model limit, so it resumes after the reset as before. The other cases where a resume cannot work: a context that no longer fits (measured: 6 helper deaths on this machine ended "Prompt is too long", all on 200,000-token windows, none ever made a live call again, and in 4 of them the system prompt and tools alone overflowed, so for those a fresh seat on the same model fails too); a resume whose `SendMessage` errors, or that dies again before any live call on an error other than a limit, a logout or a transient (the failed-resume row); and a model no longer offered to the account at all (below the table; no such error has been measured, so `scan` does not detect it).
## The decision table — read it off `scan`, never re-derive it by hand
| row | condition | action |
|---|---|---|
| BANKED | a `SubagentHandback` exists in the transcript | the work came back before the error: collect the hand-back (the pause spec's banking rules), nothing to recover. Measured once: 3 of 3 slices that "looked failed" at a limit had handed back seconds before it |
| RESUME | every other death, warm or cold, at any size (an agent that ran on the model its dispatch named, or on its pin, included: its resume runs on that model) | `SendMessage` to the agent id: HEAD now, how its files read, "continue from your last line, hand back per the original brief", and the word `RESUME-OK` (`subagent-resume-guard.py` refuses a send to a helper idle past 4 minutes without it, which is every death this table resumes after a limit). Warm, it pays only the increment; cold, it rewrites the cache once and keeps the agent's own work, cheaper than a fresh seat re-reading it |
| RESUME, SESSION MODEL UNREAD | the session's model could not be read and the agent's was (with neither read, the row is a plain RESUME) | resume only after confirming the session runs the agent's model; if it does not, treat the row as FRESH on that model |
| WAIT | it died at its OWN model's limit, on any model but Fable (an Opus wording such as "You have used your Opus weekly limit" is a self-test fixture, not a measured text; `classify_error` reads it as api-error and `_model_limit` still flags it) | it cannot run on that model until that limit resets; on Opus no other model has room for it, and on any other model only Fable moves: do not resume it now. After the reset, resume it if a resume runs on that model (its dispatch named it; else its definition pins it; else the session runs it), otherwise the takeover below ON THAT MODEL; the row's reason names which |
| FRESH | a Fable agent died at Fable's OWN limit ("You've reached your Fable limit"), a weekly limit and never the session one | it moves at once, no word from the owner needed: the takeover below ON OPUS AT `effort: "xhigh"`, whatever the agent's dispatch named and whatever the session runs, in a session running at `/effort max` too: it still moves at once, at xhigh, and its report names that the session runs at max; and before any later Fable-routed dispatch in the session, read `fable_week_pct` in the status-line file, since an account switch can free Fable without anyone saying so |
| FRESH | its context does not fit ("Prompt is too long") | a resume re-sends the same context and fails the same way, and a fresh seat on the same model carries the same system prompt and tools: the takeover below ON A MODEL WITH A LARGER CONTEXT WINDOW |
| FRESH | the agent ran on a model a resume would not run on (its dispatch named another; or, none named, its definition pins another; or, neither, the session no longer runs it) | `digest` → dispatch a fresh agent of the SAME type ON THE AGENT'S MODEL (brief below) → `mark --as fresh` |
| FRESH | marked `resumed` for an earlier death, no live model call since, and the new death is not a limit, a logout or a server-side transient (those resume again after the reset, the re-login or the overload; above) | the resume failed: same takeover as above, ON THE AGENT'S MODEL |
If the model the agent ran on is no longer offered to the account at all (a resume or a dispatch on it errors naming the model), there is no reset to wait for: seat the takeover on a model the account has, and tell the owner in one line. Neither is a reason for a fresh seat: absence from `ListAgents`, or a cold cache.
⛔ A `ListAgents` row is not the test for any row — a dead agent is absent from it and still resumable; the `SendMessage` result is the test (conventions, the limit-reset row). ⛔ Never resume a FRESH row, or a WAIT row before its model's limit resets: a resume would finish it on another model, fail the same way, or run on a model at its limit. After that reset a WAIT row still reads WAIT (`scan` reads no clock; its reason quotes the error, which names the reset): do what its reason says for after the reset. Size is never a reason to start fresh: a fresh seat re-reads its way back to the same size (measured above), so a job too big to finish before compaction compacts either way.
## Process
0. **One line to the owner** — how many died, at what, the split the table gives — then act; the recovery is not a question (above 90% of the five-hour session limit the line also names what is held: § Boundaries).
1. **`scan`.** For each row read the action AND its reason (the numbers: age, context, tool calls, the two models). The scan skips ids already marked and deaths before `DETECTION_EPOCH`; `--all` shows both, with their mark or the `pre-epoch` flag.
2. **BANKED rows:** bank the hand-back as the pause spec says (record it, take no action on its content here).
3. **RESUME rows: `mark <id> --as resumed` FIRST, then `SendMessage`** — except a row held above 90% of the five-hour session limit, which gets neither. Above 90%, settle the held rows from step 1's scan before marking anything: a RESUME row whose reason says the cache is cold is held while 10 or more OTHER rows are to be resumed now — the rows that read RESUME, plus any WAIT row past its reset that this run resumes (step 3a; the guard cannot see that one, since `scan` reads no clock); a FRESH or BANKED row, or a WAIT row before its reset, does not count (§ Boundaries). Name each held row in step 0's line and resume it after the five-hour reset, or now if the owner orders it (`OWNER-ORDERED:` in the message). A held row is not a WAIT row: a WAIT row waits for its own model's reset (step 3a), a held row for the session's. Never mark a held row: a mark written for a resume the guard then denies hides that death from `scan` and the hook (only `scan --all` lists it), and nothing names it after the reset. A `SendMessage` the guard denies is a hold, not a failed resume: never take it to step 4; if that row was already marked, note it in the working plan and resume it after the reset. That is `agent-dispatch-session-limit-guard.py` (it names `OWNER-ORDERED`); a deny from `subagent-resume-guard.py` (it names `RESUME-OK`) is neither a hold nor a failed resume: the message lacked the marker, so re-send it with `RESUME-OK` now. `mark` records the transcript's last death, and while the agent is dead that is exactly the death the scan showed; written after the resume, it could record a re-death the resume had already produced and hide it. Then `SendMessage` to the agent id with the resume message (the RESUME row's, `RESUME-OK` in it); if the result is an error, the seat is gone — treat the row as FRESH (step 4), whose own mark replaces this one. A resume that makes live calls clears the detector by itself. A mark covers the death it was written for, so if the same agent dies again the hook names it again: after a live call, or at a limit, a logout or a transient, it is resumed again (after the reset); on any other error with no live call since the marked death, the scan reads the resume as failed and the row is FRESH. `mark` refuses an agent whose transcript does not end in a death (exit 1, nothing written), since a mark with no death to cover would hide every later one.
3a. **WAIT rows:** nothing now, neither a resume nor a fresh seat; step 0's line names each with the reset its error gives (the reason quotes the error). The row reads WAIT until it is marked, so the seat watches the clock, not the table: once that reset has passed, do the reason's "After the reset" step (a resume is step 3, a fresh seat ON that model step 4). There is no other model to move it to; a Fable agent at Fable's own limit never reaches this step, its row is FRESH on Opus (step 4).
4. **FRESH rows — first check what the dead seat already persisted** (a takeover assumes the dead seat reached no verdict; in the founding run one of four had written its full report). If the digest's last Write calls show the deliverable the ORIGINAL BRIEF names already on disk and whole, read it instead and `mark <id> --as dropped --note "deliverable on disk: <path>"`. **Otherwise, the takeover brief.** `digest <id> --out <scratchpad>/<topic>-dead/<name>.txt`, then dispatch the same agent type, `run_in_background`, with a brief that says: (a) read the digest whole FIRST — its "ORIGINAL BRIEF" section is the predecessor's brief verbatim and binds the taker-over in full; (b) the predecessor's reads are NOT in its context, so it re-reads what it needs, and uses the digest only to reopen scratch files the predecessor already wrote and to see where it died; (c) it never adopts an unfinished conclusion of the predecessor as a verdict — every finding rests on text it read itself; (d) it returns exactly what the original brief asked, plus one line naming which predecessor scratch files it reused. Then `mark <id> --as fresh --note "<what was dispatched>"`. At most 12 agents in flight, as always.
5. **Record:** one dated block in the working plan (which seats died, at what, the row each took, where the digests are; agent ids only in the scratchpad), and the builders file if a pause is on.
6. **Readout, in the owner's register:** what died and why, what was resumed, what was re-seated fresh, what came back banked, what waits for which model's reset, what the fresh seats will hand back, and that nothing was committed. No agent ids.
## Boundaries
- **Not `/pause resume`:** that is the owner's resume of PAUSED work; this recovers DEAD work and runs inside either state. A paused seat still dispatches here because the recovery order is the owner's.
- **Not a crash detector:** a seat that died with no API-error record (a killed process, a stream stall) ends like a live tool call, so the scan cannot name it; the task notification is its only signal.
- **Not a retry loop:** a seat that dies again at the same limit, at a logout or on an overload is left dead until the reset, the re-login or the overload clears, then resumed again; it is never a failed resume (above). The hook keeps naming it, which is the point.
- **Agent ids never reach the owner or a committed file** — the state file is gitignored, the digests live in the scratchpad, the plan block names the work by its description.
- **The rule:** always resume, except a model change or a failed resume, and the agent's own model at its limit (an Opus agent waits for the reset, a Fable agent at Fable's own limit is FRESH on Opus at once). A context that no longer fits is FRESH on a model with a larger window. A change to any of it is the owner's ruling and a `/meta` edit, never a per-run judgment.
- **Above 90% of the five-hour session limit:** a RESUME goes ahead when the helper's cache is warm or it is not one of a batch (fewer than 10 other helpers to be resumed now: the guard counts the other rows the scan reads RESUME, since a WAIT or FRESH row is not resumed now; the 10 is `BATCH_OTHERS`, read literally, the owner's to move); a cold resume in a batch is held, neither marked nor sent (step 3), until the five-hour reset, and `agent-dispatch-session-limit-guard.py` denies its `SendMessage` (matched to the dead helper by id, off this tool's scan) unless the message carries `OWNER-ORDERED: <the owner's words>`. A FRESH row's dispatch is a new launch, which the same guard denies unless the prompt carries that line. Whether the owner's typing `/limit-recovery` is itself such an order is not settled: name the held helpers in step 0's line and ask.
## Revisit
- If a fresh takeover ever finishes clearly SMALLER than the agent it replaced, that is the evidence the dropped room line lacked: bring it to the owner. If a FRESH taker-over ever reported the digest insufficient, add the predecessor's last N tool RESULTS to the digest.
- If the hook ever names a death the seat had already handled by hand without `mark`, the mark is the missing habit, not the detector.
- The model check reads the session's model from the last 64 KB of its transcript, and once more from the last 4 MB (`SESSION_TAIL_MAX_BYTES`) when those 64 KB hold no reply (a SessionStart injection alone can exceed them); if a run still shows SESSION MODEL UNREAD on a session that plainly had a model, widen that read again before trusting the exception.
- The first live RESUME row: confirm the hook stops naming the agent once its resumed reply lands. The self-clear assumes a resume appends to the same transcript, and no RESUME had run live when this shipped; step 3 marks before the resume, so a resume that does not clear is already covered by its mark.
- A model no longer offered to the account is stated below the table, not detected: the first resume or dispatch whose error names a model as unavailable, add that error's shape to `scan` as its own row.
- WAIT reads no clock. The first WAIT row read after its reset by a seat that did not resume it: parse the reset time out of the error so `scan` itself turns WAIT into the after-reset step.
- `MODEL_LIMIT_MOVES = {"fable": "opus"}` is the model-limit rule (above). Another family joins the mapping only on the owner's word. Its carriers, to change together: this file's opening paragraph, table, model-limit paragraph, step 3a and § Boundaries' rule line, the conventions row (both of its own-limit clauses) and its index line, `limit-recovery-check.sh`'s header, architecture.md, `/pause` step 4 and `review-hub/references/pause-and-limits.md` § Near the 5-hour limit, rule 1.