# Worktree Cleanup

> Set up automated cleanup of dead git worktrees and merged branches. Use when user wants to automate worktree/branch cleanup, schedule daily git maintenance, clean up stale branches on wake/login, or set up launchd automation for git hygiene.

- **Type:** Skill
- **Install:** `agentstack add skill-assapir-agent-skills-worktree-cleanup`
- **Verified:** Yes — security-reviewed for prompt injection and unsafe behavior
- **Seller:** [assapir](https://agentstack.voostack.com/s/assapir)
- **Installs:** 0
- **Category:** [Agent Skills](https://agentstack.voostack.com/c/agent-skills)
- **Latest version:** 0.1.0
- **License:** MIT
- **Upstream author:** [assapir](https://github.com/assapir)
- **Source:** https://github.com/assapir/agent-skills/tree/main/worktree-cleanup

## Install

```sh
agentstack add skill-assapir-agent-skills-worktree-cleanup
```

Requires the [AgentStack CLI](https://agentstack.voostack.com/docs/cli). Works with Claude Code, Cursor, and any MCP-compatible agent.

## About

# Worktree Cleanup

Automate daily cleanup of dead worktrees and merged branches on macOS.

## What It Does

- Prunes dead worktrees (`git worktree prune`)
- Deletes branches merged into master/main
- Prunes stale remote tracking branches (`git fetch --prune`)
- Runs once per day on configured workdays (default: Sun-Thu)
- Triggers on first wake/login of the day

## Installation

Run the install script with optional parameters:

```bash
# Default: ~/code directory, Sun-Thu
~/.claude/skills/worktree-cleanup/scripts/install-cleanup.sh

# Custom directory
~/.claude/skills/worktree-cleanup/scripts/install-cleanup.sh ~/projects

# Custom directory and workdays (Mon-Fri = 1,2,3,4,5)
~/.claude/skills/worktree-cleanup/scripts/install-cleanup.sh ~/projects "1,2,3,4,5"
```

## Management Commands

```bash
# Run cleanup manually
~/.local/bin/cleanup-worktrees.sh

# View logs
cat ~/.local/state/worktree-cleanup.log

# Disable temporarily
launchctl unload ~/Library/LaunchAgents/com.$(whoami).cleanup-worktrees.plist

# Re-enable
launchctl load ~/Library/LaunchAgents/com.$(whoami).cleanup-worktrees.plist

# Uninstall completely
launchctl unload ~/Library/LaunchAgents/com.$(whoami).cleanup-worktrees.plist
rm ~/.local/bin/cleanup-worktrees.sh ~/Library/LaunchAgents/com.$(whoami).cleanup-worktrees.plist
```

## Configuration

Environment variables (set in launchd plist):
- `WORKTREE_CLEANUP_DIR` - Directory to scan for git repos (default: ~/code)
- `WORKTREE_CLEANUP_DAYS` - Workdays as comma-separated numbers, 0=Sun..6=Sat (default: 0,1,2,3,4)

## Source & license

This open-source skill is cataloged on AgentStack and links to its original source — we do not rehost the code.

- **Author:** [assapir](https://github.com/assapir)
- **Source:** [assapir/agent-skills](https://github.com/assapir/agent-skills)
- **License:** MIT

Install and usage instructions live in the source repository linked above.

## Pricing

- **Free** — Free

## Security capabilities

Automated source analysis of v0.1.0 — what this tool can access:

- **Network access:** no
- **Filesystem access:** no
- **Shell / process execution:** no
- **Environment & secrets:** no
- **Dynamic code execution:** no

*"Yes" means the capability is present in the source — more access means more to trust, not that it is unsafe.*


## Versions

- **0.1.0** — security scan: passed — Imported from the upstream source.

## Links

- Listing page: https://agentstack.voostack.com/l/skill-assapir-agent-skills-worktree-cleanup
- Seller: https://agentstack.voostack.com/s/assapir
- Browse the marketplace: https://agentstack.voostack.com/browse

---
Listed on AgentStack — the marketplace for AI agent skills and MCP servers. Every listing is security-reviewed. Creators keep 70%.
