| name | git-reset-workspace |
| disable-model-invocation | true |
| description | Multi-phase workspace cleanup. Stops background agents, inventories
uncommitted work, switches to main, prunes stale branches, cleans
worktrees, verifies clean state. Safe by default — never destroys
work without confirmation. Use for end-of-day cleanup, before context
switches, or when a repo is in a messy state.
|
| allowed-tools | ["Read","Bash","Glob","Grep","AskUserQuestion","Agent"] |
Reset Workspace
Systematic workspace cleanup in six phases. Safe by default — every destructive
action requires confirmation.
When to Use
- End of day/week cleanup
- Before switching to a different project
- When a repo is in a messy state (stale branches, orphan worktrees)
- Before machine migration
- When resuming after a long break and state is unclear
Phases
Phase 1: Stop Background Processes
Check for and stop background processes related to development:
ps aux | grep "Codex" | grep -v grep
ps aux | grep -E "go test|npm test|make" | grep -v grep
lsof -i -P | grep LISTEN | grep -v "$(whoami)" --invert-match
Present findings. Ask before killing anything.
Phase 2: Inventory Uncommitted Work
For the current repo (and optionally all repos under ~/repo/):
git status --short
git stash list
git diff --stat
find ~/repo -maxdepth 3 -name .git -type d -exec dirname {} \; | while read repo; do
changes=$(git -C "$repo" status --porcelain 2>/dev/null | wc -l | tr -d ' ')
stashes=$(git -C "$repo" stash list 2>/dev/null | wc -l | tr -d ' ')
branch=$(git -C "$repo" branch --show-current 2>/dev/null)
[ "$changes" -gt 0 ] || [ "$stashes" -gt 0 ] || [ "$branch" != "main" -a "$branch" != "master" ] && \
echo "$repo: ${changes} changes, ${stashes} stashes, on $branch"
done
Do NOT proceed past this phase if there is uncommitted work. Present
findings and ask the user what to do:
- Commit it
- Stash it
- Discard it (requires explicit approval)
Phase 3: Switch to Main
git checkout main 2>/dev/null || git checkout master
git pull --rebase
If checkout fails (uncommitted changes), loop back to Phase 2.
Phase 4: Prune Stale Branches
List branches with age and merge status:
git branch --merged main | grep -v "main\|master\|\*"
git branch --no-merged main --format="%(refname:short) %(committerdate:relative)"
Present two lists:
- Merged branches (safe to delete — already in main)
- Unmerged branches (may have work — show last commit date and message)
Ask before deleting. For merged branches, suggest batch delete. For unmerged,
require individual confirmation.
git branch --merged main | grep -v "main\|master\|\*" | xargs git branch -d
Prune remote tracking branches:
git remote prune origin
Phase 5: Clean Worktrees
git worktree list
For each worktree that isn't the main working tree:
- Check if it has uncommitted changes
- Check if its branch still exists
- Present findings
git worktree prune
Phase 6: Verify Clean State
Final verification:
git status
git branch
git stash list
git worktree list
Expected state:
- On main/master
- No uncommitted changes
- No stashes (or intentionally kept stashes)
- Only main + intentionally kept branches
- Only the primary worktree
Present final state. Note any intentional deviations.
Safety Rules
- Never
git clean -fdx without showing what will be deleted and getting approval
- Never
git reset --hard without confirming no work will be lost
- Never delete unmerged branches without individual confirmation
- Never kill processes without showing what they are first
- Stale = merged into main or last commit >30 days ago — not just "old"
- Worktrees with changes are not orphaned — they have work in progress
Common Mistakes
- Deleting a branch that has unpushed commits — always check
git log main..branch before deleting
- Pruning a worktree that's mid-work — check
git -C <worktree> status first
- Killing a background process that belongs to another project — identify the process fully before killing
- Running on a shared repo without coordination — don't prune remote branches other people use
- Forgetting stashes —
git stash list is easy to skip but stashes contain real work