remove-worktree

Instructions for safely removing a Git worktree, which is a separate working directory linked to another branch, and then deleting that branch.

In plain words
What is it for?
Use it to list worktrees, select a non-main one by path or branch, review its changes, and clean it up safely.
Why use it?
It prevents accidentally removing the main worktree or losing uncommitted changes. If unfinished work exists, it requires confirmation before continuing.

Skill for Claude CodeCodex

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.

agentmods
npx agentmods add skills/hyperaiteam/clitrigger/remove-worktree
Any agent
npx skills add HyperAITeam/CLITrigger --skill remove-worktree
Clone the repo
git clone --depth 1 https://github.com/HyperAITeam/CLITrigger

Made for: Claude Code, Codex.

Per session 31 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 1,032 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
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 $0.00031 $0.01032
Opus 5 $0.00015 $0.00516
Sonnet 5 $0.00006 $0.00206
Haiku 4.5 $0.00003 $0.00103

Measured 2d ago against content hash a5ec622717cb, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

remove-worktree scanned grade A with 0 findings 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 2d 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.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

.claude/skills/remove-worktree/SKILL.md · 105 lines

How it starts

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

Remove Worktree

워크트리를 제거하고 연결된 브랜치를 정리합니다.

Current context

  • Worktree list: !git worktree list --porcelain

Instructions

Follow these phases exactly, in order. Do NOT skip phases.


Phase 1: 워크트리 선택

  1. git worktree list --porcelain을 실행하여 모든 워크트리 정보를 파싱한다.

    • 각 워크트리 항목은 worktree <path>, HEAD <hash>, branch refs/heads/<name> 형태로 출력된다.
    • main worktree (현재 체크아웃된 주 저장소)는 목록에서 제외한다.
  2. $ARGUMENTS가 제공된 경우:

    • 워크트리 경로 또는 브랜치명으로 매칭되는 항목을 찾는다.
    • 경로의 마지막 부분(디렉터리명)으로도 매칭을 시도한다.
    • 매칭되는 항목이 없으면 사용 가능한 워크트리 목록을 보여주고 중단한다.
  3. $ARGUMENTS가 없는 경우:

    • 워크트리가 하나도 없으면 "제거할 워크트리가 없습니다."라고 알리고 중단한다.
    • 워크트리가 하나면 자동 선택한다.
    • 워크트리가 여러 개면 번호와 함께 목록을 보여주고 AskUserQuestion으로 선택 받는다.
      제거할 워크트리를 선택하세요:
      1. feature/task-abc123  →  .worktrees/feature-task-abc123
      2. feature/task-xyz789  →  .worktrees/feature-task-xyz789
      
  4. 선택된 워크트리의 경로브랜치명을 확정한다.


Phase 2: 안전 검사

  1. git -C <worktree-path> status --porcelain을 실행한다.

  2. 변경사항이 없으면: Phase 3으로 바로 진행한다.

  3. 미커밋 변경사항이 있으면:

    • 변경된 파일 목록을 보여준다.
    • AskUserQuestion으로 확인을 받는다:

      "워크트리 <branch-name>에 미커밋 변경사항이 있습니다. 강제로 제거하면 이 변경사항은 영구적으로 삭제됩니다. 계속하시겠습니까? (yes/no)"

    • "no" 또는 거부하면 중단하고 변경사항을 커밋하거나 스태시할 것을 안내한다.
    • "yes"면 강제 제거 플래그(--force)를 사용하기로 표시하고 Phase 3으로 진행한다.

Phase 3: 워크트리 제거

  1. 워크트리를 제거한다:

    • 변경사항 없음: git worktree remove <worktree-path>
    • 강제 제거: git worktree remove --force <worktree-path>
  2. 명령이 실패하면 에러 메시지를 출력하고 중단한다.

  3. git worktree list를 실행하여 워크트리가 실제로 제거되었는지 확인한다.


Phase 4: 브랜치 처리

  1. 제거된 워크트리의 브랜치명(<branch-name>)을 사용한다.

  2. AskUserQuestion으로 브랜치 삭제 여부를 확인한다:

    "브랜치 <branch-name>도 삭제하시겠습니까? (yes/no)"

  3. "yes"인 경우:

    • git branch -D <branch-name>을 실행한다.
    • 실패하면 에러를 보고하되 전체 작업은 성공으로 처리한다.
  4. "no"인 경우: 브랜치를 그대로 유지한다.


Phase 5: 완료 보고

다음 내용을 요약하여 보고한다:

  • 제거된 워크트리 경로
  • 삭제된 브랜치 (삭제한 경우) 또는 유지된 브랜치 (유지한 경우)
  • 원격 브랜치가 존재할 경우 안내:

    원격 브랜치도 삭제하려면: git push origin --delete <branch-name>

Read the full file on GitHub · 105 lines

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. 2d ago First seen · 105 lines · 31 tokens per session scan A a5ec622717cb

Subscribe to this mod's changes

remove-worktree is a skill published in the GitHub repository HyperAITeam/CLITrigger (13 stars, last pushed 8d ago), licensed MIT. It adds 31 tokens to every session and 1,032 once invoked, about $0.0002 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.

Related

Other skills, from other repositories