"Phase 8: Cleanup — remove the worktree and delete the state file. Final phase. Requires Phase 7: Learning to be complete."
Install
npx skillscat add benkruger/flow/flow-cleanup Install via the SkillsCat registry.
FLOW Cleanup — Phase 8: Cleanup
Usage
/flow:flow-cleanup
/flow:flow-cleanup --auto
/flow:flow-cleanup --manual/flow:flow-cleanup— uses configured mode from.flow.json(default: auto)/flow:flow-cleanup --auto— skips confirmation and proceeds directly to cleanup/flow:flow-cleanup --manual— prompts for user confirmation before any destructive action
Mode Resolution
- If
--autowas passed → mode is auto - If
--manualwas passed → mode is manual - Otherwise, read
.flow.jsonfrom the project root. Useskills.flow-cleanupvalue. - If
.flow.jsonhas noskillskey → use built-in default: auto
- Find the project root: run
git worktree list --porcelainand note the
path on the firstworktreeline. - Get the current branch: run
git branch --show-current. - Use the Read tool to read
<project_root>/.flow-states/<branch>.json.- If the file exists: extract
feature,worktree, andcumulative_seconds. Checkphases.flow-learning.status— if not"complete",
record warning "Phase 7 not complete (status: )." - If the file does not exist: record warning "No state file found for
branch ''."
- If the file exists: extract
Use these values for all subsequent steps — do not re-read the state file
or re-run git commands to gather the same information.
Carry any warnings forward to the confirmation step in Step 2.
Resolve the mode using the Mode Resolution rules above.
Announce
At the very start, output the following banner in your response (not via Bash) inside a fenced code block:
```text
============================================
FLOW v0.19.0 — Phase 8: Cleanup — STARTING
============================================
```Logging
No logging for this phase. Cleanup deletes the log file as part of its
operation — writing log entries that are immediately deleted is pointless.
Steps
Step 1 — Handle missing state file
This step only runs if the SOFT-GATE found no state file. If the state
file existed, the SOFT-GATE already extracted all needed values — skip
to Step 2.
Infer what you can:
branchfromgit branch --show-current(already known from the gate)- Detect worktree path from
git worktree list - Use the branch name as the feature name
Tell the user what was inferred:
"No state file found. Inferring from git: branch '',
worktree ''."
Step 2 — Check PR merge status
Verify the PR has been merged before allowing cleanup.
If the state file had a pr_number, run:
gh pr view <pr_number> --json state --jq .stateIf the state file had no pr_number (or no state file was found), try the branch name:
gh pr view <branch> --json state --jq .stateIf the result is MERGED, continue to Step 3.
If the result is anything else (e.g., OPEN, CLOSED), stop:
"Your PR must be merged before cleanup. Current PR status: .
Merge the PR first, then run/flow:flow-cleanupagain."
If both commands fail (no PR found), stop:
"Could not find a PR for this branch. Merge your PR first, then run
/flow:flow-cleanupagain."
Step 3 — Confirm with user (manual mode only)
Skip this step if mode is auto — proceed directly to Step 4.
If mode is manual, this phase is destructive and irreversible. Use AskUserQuestion.
If the SOFT-GATE printed warnings, include them in the confirmation so
the user knows what's off before confirming:
"Ready to clean up feature ''?
⚠
This will remove the worktree and delete the state file and log permanently."
- Yes, clean up — proceed
- No, not yet — stop here
If there were no warnings:
"Ready to clean up feature ''?
This will remove the worktree and delete the state file and log permanently."
- Yes, clean up — proceed
- No, not yet — stop here
Step 4 — Run cleanup script
Run the cleanup script from the project root:
exec ${CLAUDE_PLUGIN_ROOT}/bin/flow cleanup <project_root> --branch <branch> --worktree <worktree_path>The script outputs JSON with a steps dict showing what happened to each resource (worktree, state_file, log_file). Each step reports "removed"/"deleted", "skipped", or "failed: reason".
Report the results to the user: what was cleaned, what was already gone, and what failed.
Step 5 — Pull merged changes
The worktree is removed and you are on main. Pull to get the merged
feature code:
git pull origin mainIf the pull fails, warn the user but do not block — cleanup succeeded.
Done — Print banner
For the banner below, compute <formatted_time> from the integer cumulative_seconds read in Step 1: Xh Ym if ≥ 3600, Xm if ≥ 60, <1m if < 60. Do not write the formatted string back to the state file.
Output the following banner in your response (not via Bash) inside a fenced code block:
```text
============================================
FLOW v0.19.0 — Phase 8: Cleanup — COMPLETE (<formatted_time>)
Feature '<feature>' is fully done.
Worktree removed, state file and log deleted.
============================================
```Rules
- Never run from inside the worktree — always navigate to project root first
- Confirm with the user only when mode is manual
- State file deletion is what resets the session hook — do not skip it
- Every step after confirmation is best-effort — if one fails, continue to the next
- Never use Bash to print banners — output them as text in your response
- Never use Bash for file reads — use Glob, Read, and Grep tools instead of ls, cat, head, tail, find, or grep
- Never use
cd <path> && git— usegit -C <path>for git commands in other directories - Never cd before running
bin/flow— it detects the project root internally