Git worktree isolation per thread
Skill kjuhwa/skills-hub/skills/git/git-worktree-isolation-per-thread
Self-correcting knowledge corpus for Claude Code — 9 stable shape clusters, bias-correction pipeline baked into contribution flow. 47 papers, 45 techniques, 1.1k skills.
npx -y skills add kjuhwa/skills-hub --skill git-worktree-isolation-per-threadAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
One thing to look at
- 0 stars0 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.
What its author says it does
Copied from the file, not written here
Use git worktrees to isolate filesystem state per conversation thread, avoiding conflicts between concurrent edits
SKILL.md
2.3 KB, 409 tokens by cl100k_base, as published. Nobody here has run it
When to Apply
- You manage multiple long-running agent threads in the same repository
- Threads may edit overlapping files concurrently without blocking each other
- You want to capture "turn diffs" per thread without conflict resolution complexity
- You need to snapshot state at checkpoint boundaries and restore old states
Steps
- On thread creation, check if thread should use a worktree (e.g.,
worktreePathin thread contracts) - Create a git worktree:
git worktree add <path> <branch> - Worktree path is stored in thread state; all thread operations (git, filesystem) use that path
- On turn start, capture a checkpoint: save current HEAD as a git ref (hidden, prefixed)
- After turn completes, compute diff between checkpoint and current HEAD
- On thread delete or reset, clean up worktree:
git worktree remove <path> --force - Optionally, dedupe worktrees: if two threads reference same commit, share a worktree
Example
// Thread creation
const worktreePath = `${workspaceRoot}/.worktrees/${threadId}`
yield* GitCore.createWorktree({ path: worktreePath, ref: 'main' })
thread.worktreePath = worktreePath
// Turn checkpoint
const checkpointRef = `refs/hidden/checkpoint/${threadId}/${turnId}`
yield* GitCore.updateRef(checkpointRef, 'HEAD')
// Turn diff
const diff = yield* GitCore.getDiff(checkpointRef, 'HEAD', { path: worktreePath })
Counter / Caveats
- Worktrees consume disk space; each is a separate
.gitdirectory - If worktree is deleted externally, git state is orphaned; add cleanup in startup readiness
- Worktree can diverge from main tree; branch consistency is caller's responsibility
- On Windows, worktree paths must not conflict with symlinks in main tree
What ships with it
Read from the repository
Just SKILL.md. No reference files, no scripts.