Agent skill · laurigates

agent-cli-worktree-safety

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.

What it needs

About 4k tokens when loaded.

What this skill does

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: A commits-only check is a data-loss bug. --porcelain (not git diff) is load-bearing: a brand-new file the agent created is untracked, and git diff cannot see it. If uncommitted files matter for the next operation — push, PR, cleanup — they matter for this check. 2. Safety-net commit before any destructive cleanup If the agent phase was supposed to commit and didn't, capture the work anyway: Call it from every post-run path — interactive and non-interactive — with a message naming the workflow, and print a warning so the user learns the safety net fired. A silent safety net hides the bug it is compensating for. 3. Pre-validate before git touches the path Typer's exists=True, dirokay=True is not enough. …

How to use it

Reference it in AdaL, Claude Code, Cursor or any coding agent — nothing to install:

@skills laurigates/agent-cli-worktree-safety

View the source on GitHub

Browse the @skills marketplace