Agent skill

Worktree Cleanup

by vchelaru in vchelaru/FlatRedBall

Remove a subagent's .claude/worktrees/agent-<id dir after its PR merges.

MITAuto-check passedDevelopment

Install Worktree Cleanup

skills CLI
$ npx skills add vchelaru/FlatRedBall --skill worktree-cleanup -a claude-code

Project install by default; add -g for ~/.claude/skills/.

GitHub CLI
$ gh skill install vchelaru/FlatRedBall worktree-cleanup --agent claude-code

Project scope by default; add --scope user for a personal install. Needs GitHub CLI 2.90.0 or later (public preview).

Manual copy
$ git clone --depth 1 https://github.com/vchelaru/FlatRedBall.git skills-src && mkdir -p .claude/skills && cp -r skills-src/.claude/skills/worktree-cleanup .claude/skills/worktree-cleanup && rm -rf skills-src

Use ~/.claude/skills/ instead of .claude/skills for a personal install. The folder must contain SKILL.md.

Claude Code skills documentation · loads skills from .claude/skills/

Facts

Skill name
worktree-cleanup
GitHub stars
578
Token cost
~810 tokens
SKILL.md length
444 words
Files
1
Skills in repo
32
Repo updated
First seen
Licence
MIT

At a glance

Remove a subagent's .claude/worktrees/agent-<id dir after its PR merges.

  • Works in 5 steps: Confirm Bash cwd is NOT inside the… → git worktree remove --force… → If the directory still exists on disk,… → …
  • Tasks that involve Git worktrees
  • Calls git and dotnet

What it does

Worktree Cleanup is an agent skill from vchelaru/FlatRedBall. Remove a subagent's .claude/worktrees/agent-<id dir after its PR merges. Triggers: git worktree remove, "Permission denied"/"Device or resource busy" on worktree cleanup, Windows file locks on bin/obj.

Its SKILL.md is about 810 tokens, which your agent loads only when the skill is triggered. It is a single SKILL.md file with no bundled scripts.

It sits in Development, covering Git worktrees. It works with Git, Bash and .NET. The repository describes itself as: Cross-platform 2D game engine focused on ultimate productivity built in .NET. The licence is MIT.

When your agent uses it

  • Tasks that involve Git worktrees

Example prompts

  • “Permission denied”
  • “Device or resource busy”
  • “/worktree-cleanup”

Workflow steps

5 steps, taken from the first numbered list in SKILL.md.

  1. Confirm Bash cwd is NOT inside the worktree (pwd); cd out first if it is.
  2. git worktree remove --force .claude/worktrees/agent- — clears git's bookkeeping even when the underlying rm fails. Check git worktree list…
  3. If the directory still exists on disk, dotnet build-server shutdown (releases MSBuild/Roslyn server handles), then retry deletion.
  4. If it still won't delete, switch tools: PowerShell's Remove-Item -Recurse -Force "" succeeds where bash rm -rf reports "Device or resource…
  5. git worktree prune -v, then verify: git worktree list (entry absent) and list the .claude/worktrees/ dir (no leftover folder).

What it can do on your machine

Read from SKILL.md and the folder at commit fa654ab. It shows what the files ask for, not the result of running them.

  • Tool permissions

    Pre-approves nothing: there is no allowed-tools line, so your agent's usual permission prompts apply.

    From allowed-tools in the SKILL.md frontmatter.

  • Runs code

    Shell commands in SKILL.md call:

    • git
    • dotnet

    From the folder's file list and the shell code blocks in SKILL.md.

  • Network

    No URLs in SKILL.md. Its commands use git, which can reach the network depending on how they are called.

    From URLs in SKILL.md, links to its own repository left out.

  • Credentials

    Names no API keys, tokens, secrets or passwords.

    From names ending in _API_KEY, _TOKEN, _SECRET, _KEY or _PASSWORD in SKILL.md.

Context cost

Worktree Cleanup loads about 810 tokens when it runs. Until then it costs about 55 tokens; SKILL.md has 444 words of instructions outside code blocks.

