Iterative optimization loop. Launches the external orchestrator that runs REVIEW→MEASURE→ANALYZE→(RESEARCH)→PLAN→IMPLEMENT→VERIFY→DOCUMENT as independent Claude sessions.
When /opt-loop is invoked, launch the external orchestrator:
bash .claude/optimize.sh
Each phase runs as an independent Claude session — no context accumulation, no drift.
State passes between phases via files in opt/:
REVIEW → opt/reviews/<date>.md (every 5 rounds, harness audit)
MEASURE → opt/measure_report.md (+ history snapshot + trajectory)
ANALYZE → opt/analyze_report.md (category + initiative + research_depth)
RESEARCH → opt/research_report.md (conditional: if research_depth=deep)
PLAN → opt/current_plan.md (auto-approved to IMPLEMENT)
IMPLEMENT → updates opt/current_plan.md (TDD, scope-bounded coders)
VERIFY → fills Results section (tests + metric diff + evaluator)
DOCUMENT → archives plan, updates INDEX.md, initiatives, state.json
bash .claude/optimize.sh # one full cycle
bash .claude/optimize.sh --rounds=5 # run up to 5 cycles back-to-back
bash .claude/optimize.sh --from=analyze # resume from a specific phase
bash .claude/optimize.sh --review # force review phase now
bash .claude/optimize.sh --no-review # skip review even if due
bash .claude/optimize.sh --dry-run # preview phases
Multi-round (--rounds=N): round 1 honors --from=, rounds 2..N always start from
MEASURE. Any phase failure stops the run. REVIEW fires automatically on its 5-round cadence.
Files the loop reads across rounds:
opt/harness.md — project-specific config (what to measure, categories, prior art sources)opt/INDEX.md — flat table of every round (one line each). ANALYZE's pattern detector.opt/initiatives/*.md — multi-round engineering projects. ANALYZE prefers continuing them.opt/state.json — counters: category_failures, rounds_since_review, rounds_since_research.opt/plans/*.md — archived plans for retrospectives.opt/reviews/*.md — harness self-audits.opt/workflow_log.jsonl — per-round metrics.Categories with category_failures >= 2 are forbidden as targets. ANALYZE must pick
a different category or continue an active initiative in a different category. This
prevents grinding on the same wall for 10 rounds.
Big changes span many rounds. Track them in opt/initiatives/*.md. ANALYZE prefers
advancing active initiatives over opportunistic new targets.
ANALYZE emits research_depth: shallow|deep. If deep, the RESEARCH phase runs between
ANALYZE and PLAN — reads reference-implementation source directly for technique-level
prior art, writes opt/research_report.md. PLAN uses it instead of shallow web-search.
Every 5 rounds, the REVIEW phase runs before MEASURE:
rounds_since_review counterIf a phase fails or is interrupted:
bash .claude/optimize.sh --from=<phase>