# Clean Stale Git Worktrees, Branches and Docker

> Dry-run-first cleanup of merged git worktrees, stale branches and orphaned Docker containers, with optional macOS launchd scheduling.

Clean Stale Git Worktrees, Branches and Docker is a free AI agent skill on Agensi by Chris Cheng, in Productivity. It loads into your AI agent through the Agensi MCP server, always in its latest approved version.

- Price: Free
- Creator: [Chris Cheng](https://www.agensi.io/creators/chrischeng0608)
- Category: [Productivity](https://www.agensi.io/skills/productivity)
- Version: 1.0
- Last updated: 2026-12-02
- Security: scan passed (2026-12-02); every new listing is also reviewed by a person
- Listing: https://www.agensi.io/skills/clean-stale-git-worktrees-branches-and-docker
- Tags: devops-cloud, productivity

## About this skill

`scripts/clean.sh` does the safe tier and is the only thing that runs unattended. Everything beyond it is a judgment call made with the user in the session.

Safe tier, applied by the script:
- Prunes worktrees whose folder is gone.
- Removes worktrees that are clean, have no process inside, and whose tip is merged (ancestor of `origin/HEAD`, a merged PR head, or behind one). Orca-managed worktrees go through `orca worktree rm`.
- Deletes branches that are merged or whose last commit is older than `--age-days` (21). Each deletion is logged to `~/.local/state/clean-git-workspaces/<key>.deleted-branches`.
- Removes containers whose bind-mount source no longer exists. Prunes images and build cache unused for 7+ days.

`schedule.sh` takes `daily`, `weekly` or `biweekly`. Weekly and biweekly take a day (`sun`..`sat`, default `mon`); biweekly skips a run when the last one was under 13 days ago. Missed runs fire on wake. The log is `~/Library/Logs/clean-git-workspaces/<key>.log`.

1. Run the dry run and show its WOULD and KEEP lines.
2. Run `--apply` on what the user approves.
3. Each KEEP item needs the user's decision:

## Requires

- Runs on macOS only
- Git
- Optional: GitHub CLI
- Optional: Docker or OrbStack
- Optional: Orca CLI

## How to use this skill

1. Connect your AI agent to Agensi once: add the MCP server https://mcp.agensi.io/mcp/auth and sign in with your Agensi account (OAuth, no API key). Steps for Claude, ChatGPT, Claude Code, Codex, Cursor, VS Code and other agents: https://www.agensi.io/docs/mcp-setup
2. Ask your agent: "Use the Clean Stale Git Worktrees, Branches and Docker skill from Agensi" and describe your task.
3. Your agent loads the skill from Agensi when it needs it. Nothing is downloaded.

## Frequently asked questions

### What does Clean Stale Git Worktrees, Branches and Docker do?

Dry-run-first cleanup of merged git worktrees, stale branches and orphaned Docker containers, with optional macOS launchd scheduling.

### Which AI agents support Clean Stale Git Worktrees, Branches and Docker?

This skill uses the open SKILL.md standard. Use it through an MCP-compatible agent connected to Agensi, and check the compatibility information on this page for confirmed agents and required capabilities.

### How do I use Clean Stale Git Worktrees, Branches and Docker?

Connect your AI agent to Agensi through MCP, then ask it to use Clean Stale Git Worktrees, Branches and Docker on your task. Your agent loads the latest approved version each time. Paid skills require a purchase or active subscription. Skill files are not available for download; your licence does not allow you to save, copy or export any part of a skill.

---

Source: [Agensi](https://www.agensi.io), the marketplace of skills for AI agents. Any MCP-compatible agent (Claude, ChatGPT, Claude Code, Codex, Cursor, VS Code and more) connects at https://mcp.agensi.io/mcp/auth and signs in with an Agensi account; setup for every agent: https://www.agensi.io/docs/mcp-setup. Append .md to any skill, guide or docs address on agensi.io for its markdown version.
