Agent skill
ralph-cleanup
Remove worktrees after successful PR merge. Cleans up git worktrees, branches, and updates manifest.
Install this agent skill to your Project
npx add-skill https://github.com/majiayu000/claude-skill-registry/tree/main/skills/other/ralph-cleanup
SKILL.md
/ralph.cleanup
Remove worktrees after successful PR merge.
Prerequisites
- PR should be merged to main
- All agents for the epic should be COMPLETE
- Run
/ralph.memory-syncto ensure all memories are synced before cleanup
Process
-
Verify PR merged
bashgh pr list --state merged --search "EP001" -
Remove worktree directories
bashfor worktree in ../floe-agent-{epic}-*; do git worktree remove "$worktree" --force done -
Prune git worktree metadata
bashgit worktree prune -
Delete merged branches locally
bashgit branch -d feature/{epic}-{task} -
Delete remote branches
bashgit push origin --delete feature/{epic}-{task} -
Update manifest.json
- Move agents from
active_agentstocompleted_today - Update statistics
- Move agents from
-
Archive activity logs (optional)
- Move
.agent/activity.mdtologs/{epic}/
- Move
Output
RALPH WIGGUM CLEANUP - EP001
Worktrees removed: 5
- ../floe-agent-ep001-auth
- ../floe-agent-ep001-catalog
- ../floe-agent-ep001-models
- ../floe-agent-ep001-tests
- ../floe-agent-ep001-integration
Branches deleted (local): 5
Branches deleted (remote): 5
Manifest updated:
Active agents: 0
Completed today: +5 (total: 12)
Average duration: 42 min
Git worktree status:
(only main worktree remains)
Partial Cleanup
To clean up specific worktrees:
# Remove single worktree
git worktree remove ../floe-agent-ep001-auth --force
# Delete specific branch
git branch -d feature/ep001-auth
git push origin --delete feature/ep001-auth
Stale Worktree Detection
Worktrees are considered stale after 24 hours without commits:
# List stale worktrees
git worktree list | while read worktree branch _; do
if [[ "$worktree" == *"floe-agent"* ]]; then
last_commit=$(cd "$worktree" && git log -1 --format=%ct)
age_hours=$(( ($(date +%s) - last_commit) / 3600 ))
if [ $age_hours -gt 24 ]; then
echo "STALE: $worktree (${age_hours}h)"
fi
fi
done
Force Cleanup
To remove all agent worktrees regardless of state:
# WARNING: This will remove all work in worktrees
git worktree list | grep "floe-agent" | cut -d' ' -f1 | \
xargs -I{} git worktree remove {} --force
git worktree prune
Recovery
If cleanup was accidental:
# Branches still exist on remote
git fetch origin
# Recreate worktree from remote branch
git worktree add ../floe-agent-ep001-auth feature/ep001-auth
Configuration
From .ralph/config.yaml:
auto_cleanup: true (remove after merge)stale_worktree_hours: 24archive_activity_logs: true
Linear Update
After cleanup, update Linear issues:
mcp__plugin_linear_linear__update_issue({
"id": task_id,
"state": "completed"
})
mcp__plugin_linear_linear__create_comment({
"issueId": task_id,
"body": "Task completed and merged. Worktree cleaned up."
})
Related Commands
/ralph.spawn- Start agents/ralph.status- Check progress/ralph.integrate- Prepare for PR
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
Didn't find tool you were looking for?