/workflow:checkpoint-refactor
Multi-phase refactoring with persistent state that survives context limits and session boundaries.
When to Use This Skill
| Use this skill when... |
Use direct refactoring instead when... |
| Refactoring spans 10+ files |
Changing 1-5 files |
| Work will exceed context limits |
Small, focused change |
| Need to resume across sessions |
Single-session task |
| Multiple dependent phases |
Independent file changes |
| Team coordination on large refactor |
Solo quick fix |
Context
- Repo root: !
git rev-parse --show-toplevel
- Plan file exists: !
find . -maxdepth 1 -name REFACTOR_PLAN.md
- Git status: !
git status --porcelain
- Recent commits: !
git log --oneline --max-count=5
Parameters
--init: Create a new refactoring plan interactively
--continue: Resume from the last completed phase
--status: Show current plan progress
--phase=N: Execute a specific phase
Plan File Format
The plan file (REFACTOR_PLAN.md) serves as persistent state. It is the loop's
compact state packet (.claude/rules/loop-integrity.md): a fresh session,
or a sub-agent with no memory of prior phases, must be able to re-enter from this
file alone. Every phase therefore carries not just what to do but what was
verified and what changed — without those, resuming across a context limit
silently redoes or undoes work.
# Refactor Plan: {description}
Created: {date}
Last updated: {date}
Base commit: {hash}
Exit condition: {the literal criterion that ends the whole refactor — e.g. "all phases done, full suite + tsc green on base"}
## Overview
{What is being refactored and why}
## Phase 1: {phase name}
- **Status**: done | in-progress | pending | needs-review
- **Files**: file1.ts, file2.ts, file3.ts
- **Description**: {what this phase does}
- **Acceptance criteria**: {how to verify success — the phase's exit condition}
- **Verifier result**: {what the independent check returned — PASS/FAIL + the criterion it judged; filled in at the phase boundary}
- **Changed since last run**: {what this phase actually touched, so a successor doesn't redo or undo it}
- **Result**: {summary of changes made, filled in after completion}
## Phase 2: {phase name}
- **Status**: pending
- **Files**: file4.ts, file5.ts
- **Description**: {what this phase does}
- **Acceptance criteria**: {how to verify success}
- **Verifier result**: {empty until verified}
- **Changed since last run**: {empty until completed}
- **Result**: {empty until completed}
...
Execution
Execute this multi-phase refactoring workflow:
Step 1: Initialize refactoring plan (--init mode)
If --init flag provided:
- Analyze scope: Read files to be refactored, understand dependencies
- Define phases where each:
- Touches 3-7 files (bounded scope)
- Has clear acceptance criteria (tests, type check)
- Can be committed independently
- Builds on previous phases
- Write plan file: Create
REFACTOR_PLAN.md at repo root
- Record base commit:
git log --format='%H' -1
Phase ordering: Shared utilities/types first, leaf components last, tests alongside implementation.
Step 2: Resume existing refactor (--continue mode)
If --continue flag provided:
- Read
REFACTOR_PLAN.md
- Find next pending phase (status
pending or needs-review)
- Verify all prior phases are
done
- Execute phase (go to Step 4)
Step 3: Check progress (--status mode)
If --status flag provided:
- Read
REFACTOR_PLAN.md
- Parse plan and display status table with phases, descriptions, statuses, file counts
- Exit
Step 4: Execute target phase (--phase=N or selected via Step 2)
For each phase:
- Read context from plan file (current phase's details)
- Read only the files listed for this phase
- Implement changes according to phase description
- Validate with appropriate tool (tsc, ty check, cargo check, or npm/pytest test)
- If validation fails:
- Fix errors if straightforward
- If complex, mark phase as
needs-review with error details
- Commit partial work with
WIP: prefix
- If validation passes, gate
done on an independent verifier when the
acceptance criteria are a judgement (e.g. "the class is now single-purpose"),
not a purely mechanical check (a green suite / clean tsc is already
independent — a failing test does not care how hard you worked):
- Dispatch a fresh
Task sub-agent that reads only this phase's
acceptance criteria and the resulting diff — not the worker's reasoning —
and judges whether the criteria are met. The worker is biased toward
declaring completion; the loop's stop condition must come from outside it
(.claude/rules/loop-integrity.md, Pillar 1). When the criteria are about
behaviour ("endpoint returns X", "the bug no longer reproduces"),
delegate this to agent-patterns-plugin:execution-grounded-review, which
runs the suite first and grounds each criterion in execution evidence
rather than appearance.
- Record the verdict in the phase's Verifier result field (PASS/FAIL +
the criterion judged).
- If the verifier returns FAIL, leave status
in-progress/needs-review
and address the gap before marking done.
- Once verified, update the plan file: set status to
done, fill Verifier
result, Changed since last run, and Result, then commit:
git add -u && git commit -m "refactor phase N: {description}"
- If more phases remain, proceed to next phase or suggest
--continue
Step 5: Sub-agent delegation (for large phases)
For phases with 7+ files, delegate to Task sub-agent with:
- File list to modify
- Phase description and acceptance criteria
- Instructions: run validation, update plan file, stage/commit changes
- If validation fails: mark phase as
needs-review with error details
Recovery Patterns
| Situation |
Action |
| Context limit hit mid-phase |
Start new session, run --continue |
| Phase marked needs-review |
Read plan for details, fix issues, run --phase=N |
| Tests broken after a phase |
Revert phase commit, investigate, re-execute |
| Plan needs adjustment |
Edit REFACTOR_PLAN.md directly, update phases |
| Base branch moved |
Rebase onto new base, re-validate completed phases |
Agentic Optimizations
| Context |
Command |
| Check plan exists |
test -f REFACTOR_PLAN.md && echo "exists" |
| Quick typecheck |
npx tsc --noEmit --pretty 2>&1 | head -20 |
| Quick test |
npm test -- --bail=1 2>&1 | tail -20 |
| Phase commit |
git commit -m "refactor phase N: description" |
| Verify working state |
npx tsc --noEmit && npm test -- --bail=1 |
| Show plan phases |
grep "^## Phase" REFACTOR_PLAN.md |
| Show phase status |
grep -A1 "^## Phase" REFACTOR_PLAN.md | grep Status |
Quick Reference
| Operation |
Command |
| Init new refactor |
/workflow:checkpoint-refactor --init |
| Check progress |
/workflow:checkpoint-refactor --status |
| Resume work |
/workflow:checkpoint-refactor --continue |
| Run specific phase |
/workflow:checkpoint-refactor --phase=3 |
| Manual plan edit |
Edit REFACTOR_PLAN.md directly |
Related Skills
1---
2name: workflow-checkpoint-refactor
3description: Multi-phase refactoring with checkpoint files that survive context limits. Use when refactoring spans 10+ files, needs phased rollout, or risks running out of context mid-session.
4args: "[--init|--continue|--status|--phase=N]"
5allowed-tools: Bash(git status *), Bash(git diff *), Bash(git log *), Bash(git add *), Bash(git commit *), Bash(npm run *), Bash(npx *), Bash(uv run *), Bash(cargo *), Read, Write, Edit, Grep, Glob, Task, TodoWrite
6argument-hint: "--init to create plan, --continue to resume, --status to check progress"
7created: 2026-02-08
8modified: 2026-06-21
9reviewed: 2026-02-14
10---
11
12# /workflow:checkpoint-refactor
13
14Multi-phase refactoring with persistent state that survives context limits and session boundaries.
15
16## When to Use This Skill
17
18| Use this skill when... | Use direct refactoring instead when... |
19|------------------------|---------------------------------------|
20| Refactoring spans 10+ files | Changing 1-5 files |
21| Work will exceed context limits | Small, focused change |
22| Need to resume across sessions | Single-session task |
23| Multiple dependent phases | Independent file changes |
24| Team coordination on large refactor | Solo quick fix |
25
26## Context
27
28- Repo root: !`git rev-parse --show-toplevel`
29- Plan file exists: !`find . -maxdepth 1 -name REFACTOR_PLAN.md`
30- Git status: !`git status --porcelain`
31- Recent commits: !`git log --oneline --max-count=5`
32
33## Parameters
34
35- **`--init`**: Create a new refactoring plan interactively
36- **`--continue`**: Resume from the last completed phase
37- **`--status`**: Show current plan progress
38- **`--phase=N`**: Execute a specific phase
39
40## Plan File Format
41
42The plan file (`REFACTOR_PLAN.md`) serves as persistent state. It is the loop's
43**compact state packet** (`.claude/rules/loop-integrity.md`): a fresh session,
44or a sub-agent with no memory of prior phases, must be able to re-enter from this
45file alone. Every phase therefore carries not just *what to do* but *what was
46verified* and *what changed* — without those, resuming across a context limit
47silently redoes or undoes work.
48
49```markdown
50# Refactor Plan: {description}
51
52Created: {date}
53Last updated: {date}
54Base commit: {hash}
55Exit condition: {the literal criterion that ends the whole refactor — e.g. "all phases done, full suite + tsc green on base"}
56
57## Overview
58{What is being refactored and why}
59
60## Phase 1: {phase name}
61- **Status**: done | in-progress | pending | needs-review
62- **Files**: file1.ts, file2.ts, file3.ts
63- **Description**: {what this phase does}
64- **Acceptance criteria**: {how to verify success — the phase's exit condition}
65- **Verifier result**: {what the independent check returned — PASS/FAIL + the criterion it judged; filled in at the phase boundary}
66- **Changed since last run**: {what this phase actually touched, so a successor doesn't redo or undo it}
67- **Result**: {summary of changes made, filled in after completion}
68
69## Phase 2: {phase name}
70- **Status**: pending
71- **Files**: file4.ts, file5.ts
72- **Description**: {what this phase does}
73- **Acceptance criteria**: {how to verify success}
74- **Verifier result**: {empty until verified}
75- **Changed since last run**: {empty until completed}
76- **Result**: {empty until completed}
77
78...
79```
80
81## Execution
82
83Execute this multi-phase refactoring workflow:
84
85### Step 1: Initialize refactoring plan (--init mode)
86
87If `--init` flag provided:
88
891. Analyze scope: Read files to be refactored, understand dependencies
902. Define phases where each:
91 - Touches 3-7 files (bounded scope)
92 - Has clear acceptance criteria (tests, type check)
93 - Can be committed independently
94 - Builds on previous phases
953. Write plan file: Create `REFACTOR_PLAN.md` at repo root
964. Record base commit: `git log --format='%H' -1`
97
98**Phase ordering**: Shared utilities/types first, leaf components last, tests alongside implementation.
99
100### Step 2: Resume existing refactor (--continue mode)
101
102If `--continue` flag provided:
103
1041. Read `REFACTOR_PLAN.md`
1052. Find next pending phase (status `pending` or `needs-review`)
1063. Verify all prior phases are `done`
1074. Execute phase (go to Step 4)
108
109### Step 3: Check progress (--status mode)
110
111If `--status` flag provided:
112
1131. Read `REFACTOR_PLAN.md`
1142. Parse plan and display status table with phases, descriptions, statuses, file counts
1153. Exit
116
117### Step 4: Execute target phase (--phase=N or selected via Step 2)
118
119For each phase:
120
1211. Read context from plan file (current phase's details)
1222. Read only the files listed for this phase
1233. Implement changes according to phase description
1244. Validate with appropriate tool (tsc, ty check, cargo check, or npm/pytest test)
1255. If validation fails:
126 - Fix errors if straightforward
127 - If complex, mark phase as `needs-review` with error details
128 - Commit partial work with `WIP:` prefix
1296. If validation passes, **gate `done` on an independent verifier** when the
130 acceptance criteria are a judgement (e.g. "the class is now single-purpose"),
131 not a purely mechanical check (a green suite / clean `tsc` is already
132 independent — a failing test does not care how hard you worked):
133 - Dispatch a fresh `Task` sub-agent that reads **only** this phase's
134 acceptance criteria and the resulting diff — not the worker's reasoning —
135 and judges whether the criteria are met. The worker is biased toward
136 declaring completion; the loop's stop condition must come from outside it
137 (`.claude/rules/loop-integrity.md`, Pillar 1). When the criteria are about
138 **behaviour** ("endpoint returns X", "the bug no longer reproduces"),
139 delegate this to `agent-patterns-plugin:execution-grounded-review`, which
140 runs the suite first and grounds each criterion in execution evidence
141 rather than appearance.
142 - Record the verdict in the phase's **Verifier result** field (PASS/FAIL +
143 the criterion judged).
144 - If the verifier returns FAIL, leave status `in-progress`/`needs-review`
145 and address the gap before marking `done`.
1467. Once verified, update the plan file: set status to `done`, fill **Verifier
147 result**, **Changed since last run**, and **Result**, then commit:
148 `git add -u && git commit -m "refactor phase N: {description}"`
1498. If more phases remain, proceed to next phase or suggest `--continue`
150
151### Step 5: Sub-agent delegation (for large phases)
152
153For phases with 7+ files, delegate to Task sub-agent with:
154- File list to modify
155- Phase description and acceptance criteria
156- Instructions: run validation, update plan file, stage/commit changes
157- If validation fails: mark phase as `needs-review` with error details
158
159## Recovery Patterns
160
161| Situation | Action |
162|-----------|--------|
163| Context limit hit mid-phase | Start new session, run `--continue` |
164| Phase marked needs-review | Read plan for details, fix issues, run `--phase=N` |
165| Tests broken after a phase | Revert phase commit, investigate, re-execute |
166| Plan needs adjustment | Edit REFACTOR_PLAN.md directly, update phases |
167| Base branch moved | Rebase onto new base, re-validate completed phases |
168
169## Agentic Optimizations
170
171| Context | Command |
172|---------|---------|
173| Check plan exists | `test -f REFACTOR_PLAN.md && echo "exists"` |
174| Quick typecheck | `npx tsc --noEmit --pretty 2>&1 \| head -20` |
175| Quick test | `npm test -- --bail=1 2>&1 \| tail -20` |
176| Phase commit | `git commit -m "refactor phase N: description"` |
177| Verify working state | `npx tsc --noEmit && npm test -- --bail=1` |
178| Show plan phases | `grep "^## Phase" REFACTOR_PLAN.md` |
179| Show phase status | `grep -A1 "^## Phase" REFACTOR_PLAN.md \| grep Status` |
180
181## Quick Reference
182
183| Operation | Command |
184|-----------|---------|
185| Init new refactor | `/workflow:checkpoint-refactor --init` |
186| Check progress | `/workflow:checkpoint-refactor --status` |
187| Resume work | `/workflow:checkpoint-refactor --continue` |
188| Run specific phase | `/workflow:checkpoint-refactor --phase=3` |
189| Manual plan edit | Edit `REFACTOR_PLAN.md` directly |
190
191## Related Skills
192
193- [code-review-checklist](../../../code-quality-plugin/skills/code-review-checklist/SKILL.md) - Review refactored code
194- [refactoring-patterns](../../../code-quality-plugin/skills/refactoring-patterns/SKILL.md) - Refactoring techniques
195- [adversarial-review](../../../agent-patterns-plugin/skills/adversarial-review/SKILL.md) - The isolated verifier a judgement-based phase gate delegates to
196- [execution-grounded-review](../../../agent-patterns-plugin/skills/execution-grounded-review/SKILL.md) - The execution-grounded verifier for behaviour-based phase acceptance criteria
197- `.claude/rules/loop-integrity.md` - Why the plan file is a state packet and why `done` is judged independently