/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
gh pr list --state merged --search "EP001"Remove worktree directories
for worktree in ../floe-agent-{epic}-*; do git worktree remove "$worktree" --force donePrune git worktree metadata
git worktree pruneDelete merged branches locally
git branch -d feature/{epic}-{task}Delete remote branches
git 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