agent-cli-worktree-safety

agent-cli-worktree-safety is a skill for Claude Code from laurigates/claude-plugins. It costs 53 tokens per session (2,128 once invoked), scanned A, original, MIT.

A safety guide for command-line tools that run an AI agent inside a temporary Git worktree, which is a separate working copy of a repository. It defines checks that prevent written files from being lost during cleanup.

In plain words
What is it for?
Use it when building or reviewing an agent CLI that creates and removes worktrees, especially when a run writes files but reports that nothing changed.
Why use it?
It addresses a failure where the tool reports no changes because it only checks commits, then force-deletes a worktree containing uncommitted files.

Skill for Claude Code

Written for Claude Code: allowed-tools in frontmatter. Also seen: model in frontmatter; mentions subagents; names the AskUserQuestion tool.

Part of the agent-patterns-plugin plugin — 26 skills shipped together

Good fit Use it when building or reviewing an agent CLI that creates and removes worktrees, especially when a run writes files but reports that nothing changed.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/laurigates/claude-plugins/agent-cli-worktree-safety
Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

Any agent
npx skills add laurigates/claude-plugins --skill agent-cli-worktree-safety
Clone the repo
git clone --depth 1 https://github.com/laurigates/claude-plugins

Made for: Claude Code.

Or install agent-patterns-plugin, the plugin that ships this one along with the rest of its 26 skills.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for agent-cli-worktree-safety

README.md
[![agentmods](https://agentmods.dev/badge/skills/laurigates/claude-plugins/agent-cli-worktree-safety/github.svg)](https://agentmods.dev/skills/laurigates/claude-plugins/agent-cli-worktree-safety)
Your own site
<a href="https://agentmods.dev/skills/laurigates/claude-plugins/agent-cli-worktree-safety"><img src="https://agentmods.dev/badge/skills/laurigates/claude-plugins/agent-cli-worktree-safety/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for agent-cli-worktree-safety

Your own site · 80×15
<a href="https://agentmods.dev/skills/laurigates/claude-plugins/agent-cli-worktree-safety"><img src="https://agentmods.dev/badge/skills/laurigates/claude-plugins/agent-cli-worktree-safety.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 53 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 2,128 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 1 finding. A grade says what 26 rules found in the file — not that it is safe. Third-party audits
  • NVIDIA SkillSpector warn 7 Sept 2026
SkillSpector: 1 finding, up to medium

These are SkillSpector’s own severities. On a checked sample its high-severity flags on skills were ~96% false positives — a documented command, a public API, a “never do X” rule — so we show them as a caution to read, not a verdict. Why →

  • medium Excessive Agency · line 8
    Skill selects an external model or provider that may use a different account or billing plan than the operator expects. Undisclosed model switches can cause unexpected cost or quota consumption.
    Fix: Remove the model/provider override or disclose it prominently and require explicit operator approval before invoking an external coding CLI or billed model.
How audits are shown
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00053 $0.02128
Opus 5.5 $0.00021 $0.00851
Sonnet 5.5 $0.00011 $0.00426
Haiku 4.5 $0.00005 $0.00213

Measured 16d ago against content hash c31d61587c78, method: parsed. Prices are Anthropic first-party input rates as of 2026-10-07, from the pricing page.

Security

Grade A, and why

agent-cli-worktree-safety scanned grade A with 1 finding against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 16d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Runs shell commandslowCapability

Expected in a hook, worth knowing in a rule or an instructions file.

commits = subprocess.run(
agent-patterns-plugin/skills/agent-cli-worktree-safety/SKILL.md · 190 lines

How it starts

The opening of the file, as written. The whole thing — 190 lines — stays where its author put it; the contents beside it link to each section on GitHub.

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.

When to Use This Skill

Use this skill when... Use something else when...
Building or reviewing a CLI that runs an agent SDK in a worktree it later removes Isolating a Claude Code subagent with isolation: "worktree" → .claude/rules/agent-runtime.md § Worktree Isolation
An agent run wrote files but reported "No changes were made" Pruning other sessions' worktrees → .claude/rules/agent-coworker-detection.md § Cleanup
Wiring the SDK's two-phase or create_worktree flow → REFERENCE.md Coordinating parallel agents → agent-patterns-plugin:agent-teams

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:

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 True
    dirty = subprocess.run(
        ["git", "status", "--porcelain"],
        cwd=worktree_path, capture_output=True, text=True,
    )
    return bool(dirty.stdout.strip())

Read the full file on GitHub · 190 lines

Files

What ships with it

1 file beside SKILL.md in the same directory: the scripts, references and assets a skill reads on demand. Not counted in the per-session cost; read them before you install if any of them is executable.

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 16d ago Changed c31d61587c78
  2. 1mo ago Changed · +12 lines bedb90bf0045
  3. 2mo ago First seen · 178 lines · 53 tokens per session scan A 2d5e9c11023b

Subscribe to this mod's changes

agent-cli-worktree-safety is a skill published in the GitHub repository laurigates/claude-plugins (60 stars, last pushed yesterday), licensed MIT. It adds 53 tokens to every session and 2,128 once invoked, about $0.0002 per session on Opus 5.5. A static security scan graded it A with 1 finding (runs shell commands). No closer match exists in the catalogue, so it is treated as the original; first seen 2026-09-03.

Related

agent-cli-worktree-safety compared with skills from other repositories

agent-cli-worktree-safety next to 6 skills from other repositories
ModTypeStarsLast pushLicenceScanTokensWorks with
agent-cli-worktree-safetylaurigates/claude-pluginsSkill60yesterdayMITA53Claude Code
changelog-summarizingshopwareLabs/ai-coding-toolsSkill482d agoMITA106Claude Code
morning-briefmelodic-software/claude-code-pluginsSkill34todayMITA152Claude Code
commit-message-writingshopwareLabs/ai-coding-toolsSkill482d agoMITA160Claude Code
feature-branch-pr-writingshopwareLabs/ai-coding-toolsSkill482d agoMITA152Claude Code
pr-description-writingshopwareLabs/ai-coding-toolsSkill482d agoMITA144Claude Code
mk:resolving-merge-conflictsngocsangyem/MeowKitSkill172d agoMITA24Claude Code