Always · name and description, kept in context so the agent knows when to use it
~55
When it runs · the whole SKILL.md, loaded when a task matches
~810

Estimates: characters ÷ 4, the usual rule of thumb; real counts depend on the model's tokenizer. Scripts and assets cost tokens only if the agent reads them.

Safety

Auto-check passed

The automated check found no risky patterns in SKILL.md.

Automated static check — not a guarantee. Review scripts before installing. It scans the text of SKILL.md for risky patterns (piping downloads into a shell, reading credential files, hidden Unicode, destructive commands); files beside SKILL.md are not scanned.

SKILL.md

The full file from vchelaru/FlatRedBall at commit fa654ab, republished under its MIT licence (© vchelaru). 444 words, ~810 tokens.

Download SKILL.mdSave it as .claude/skills/worktree-cleanup/SKILL.md (or your agent's skills folder).
name
worktree-cleanup
description
Remove a subagent's .claude/worktrees/agent-<id> dir after its PR merges. Triggers: git worktree remove, "Permission denied"/"Device or resource busy" on worktree cleanup, Windows file locks on bin/obj.

Worktree Cleanup (Windows)

The Agent tool's isolation: "worktree" auto-creates .claude/worktrees/agent-<id>/ and auto-removes it if the agent made no changes. Once an agent did change files and its PR has merged, the worktree is orphaned and needs manual cleanup — git worktree remove almost always fails with "Permission denied" on Windows because MSBuild's persistent build server and file watchers hold handles on bin//obj/ for a while after dotnet build/dotnet test exits. Don't bother expecting the plain command to succeed first try.

Landmine — the orchestrator's own Bash cwd is the most common lock. If you ever cd'd the Bash tool into a worktree path (or ran commands there) during the session, that shell holds a directory handle for as long as it stays parked there — rm -rf and even Remove-Item fail against it. Before any removal attempt, run pwd and confirm the Bash cwd is the primary checkout, not the worktree. cding away in a prior tool call doesn't guarantee it stuck — verify, don't assume.

Sequence, run from the primary checkout:

  1. Confirm Bash cwd is NOT inside the worktree (pwd); cd out first if it is.
  2. git worktree remove --force .claude/worktrees/agent-<id> — clears git's bookkeeping even when the underlying rm fails. Check git worktree list to confirm the entry is gone.
  3. If the directory still exists on disk, dotnet build-server shutdown (releases MSBuild/Roslyn server handles), then retry deletion.
  4. If it still won't delete, switch tools: PowerShell's Remove-Item -Recurse -Force "<path>" succeeds where bash rm -rf reports "Device or resource busy" — this is a real, repeatable difference in this environment, not a fluke. Prefer it as the fallback rather than retrying rm.
  5. git worktree prune -v, then verify: git worktree list (entry absent) and list the .claude/worktrees/ dir (no leftover folder).
Show full SKILL.md (153 more words)Show less

If PowerShell's Remove-Item still fails: check for a Visual Studio instance (or its ServiceHub.*.exe/indexer) with that worktree open, or stray dotnet/MSBuild/VBCSCompiler.exe processes beyond what build-server shutdown released — kill or ask the user before force-killing anything unidentified.

Don't trust the agent's self-report of what it created as a workaround. An agent that hit a build dependency needing a specific sibling-directory name may describe its fix as a "symlink/junction," but actually run git worktree add at that path (a second real worktree, invisible in git worktree list under the original name). If git worktree remove on the original leaves a same-named directory elsewhere that a plain rmdir/Remove-Item refuses with "not empty" rather than deleting instantly (reparse points delete instantly regardless of contents), it's a real directory, not a link — check (Get-Item $path).Attributes for ReparsePoint before assuming, and if absent, treat it as an orphaned worktree copy: safe to delete outright once its PR has merged.

© vchelaru, MIT. Rendered from Markdown: HTML in the file is shown as text, images as links, and headings moved down two levels. Raw file

Files

Just SKILL.md in .claude/skills/worktree-cleanup of vchelaru/FlatRedBall.

Open the folder on GitHubat commit fa654ab

Compare with similar skills

Worktree Cleanup next to the 5 skills that share the most tags, products or categories with it. Stars are the repository's; “used in” counts other GitHub owners with a copy.

Worktree Cleanup compared with similar skills
SkillStarsUsed inTokensAuto-checkLicenceRepo updated
Worktree Cleanup this skillvchelaru/FlatRedBall578—~810Automated safety check: PassMIT
Cursor Composer Task DelegateChachamaru127/claude-code-harness3.2k—~4.4kAutomated safety check: NotesMIT
Knowledge Shell Process And WorktreeechoVic/blade-code181—~1.7kAutomated safety check: PassMIT
Build Px4 macOSPX4/PX4-Autopilot13k—~1.1kAutomated safety check: PassBSD-3-Clause
Git Worktree IsolationjnMetaCode/superpowers-zh8.3k1 repos~982Automated safety check: PassMIT
WorktreeAgentsMesh/AgentsMesh2.4k—~553Automated safety check: NotesCustom licence

Similar skills

  • Cursor Composer Task Delegate

    Chachamaru127/claude-code-harness

    Hands one implementation task to Cursor Composer in an isolated git worktree, then reviews its diff and cherry-picks the result into the main branch.

    3.2k GitHub stars~4.4k tokensUpdated 5 days ago
    DevelopmentAuto-check: notes
  • Covers Bash 前后台执行、stdin/终止、输出有界化、进程树与持久租约、Workspace 写沙箱,以及托管 Git worktree 的隔离和交付。

    181 GitHub stars~1.7k tokensUpdated today
    DevelopmentAuto-check passed
  • Build Px4 macOS

    PX4/PX4-Autopilot

    Build PX4 board firmware on macOS in the px4-dev Docker container, including git worktrees, and stage commit-labeled artifacts without flashing hardware.

    13k GitHub stars~1.1k tokensUpdated today
    DevelopmentAuto-check passed
  • Git Worktree Isolation

    jnMetaCode/superpowers-zh

    Sets up an isolated workspace before feature work or plan execution, preferring native worktree tools and falling back to git worktree, with instructions in Chinese.

    8.3k GitHub starsUsed in 1 repo~982 tokens
    DevelopmentAuto-check passed
  • Worktree

    AgentsMesh/AgentsMesh

    Creates or reuses an isolated AgentsMesh Git worktree from a verified base branch, preserves existing changes, and optionally starts the worktree-scoped development environment.

    2.4k GitHub stars~553 tokensUpdated 16 days ago
    DevelopmentAuto-check: notes
  • Automate git worktree creation and copy private files (not tracked in git) to new workdirs.

    155 GitHub stars~930 tokensUpdated 3 mo ago
    DevelopmentAuto-check passed

More from vchelaru/FlatRedBall

All 32 skills in this repo
  • Glue Live Game Testing

    vchelaru/FlatRedBall

    Testing GlueControl's embedded runtime (CommandReceiver, GlueControlManager) against a real running game process.

    578 GitHub stars~1.5k tokensUpdated today
    Auto-check passed
  • Glue Unit Test Bootstrap

    vchelaru/FlatRedBall

    Bootstrapping GlueUnitTests that touch GlueState.Self/GlueCommands.Self/ProjectManager.

    578 GitHub stars~4.3k tokensUpdated today
    Auto-check passed
  • Gluj Versions

    vchelaru/FlatRedBall

    A skill your agent uses when adding, modifying, or reasoning about Gluj/Glux file format versions, the GluxVersions enum, FileVersion checks, or anything that gates behavior on the version of a…

    578 GitHub stars~1.4k tokensUpdated today
    Auto-check passed
  • Gum Codegen

    vchelaru/FlatRedBall

    A skill your agent uses when working on Glue's Gum code generation — adding/removing/version-gating generated properties on Gum standard runtime types (NineSlice, Text, Container, Sprite, etc.), or…

    578 GitHub stars~3.4k tokensUpdated today
    Auto-check passed
  • Release

    vchelaru/FlatRedBall

    FRB1 (engine + Glue) release runbook — gh CLI sequence for Engine.yml/glue.yml, version scheme, release notes.

    578 GitHub stars~3.5k tokensUpdated today
    Auto-check passed
  • Release Notes

    vchelaru/FlatRedBall

    Drafts FRB1 release notes from commits/PRs since the last release.

    578 GitHub stars~1.9k tokensUpdated today
    Auto-check passed

Works with

Questions about Worktree Cleanup

What does Worktree Cleanup do?

Remove a subagent's .claude/worktrees/agent-<id dir after its PR merges. Worktree Cleanup is an agent skill from vchelaru/FlatRedBall.claude/worktrees/agent-<id dir after its PR merges.

When should I use Worktree Cleanup?

Worktree Cleanup fits situations like: tasks that involve Git worktrees.

How do I install Worktree Cleanup in Claude Code?

Run `npx skills add vchelaru/FlatRedBall --skill worktree-cleanup -a claude-code`. Or copy the skill folder (.claude/skills/worktree-cleanup in vchelaru/FlatRedBall) into .claude/skills/worktree-cleanup in your project. Claude Code loads it when a task matches its description.

How do I install Worktree Cleanup in Codex?

Run `npx skills add vchelaru/FlatRedBall --skill worktree-cleanup -a codex`. Or copy the skill folder (.claude/skills/worktree-cleanup in vchelaru/FlatRedBall) into .agents/skills/worktree-cleanup in your project. Codex loads it when a task matches its description.

Can I use Worktree Cleanup in Cursor, Gemini CLI or GitHub Copilot?

Cursor, Gemini CLI, GitHub Copilot and OpenCode also load SKILL.md folders. With the skills CLI, run `npx skills add vchelaru/FlatRedBall --skill worktree-cleanup -a cursor` (or -a gemini-cli, github-copilot or opencode for the others). To copy it by hand, put the folder in .cursor/skills/worktree-cleanup, .gemini/skills/worktree-cleanup, .github/skills/worktree-cleanup and .opencode/skills/worktree-cleanup in your project.

What does Worktree Cleanup need to run?

Going by SKILL.md and its folder, Worktree Cleanup needs the command-line tools its instructions call (git and dotnet).

Does Worktree Cleanup access the network?

SKILL.md contains no URLs. Its commands use git, which can reach the network depending on how they are called. This is read from the text; nothing was executed.

Is Worktree Cleanup safe to install?

Our automated static check of SKILL.md found no risky patterns, such as piping downloads into a shell, reading credential files or hidden Unicode. It is not a guarantee. Review the folder before installing.

What licence does Worktree Cleanup use?

Worktree Cleanup is published under the MIT licence (the repository's licence). It allows redistribution, so the full SKILL.md is shown on this page.

How many tokens does Worktree Cleanup use?

About 810 tokens (SKILL.md is roughly 3.2k characters). Agents keep only the skill's name and description in context until a task matches; then they load SKILL.md in full.

What are the alternatives to Worktree Cleanup?

Skills that share tags, products or a category with Worktree Cleanup: Cursor Composer Task Delegate (Chachamaru127/claude-code-harness, 3.2k stars), Knowledge Shell Process And Worktree (echoVic/blade-code, 181 stars), Build Px4 macOS (PX4/PX4-Autopilot, 13k stars) and Git Worktree Isolation (jnMetaCode/superpowers-zh, 8.3k stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.

Who maintains Worktree Cleanup?

vchelaru (a GitHub user) maintains it in vchelaru/FlatRedBall, which has 578 GitHub stars. The repository holds 32 skills in this directory. The repository was last updated on October 10, 2026.

Source: vchelaru/FlatRedBall on GitHub. Facts on this page come from the repository at the commit we read; the author's words are quoted as theirs.