worktree-lifecycle

worktree-lifecycle is a skill for Claude Code, Codex from MadAppGang/magus. It costs 39 tokens per session (3,721 once invoked), scanned D, a copy of worktree-lifecycle, MIT.

A guide for using Git worktrees, which let one repository have several separate working folders at the same time.

In plain words
What is it for?
Use it to create, switch between, check, and safely clean up worktrees for feature development, prototypes, or parallel agent tasks.
Why use it?
It helps isolate risky, experimental, or parallel changes while keeping the current working folder untouched.

Skill for Claude CodeCodex

Part of the dev plugin — 41 skills, 13 commands, 13 agents shipped together

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/madappgang/magus/worktree-lifecycle
Any agent
npx skills add MadAppGang/magus --skill worktree-lifecycle
Clone the repo
git clone --depth 1 https://github.com/MadAppGang/magus

Made for: Claude Code, Codex.

Or install dev, the plugin that ships this one along with the rest of its 41 skills, 13 commands, 13 agents.

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 worktree-lifecycle

README.md
[![agentmods](https://agentmods.dev/badge/skills/madappgang/magus/worktree-lifecycle.svg)](https://agentmods.dev/skills/madappgang/magus/worktree-lifecycle)
Your own site
<a href="https://agentmods.dev/skills/madappgang/magus/worktree-lifecycle"><img src="https://agentmods.dev/badge/skills/madappgang/magus/worktree-lifecycle.svg" alt="Measured on agentmods" height="20"></a>
Per session 39 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 3,721 The whole file, excluding the scripts and references it only reads on demand.
Security scan D 2 findings. Scan, not verified.
Origin 86% copy Near-identical to another mod 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.00039 $0.03721
Opus 5 $0.00019 $0.01861
Sonnet 5 $0.00008 $0.00744
Haiku 4.5 $0.00004 $0.00372

Measured yesterday against content hash 6f69614ab232, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade D, and why

worktree-lifecycle scanned grade D with 2 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 yesterday.

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.

Reads agent configuration directoriesmediumAgent snooping

.claude/, .codex/, .gemini/ hold keys, settings and other credentials a mod has no legitimate need for.

cat > "$HOME/.claude/.statusline-worktree-${SESSION_ID}" <<MARKER_EOF

Recursive force deletehighDestructive command

rm -rf with a variable or a broad path is one typo away from removing the wrong tree.

- [ ] Manually deleting worktree with `rm -rf` (use `git worktree remove`)
Origin

This is a copy

86% identical to worktree-lifecycle — 14 lines differ, which has more behind it and is treated as the original. This page carries a canonical link to it rather than competing with it.

plugins/dev/skills/discipline/worktree-lifecycle/SKILL.md · 454 lines

How it starts

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

Worktree Lifecycle

Purpose: Manage git worktrees for isolated feature work with safety checks, multi-stack setup, and clean lifecycle management.

When to Use

This skill applies whenever you:

  • Start a new feature that requires isolated workspace
  • Execute risky or experimental changes
  • Need to keep current work untouched while testing alternatives
  • Coordinate parallel agent work (each agent in separate worktree)
  • Follow an implementation plan requiring clean environment
  • Preserve long-running feature work across sessions

Trigger keywords: experiment, prototype, risky, breaking, parallel, isolate, worktree, workspace

Red Flags (Anti-Patterns)

  • Creating worktree without checking if branch already exists
  • Creating worktree without checking if directory path is available
  • Forgetting to add worktree directory to .gitignore
  • Manually deleting worktree with rm -rf (use git worktree remove)
  • Removing worktree with uncommitted changes without user confirmation
  • Using same branch in multiple worktrees simultaneously
  • Working in worktree after returning to main directory (stale CWD)
  • Not storing original CWD before entering worktree
  • Skipping dependency installation in new worktree
  • Not running baseline tests before starting work

6-Phase Lifecycle

Phase 1: Pre-flight Checks

Purpose: Verify all prerequisites before creating anything.

Required checks (all must pass):

# 1. Verify git repository
git rev-parse --git-dir &>/dev/null
if [ $? -ne 0 ]; then
  ERROR: "Not a git repository"
  RECOVERY: Abort with clear error message
fi

# 2. Detect detached HEAD state
if ! git symbolic-ref HEAD &>/dev/null; then
  WARNING: "Currently in detached HEAD state"
  RECOVERY: Ask user if they want to create branch from current commit
fi

# 3. Check if branch already in a worktree
if git worktree list | grep -q "$BRANCH"; then
  ERROR: "Branch $BRANCH already checked out in a worktree"
  RECOVERY: Ask user - reuse existing, rename branch, or cancel
fi

# 4. Check if branch exists (but not in worktree)
if git branch --list "$BRANCH" | grep -q .; then
  WARNING: "Branch $BRANCH already exists"
  RECOVERY: Ask user - use existing branch or create new with different name
fi

# 5. Check if target path is available
# IMPORTANT: Create directory first before checking (git check-ignore needs path to exist)
mkdir -p "$WORKTREE_DIR"
if [ -d "$WORKTREE_PATH" ]; then
  ERROR: "Directory $WORKTREE_PATH already exists"
  RECOVERY: Ask user - choose different path or remove existing
fi

Read the full file on GitHub · 454 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. yesterday First seen · 454 lines · 39 tokens per session scan D 6f69614ab232

Subscribe to this mod's changes

worktree-lifecycle is a skill published in the GitHub repository MadAppGang/magus (9 stars, last pushed yesterday), licensed MIT. It adds 39 tokens to every session and 3,721 once invoked, about $0.0002 per session on Opus 5. A static security scan graded it D with 2 findings (reads agent configuration directories, recursive force delete). It is 86% identical to worktree-lifecycle, differing in 14 lines, and is treated as a copy.

Related

Other skills, from other repositories

systematic-debugging

Use when encountering any bug, test failure, or unexpected behavior, before proposing fixes.

obra/superpowers · 21 tokens

local-ai-agents

Build local-first AI agents that run entirely on a developer workstation with Microsoft Foundry Local and Qwen function-calling models. Covers Small Language Models (SLMs), the OpenAI-compatible local endpoint, sandboxed local tools, local RAG with Chroma, local MCP servers, hybrid cloud/local routing, and the…

microsoft/ai-agents-for-beginners · 200 tokens

next-cache-components-adoption

Turn on Cache Components in a Next.js app and resolve the blocking routes it surfaces. Use when the user wants to enable, adopt, or migrate to Cache Components, flip the cacheComponents flag, work through a flood of blocking-prerender / instant validation errors, run the cache-components-instant-false codemod, or…

vercel/next.js · 95 tokens

chat-pet-sprite-creation

Use when creating or changing VS Code chat pet sprite art, sprite sheets, state animations, eye treatments, Stable/Insiders variants, or pet transitions under src/vs/workbench/contrib/chat/browser/widget/media/chatPet.

microsoft/vscode · 53 tokens

cpu-profile-analysis

Analyze V8/Chrome CPU profiles (.cpuprofile) and DevTools trace files (Trace-.json). Use when: profiling performance, investigating slow functions, comparing code paths, finding bottlenecks, analyzing timeToRequest, understanding call trees from sampling profiler data, analyzing layout/paint/rendering, investigating…

microsoft/vscode · 71 tokens

insight-error-page

Write or audit an insight-kind error page for the Next.js dev overlay. Use when creating a new errors/ .mdx page, auditing an existing one, or checking that a page matches the framework fix cards. Covers page structure, title alignment, FixCard cards with Copy prompt button, code snippets, terminology verification…

vercel/next.js · 83 tokens