agent-cli-worktree-safety

Solid

Data-loss invariants for a CLI that runs an agent SDK in a git worktree then force-removes it. Use when building or reviewing such a CLI, or when an agent run reports "no changes" after writing files.

Data & Documents 58 stars 6 forks Updated today MIT

Install

View on GitHub

Quality Score: 81/100

Stars 20%
59
Recency 20%
100
Frontmatter 20%
70
Documentation 15%
100
Issue Health 10%
50
License 10%
100
Description 5%
100

Skill Content

# Agent-CLI Worktree Safety Data-loss prevention for CLIs that create a git worktree, run an LLM orchestrator (`claude-agent-sdk` or similar) that writes files there, and then clean up with `git worktree remove --force`. ## The core failure mode Three independent mistakes compound into silent data loss: 1. **Driver phases write but never commit** — "the outer orchestrator handles git state". 2. **The outer orchestrator ends without committing** — it stalls on an interactive tool call that cannot render (see *Interactive tools in SDK subprocess mode* below), or simply finishes. 3. **The "has changes" check only counts commits** (`git log base..HEAD`), so it reports nothing to preserve — and cleanup force-removes the worktree. Net result: many files are written, the user is told **"No changes were made"**, and the work is destroyed. No error, no traceback. That user-visible message is the diagnostic tell — if a run wrote files and reported no changes, check invariant 1 before anything else. ## Required invariants ### 1. "Has changes" means commits OR a dirty tree Any function deciding whether a worktree is worth preserving must return true when the working tree is dirty, even with no commits beyond base: ```python def worktree_has_changes(worktree_path, base_branch): commits = subprocess.run( ["git", "log", "--oneline", f"{base_branch}..HEAD"], cwd=worktree_path, capture_output=True, text=True, ) if commits.stdout.strip(): return Tru...

Details

Author
laurigates
Repository
laurigates/claude-plugins
Created
8 months ago
Last Updated
today
Language
Shell
License
MIT

Similar Skills

Semantically similar based on skill content — not just same category