iterative-planner
Original:🇺🇸 English
Translated
2 scriptsChecked / no sensitive code detected
State-machine driven iterative planning and execution for complex coding tasks. Cycle: Explore → Plan → Execute → Reflect → Re-plan. Filesystem as persistent memory. Use for multi-file tasks, migrations, refactoring, failed tasks, or anything non-trivial.
7installs
Added on
NPX Install
npx skill4agent add nikolasmarkou/iterative-planner iterative-plannerTags
Translated version includes tags in frontmatterSKILL.md Content
View Translation Comparison →Iterative Planner
Core Principle: Context Window = RAM. Filesystem = Disk.
Write to disk immediately. The context window will rot. The files won't.
{plan-dir}plans/plan_YYYY-MM-DD_XXXXXXXX/plans/.current_planplans/FINDINGS.mdplans/DECISIONS.mdState Machine
mermaid
stateDiagram-v2
[*] --> EXPLORE
EXPLORE --> PLAN : enough context
PLAN --> EXPLORE : need more context
PLAN --> PLAN : user rejects / revise
PLAN --> EXECUTE : user approves
EXECUTE --> REFLECT : phase ends/failed/surprise/leash
REFLECT --> CLOSE : all criteria met
REFLECT --> RE_PLAN : failed / better approach
REFLECT --> EXPLORE : need more context
RE_PLAN --> PLAN : new approach ready
CLOSE --> [*]| State | Purpose | Allowed Actions |
|---|---|---|
| EXPLORE | Gather context | Read-only on project. Write only to |
| PLAN | Design approach | Write plan.md. NO code changes. |
| EXECUTE | Implement step-by-step | Edit files, run commands, write code. |
| REFLECT | Evaluate results | Read outputs, run tests. Update decisions.md. |
| RE-PLAN | Revise direction | Log pivot in decisions.md. Do NOT write plan.md yet. |
| CLOSE | Finalize | Write summary.md. Audit decision anchors. Merge findings/decisions to consolidated files. |
Transitions
| From → To | Trigger |
|---|---|
| EXPLORE → PLAN | Sufficient context. ≥3 indexed findings in |
| PLAN → EXPLORE | Can't state problem, can't list files, or insufficient findings. |
| PLAN → PLAN | User rejects plan. Revise and re-present. |
| PLAN → EXECUTE | User explicitly approves. |
| EXECUTE → REFLECT | Execution phase ends (all steps done, failure, surprise, or leash hit). |
| REFLECT → CLOSE | All criteria verified PASS in |
| REFLECT → RE-PLAN | Failure or better approach found. |
| REFLECT → EXPLORE | Need more context before re-planning. |
| RE-PLAN → PLAN | New approach formulated. Decision logged. |
Every transition → log in . RE-PLAN transitions → also log in (what failed, what learned, why new direction).
At CLOSE → audit decision anchors (). Merge per-plan findings/decisions to and .
state.mddecisions.mdreferences/decision-anchoring.mdplans/FINDINGS.mdplans/DECISIONS.mdMandatory Re-reads (CRITICAL)
These files are active working memory. Re-read during the conversation, not just at start.
| When | Read | Why |
|---|---|---|
| Before any EXECUTE step | | Confirm step, manifest, fix attempts, progress sync |
| Before writing a fix | | Don't repeat failed approaches. Check 3-strike. |
Before modifying | Referenced | Understand why before changing |
| Before PLAN or RE-PLAN | | Ground plan in known facts |
| Before any REFLECT | | Compare against written criteria, not vibes |
| Every 10 tool calls | | Reorient. Right step? Scope crept? |
>50 messages: re-read + before every response. Files are truth, not memory.
state.mdplan.mdBootstrapping
bash
node <skill-path>/scripts/bootstrap.mjs "goal" # Create new plan (backward-compatible)
node <skill-path>/scripts/bootstrap.mjs new "goal" # Create new plan
node <skill-path>/scripts/bootstrap.mjs new --force "goal" # Close active plan, create new one
node <skill-path>/scripts/bootstrap.mjs resume # Re-entry summary for new sessions
node <skill-path>/scripts/bootstrap.mjs status # One-line state summary
node <skill-path>/scripts/bootstrap.mjs close # Close plan (preserves directory)
node <skill-path>/scripts/bootstrap.mjs list # Show all plan directoriesnewresumeclose--forcenew.gitignoreplans/closestate.md.current_plansummary.mdclose{plan-dir}state.mdplan.mddecisions.mdfindings.mdprogress.mdverification.mdfindings.mdFilesystem Structure
plans/
├── .current_plan # → active plan directory name
├── FINDINGS.md # Consolidated findings across all plans (merged on close)
├── DECISIONS.md # Consolidated decisions across all plans (merged on close)
└── plan_2026-02-14_a3f1b2c9/ # {plan-dir}
├── state.md # Current state + transition log
├── plan.md # Living plan (rewritten each iteration)
├── decisions.md # Append-only decision/pivot log
├── findings.md # Summary + index of findings
├── findings/ # Detailed finding files (subagents write here)
├── progress.md # Done vs remaining
├── verification.md # Verification results per REFLECT cycle
├── checkpoints/ # Snapshots before risky changes
└── summary.md # Written at CLOSETemplates:
references/file-formats.mdFile Lifecycle Matrix
R = read only | W = update (implicit read + write) | R+W = distinct read and write operations | — = do not touch (wrong state if you are).
Read-before-write rule: Always read a plan file before writing/overwriting it — even on the first update after bootstrap. Claude Code's Write tool will reject writes to files you haven't read in the current session. This applies to every W and R+W cell below.
| File | EXPLORE | PLAN | EXECUTE | REFLECT | RE-PLAN | CLOSE |
|---|---|---|---|---|---|---|
| state.md | W | W | R+W | W | W | W |
| plan.md | — | W | R+W | R | R | R |
| decisions.md | — | R+W | R | R+W | R+W | R |
| findings.md | W | R | — | R | R+W | R |
| findings/* | W | R | — | R | R+W | R |
| progress.md | — | W | R+W | R+W | W | R |
| verification.md | — | W | W | W | R | R |
| checkpoints/* | — | — | W | R | R | — |
| summary.md | — | — | — | — | — | W |
| plans/FINDINGS.md | R | R | — | — | R | W(merge) |
| plans/DECISIONS.md | R | R | — | — | R | W(merge) |
Per-State Rules
EXPLORE
- Read ,
state.mdandplans/FINDINGS.mdat start of EXPLORE for cross-plan context.plans/DECISIONS.md - Read code, grep, glob, search. One focused question at a time.
- Flush to +
findings.mdafter every 2 reads. Read the file first before each write.findings/ - Include file paths + code path traces (e.g. →
auth.rb:23→SessionStore#find).redis_store.rb:get - DO NOT skip EXPLORE even if you think you know the answer.
- Minimum depth: ≥3 indexed findings in before transitioning to PLAN. Findings must cover: (1) problem scope, (2) affected files, (3) existing patterns or constraints. Fewer than 3 → keep exploring.
findings.md - Use Task subagents to parallelize research. All subagent output → files. Never rely on context-only results. Main agent updates
{plan-dir}/findings/index after subagents write — subagents don't touch the index. Naming:findings.md(kebab-case, descriptive — e.g.findings/{topic-slug}.md,auth-system.md).test-coverage.md - Use "think hard" / "ultrathink" for complex analysis.
- REFLECT → EXPLORE loops: append to existing findings, don't overwrite. Mark corrections with .
[CORRECTED iter-N]
PLAN
- Gate check: read ,
state.md,plan.md,findings.md,findings/*,decisions.md,progress.md,verification.md,plans/FINDINGS.mdbefore writing anything. If not read → read now. No exceptions. Ifplans/DECISIONS.mdhas <3 indexed findings → go back to EXPLORE.findings.md - Problem Statement first — before designing steps, write in : (1) what behavior is expected, (2) invariants — what must always be true, (3) edge cases at boundaries. Can't state the problem clearly → go back to EXPLORE.
plan.md - Write : problem statement, steps, failure modes, risks, success criteria, verification strategy, complexity budget.
plan.md - Verification Strategy — for each success criterion, define: what test/check to run, what command to execute, what result means "pass". Write to plan.md section. Plans with no testable criteria → write "N/A — manual review only" (proves you checked). See
Verification Strategyfor template.references/file-formats.md - Failure Mode Analysis — for each external dependency or integration point in the plan, answer: what if slow? returns garbage? is down? What's the blast radius? Write to plan.md section. No dependencies → write "None identified" (proves you checked).
Failure Modes - Write : log chosen approach + why (mandatory even for first plan). Trade-off rule — phrase every decision as "X at the cost of Y". Never recommend without stating what it costs.
decisions.md - Read then write with initial template (criteria table populated from success criteria, methods from verification strategy, results pending).
verification.md - Read then write +
state.md.progress.md - List every file to modify/create. Can't list them → go back to EXPLORE.
- Only recommended approach in plan. Alternatives → .
decisions.md - Wait for explicit user approval.
EXECUTE
- Pre-Step Checklist in : reset all boxes
state.md, then check each[ ]as completed before starting the step. This is the file-based enforcement of Mandatory Re-reads.[x] - Iteration 1, first EXECUTE → create (nuclear fallback). "Git State" = commit hash BEFORE changes (the restore point).
checkpoints/cp-000-iter1.md - One step at a time. Post-Step Gate after each (see below).
- Checkpoint before risky changes (3+ files, shared modules, destructive ops). Name: (e.g.
cp-NNN-iterN.md). Increment NNN globally across iterations.cp-001-iter2.md - Commit after each successful step: .
[iter-N/step-M] description - If something breaks → STOP. 2 fix attempts max (Autonomy Leash). Each must follow Revert-First.
- Irreversible operations (DB migrations, external API calls, service config, non-tracked file deletion): mark step in
[IRREVERSIBLE]during PLAN. Full procedure:plan.md.references/code-hygiene.md - Surprise discovery (behavior contradicts findings, unknown dependency, wrong assumption) → note in , finish or revert current step, transition to REFLECT. Do NOT silently update findings during EXECUTE.
state.md - Add comments where needed (
# DECISION D-NNN).references/decision-anchoring.md
Post-Step Gate (successful steps only — all 3 before moving on)
- — mark step
plan.md, advance marker, update complexity budget[x] - — move item Remaining → Completed, set next In Progress
progress.md - — update step number, append to change manifest
state.md
On failed step: skip gate. Follow Autonomy Leash (revert-first, 2 attempts max).
REFLECT
- Read (criteria + verification strategy) +
plan.mdbefore evaluating.progress.md - Read + relevant
findings.md— check if discoveries during EXECUTE contradict earlier findings. Note contradictions infindings/*.decisions.md - Read — know what rollback options exist before deciding next transition. Note available restore points in
checkpoints/*if transitioning to RE-PLAN.decisions.md - Cross-validate: every in plan.md must be "Completed" in progress.md. Fix drift first.
[x] - Run verification — execute each check defined in the Verification Strategy. Read , then record results: criterion, method, command/action, result (PASS/FAIL), evidence (output summary or log reference). See
verification.mdfor template.references/file-formats.md - Read — check 3-strike patterns.
decisions.md - Compare against written criteria, not memory. Run 5 Simplification Checks ().
references/complexity-control.md - Write (what happened, learned, root cause) +
decisions.md+progress.md.state.md
| Condition | → Transition |
|---|---|
All criteria verified PASS in | → CLOSE |
| Failure understood, new approach clear | → RE-PLAN |
| Unknowns need investigation, or findings contradicted | → EXPLORE (update findings first) |
RE-PLAN
- Read ,
decisions.md, relevantfindings.md.findings/* - Read — decide keep vs revert. Default: if unsure, revert to latest checkpoint. See
checkpoints/*for full decision framework.references/code-hygiene.md - If earlier findings proved wrong or incomplete → update +
findings.mdwith corrections. Mark corrections:findings/*+ what changed and why. Append, don't delete original text.[CORRECTED iter-N] - Write : log pivot + mandatory Complexity Assessment.
decisions.md - Write +
state.md(mark failed items, note pivot).progress.md - Present options to user → get approval → transition to PLAN.
Complexity Control (CRITICAL)
Default response to failure = simplify, not add. See .
references/complexity-control.mdRevert-First — when something breaks: (1) STOP (2) revert? (3) delete? (4) one-liner? (5) none → REFLECT.
10-Line Rule — fix needs >10 new lines → it's not a fix → REFLECT.
3-Strike Rule — same area breaks 3× → RE-PLAN with fundamentally different approach. Revert to checkpoint covering the struck area.
Complexity Budget — tracked in plan.md: files added 0/3, abstractions 0/2, lines net-zero target.
Forbidden: wrapper cascades, config toggles, copy-paste, exception swallowing, type escapes, adapters, "temporary" workarounds.
Nuclear Option — iteration 5 + bloat >2× scope → recommend full revert to (or later checkpoint if user agrees). Otherwise proceed with caution. See .
cp-000references/complexity-control.mdAutonomy Leash (CRITICAL)
When a step fails during EXECUTE:
- 2 fix attempts max — each must follow Revert-First + 10-Line Rule.
- Both fail → STOP COMPLETELY. No 3rd fix. No silent alternative. No skipping ahead.
- Revert uncommitted changes to last clean commit. Codebase must be known-good before presenting.
- Present: what step should do, what happened, 2 attempts, root cause guess, available checkpoints for rollback.
- Transition → REFLECT. Log leash hit in . Wait for user.
state.md
Track attempts in . Resets on: user direction, new step, or RE-PLAN.
No exceptions. Unguided fix chains derail projects.
state.mdCode Hygiene (CRITICAL)
Failed code must not survive. Track changes in change manifest in .
Failed step → revert all uncommitted. RE-PLAN → explicitly decide keep vs revert.
Codebase must be known-good before any PLAN. See .
state.mdreferences/code-hygiene.mdDecision Anchoring (CRITICAL)
Code from failed iterations carries invisible context. Anchor
at point of impact — state what NOT to do and why. Audit at CLOSE.
See .
# DECISION D-NNNreferences/decision-anchoring.mdIteration Limits
Increment on PLAN → EXECUTE. Iteration 0 = EXPLORE-only (pre-plan). First real = iteration 1.
- Iteration 6+: hard STOP. Going in circles? Harder than scoped? Break into smaller tasks.
Recovery from Context Loss
- If is missing or corrupted: run
plans/.current_planto find plan directories, then recreate the pointer:bootstrap.mjs list(substitute actual directory name).echo "plan_YYYY-MM-DD_XXXXXXXX" > plans/.current_plan - → plan dir name
plans/.current_plan - → where you are
state.md - → current plan
plan.md - → what was tried / failed
decisions.md - → done vs remaining
progress.md - +
findings.md→ discovered contextfindings/* - → available rollback points and their git hashes
checkpoints/* - +
plans/FINDINGS.md→ cross-plan context from previous plansplans/DECISIONS.md - Resume from current state. Never start over.
Git Integration
- EXPLORE/PLAN/REFLECT/RE-PLAN: no commits.
- EXECUTE: commit per successful step . Failed step → revert uncommitted.
[iter-N/step-M] desc - RE-PLAN: keep successful commits if valid under new plan, or to revert. No partial state. Log choice in
git checkout <checkpoint-commit> -- ..decisions.md - CLOSE: final commit + tag.
User Interaction
| State | Behavior |
|---|---|
| EXPLORE | Ask focused questions, one at a time. Present findings. |
| PLAN | Present plan. Wait for approval. Re-present if modified. |
| EXECUTE | Report per step. Surface surprises. Ask before deviating. |
| REFLECT | Show expected vs actual. Propose: continue, re-plan, or close. |
| RE-PLAN | Reference decision log. Explain pivot. Get approval. |
When NOT to Use
Simple single-file changes, obvious solutions, known-root-cause bugs, or "just do it".
References
- — templates for all
references/file-formats.mdfiles{plan-dir} - — anti-complexity protocol, forbidden patterns
references/complexity-control.md - — change manifest, revert procedures
references/code-hygiene.md - — when/how to anchor decisions in code
references/decision-anchoring.md