recover-agent-work
Skill2 starsChanged 46 days agoMITView on GitHub
Recover the uncommitted work of a background or subagent that died, was rate-limited, crashed, timed out, or was interrupted mid-task, instead of re-running it from scratch. Use when an implementer agent stopped without opening its PR, when you see a rate-limit or crash on a spawned agent, or when a worktree has changes but no commit. The work is almost always still on disk in the agent's worktree.
- Commits and pushes
In this repository7 other files it gives its agents.
- gate-prSkill
- orchestrate-sprintSkill
- orchestrate-ticketSkill
- orchestration-initSkill
- orchestration-reportSkill
- release-integrationSkill
- scope-ticketSkill
The file
We split this skill into the rules it gives an agent
7 rules. About 0 are common, 5 are distinctive, and 2 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈5
Distinctive · estimate
This author's own choices. Worth a look.
2
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 8
When a background agent dies (rate limit, crash, timeout, interruption), its work is not lost.
- Distinctive: line 42
Read the agent's intent: If a transcript or task output for the dead agent is available, read it for how far it got and what its own …
- Distinctive: line 47
Commit from the worktree: Run the commit with the worktree as the working directory, so it lands on the agent's branch:
- Very specific: line 53
Before committing, make the work actually mergeable: run the repo's self_check commands from config in the worktree, and finish anything …
- Very specific: line 67
Do not cd into the main repo and commit there.
- Distinctive: line 69
Do not delete or force-remove the worktree until the work is committed and pushed.
- Distinctive: line 72
Do not restart the ticket from an empty branch when a dirty worktree exists.
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Recover a dead agent's work
When a background agent dies (rate limit, crash, timeout, interruption), its work
is not lost. It is sitting UNCOMMITTED in its git worktree. Cleanup defaults to
manual; even under worktree_cleanup: auto, the explicit cleanup and optional
Stop-hook sweep skip dirty or locked worktrees, precisely so a dead-mid-edit
agent's changes survive for recovery. Do not
re-run the ticket from scratch; recover what is already there.
The key facts
- A finished, clean agent worktree may be swept only under
auto. A dirty one is preserved. So if the agent got far enough to write files, they are still on disk. - Branch refs live in the shared
.git. If the agent committed but did not push, the commit is safe even if the worktree were removed. - The work must be committed from inside the worktree path, not from the main repo checkout. Committing from the wrong working directory is how recovered work gets stranded on the wrong branch or lost again.
Procedure
- Find the worktree. List them and locate the agent's:
Agent worktrees live under the configuredgit worktree listworktree_base(default.claude/worktrees/) with anagent-*name. Match it to the ticket. - See what survived. Inspect the worktree's tree without changing directory
into the main repo:
Uncommitted changes here are the recoverable work.git -C <worktree> status git -C <worktree> diff - Read the agent's intent. If a transcript or task output for the dead agent is available, read it for how far it got and what its own verdict was (tests passing, PR intended, blockers hit). Recover to the state it was aiming for, not a guess.
- Commit from the worktree. Run the commit with the worktree as the working
directory, so it lands on the agent's branch:
Before committing, make the work actually mergeable: run the repo'sgit -C <worktree> add -A git -C <worktree> commit -m "<conventional message referencing the ticket>"self_checkcommands from config in the worktree, and finish anything the agent left half-done. A recovered commit still has to pass the same gates. - Open the PR yourself. Push the branch and open the PR to the configured
target branch role, exactly as the implementer would have:
Then it re-enters the normal pipeline at the gate stage.git -C <worktree> push -u origin HEAD gh pr create --base <configured-target-branch> ...
Do not
- Do not
cdinto the main repo and commit there; the changes are in the worktree, on the agent's branch. - Do not delete or force-remove the worktree until the work is committed and
pushed.
git worktree remove --forceon a dirty worktree discards exactly the work you are trying to save. - Do not restart the ticket from an empty branch when a dirty worktree exists; that duplicates effort and risks two branches for one ticket.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

