Skip to content
xsyetopz edited this page Oct 19, 2026 · 2 revisions

Patch

This page tells how the core plugin claudetto keeps the work of a subagent in a git worktree when the worktree is lost. A user who runs subagents in worktrees and a contributor who edits the patch slice read it.

What It Does for You

A subagent in a worktree can stop before it commits. A turn limit or a usage limit can stop it, and the removal of its worktree then deletes the work. The slice keeps one cumulative patch for each subagent, so the work stays.

The slice adds three items:

Item Kind What it does
tool.call hook Hook on Edit and Write Writes the patch of the agent after each edit.
claudetto-patch Command in bin/ Lists and lands the patches.
patch Skill Tells Claude how to land a patch and how to continue the work.

The slice has no userConfig key and no setting.

How the Hook Writes a Patch

The hook runs with the phase observe and calls next first, so the edit is done before the patch is written. It acts only when these facts are true:

  • The call comes from a subagent, so the event has an agentId.
  • The edited file is in a linked git worktree.

The main thread and a main checkout write nothing. In a main checkout the git dir is the common dir, and only a linked worktree loses its work with its removal.

The hook then does these steps:

  1. It reads the base commit. The first write of the agent saves HEAD in the file base. Later writes read that file, so a commit of the agent stays in the patch.
  2. It adds all files, with the untracked files, to a temporary index claudetto.index in the git dir of the worktree. The index of the worktree does not change.
  3. It writes the diff of the base against that index, in binary form, to changes.patch.

The files are in the main checkout, in .claudetto/patches/<agentId>/:

File Content
base The base commit.
changes.patch All changes of the agent since the base, with new files and commits.

The patch stays after the worktree is gone.

How to Use It

claudetto-patch list
claudetto-patch land <agentId> [--3way]

list prints one line for each patch: the agent id, the first 8 characters of the base, and the count of files. land applies the patch of one agent to the main checkout. It first runs git apply --check. When the check fails, the command changes no file and prints the error of git. You review the change with git diff and commit it.

With --3way, a patch that does not apply goes in with conflict markers. The command does not resolve a conflict. The user or Claude resolves it by hand.

Code Meaning
0 Done.
1 No patch for the id, a patch that does not apply, a fault of git, or a folder that is not a git repository.
2 A usage fault.

The Skill

Claude runs the skill when a subagent in a worktree stopped, ended, or reported work, and before it removes the worktree. The skill tells Claude to land the patch and to send a patch that does not apply back to an agent for a rebase. To continue the work of a stopped agent, the new agent reads changes.patch first and applies it with git apply in its own worktree.

Bounds

Bound Value Set in
GIT_TIMEOUT_MS 60,000 slices/patch/limits.ts

It is the time that one git run may take, in milliseconds.

Edge Cases

The patch slice keeps the work of a subagent when its git worktree is lost. It saves one patch for each subagent after each edit. You or Claude can then land the patch in the main checkout.

See Also

Clone this wiki locally