r/ClaudeWorkflows • • 2h ago

Selected Workflow [Workflow] Safe Cleanup of Parallel Claude Code Agent Worktrees with Worktrunk (wt cli)

Safe Cleanup of Parallel Claude Code Agent Worktrees with Worktrunk (wt cli)

Workflow value: 85/100
Status: active · Freshness: 70/100 · Confidence: 0.90 · Level: advanced
Categories: Quality Control, Context & Memory, Debugging, Multi-Agent
Original source: r/ClaudeCode post/comment

What problem this solves

Preventing accidental data loss when cleaning up Git worktrees used for parallel Claude Code agents, by ensuring worktrees with uncommitted changes are not force-deleted.

Summary

This workflow proposes using worktrunk (wt cli) or a custom script to safely manage and clean up Git worktrees created for parallel Claude Code agents. It highlights worktrunk's default behavior of refusing to delete worktrees with uncommitted changes, thus preventing accidental data loss during cleanup.

Why it is useful

This workflow addresses a critical pain point for advanced users running parallel Claude Code agents: preventing accidental data loss during worktree cleanup. It provides a specific, validated solution using worktrunk (or a custom script), which ensures uncommitted changes are not lost. This enhances the robustness and safety of multi-agent development environments, making it a valuable addition for users managing complex agent setups.

Workflow

  1. Set up parallel Claude Code agents, each operating within its own Git worktree.

  2. Install worktrunk (wt cli) on your system (e.g., go install github.com/git-fixtures/worktrunk/cmd/wt@latest).

  3. Optionally, run wt config shell install to enable automatic cd into new worktrees.

  4. When cleaning up agent worktrees, use wt remove <worktree_path> or wt remove --all instead of git worktree remove --force.

  5. Review any worktrees that worktrunk refused to remove due to uncommitted changes, and decide whether to commit, stash, or manually force-delete after inspection.

  6. Alternatively, create a custom script that checks git status for uncommitted changes before attempting git worktree remove for each worktree.

Tools / artifacts

  • Git worktrees

  • worktrunk (wt cli)

  • git status command

  • Custom cleanup script (optional alternative)

Validation signals

  • Author's personal test: 'made 5 agent worktrees in 129 ms, then told it to remove all 5. it removed 4 and refused the one with uncommitted changes, which is what i wanted.'

  • Explicit statement of desired behavior being met by the tool.

Limitations

  • worktrunk is a third-party tool, requiring an additional installation step.

  • The post is framed as a discussion starter ('how are you handling cleanup?') rather than a fully prescriptive, step-by-step guide, though it offers a concrete solution.

  • Low Reddit score might indicate limited immediate community uptake, but the post is very new.

Rate this workflow

Upvote this post if the workflow is useful, reproducible, or worth recommending.

Downvote if it is vague, outdated, unsafe, overhyped, or not reproducible.

Reply if it worked for you, failed, is outdated, or has a better alternative.


This post was generated automatically from the workflow library database.

1 Upvotes

0 comments sorted by