agentsclimarketplace

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.

Install
npx -y skills add kjuhwa/skills-hub --skill git-worktree-isolation-per-thread

Assembled 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

  1. On thread creation, check if thread should use a worktree (e.g., worktreePath in thread contracts)
  2. Create a git worktree: git worktree add <path> <branch>
  3. Worktree path is stored in thread state; all thread operations (git, filesystem) use that path
  4. On turn start, capture a checkpoint: save current HEAD as a git ref (hidden, prefixed)
  5. After turn completes, compute diff between checkpoint and current HEAD
  6. On thread delete or reset, clean up worktree: git worktree remove <path> --force
  7. 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 .git directory
  • 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.

Keep looking

Skills are one crate of 328,083. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.