Plan, Implement, Verify, Recover
Apply the smallest workflow that safely completes the requested code change.
Do not expose private reasoning. Communicate only decisions, plans, risks,
blockers, verification evidence, and concise progress useful to the user.
Inspect Project Instructions
Before editing:
- Read applicable
AGENTS.md and repository instructions.
- Inspect repository status and preserve unrelated user changes.
- Locate relevant entrypoints, implementation files, nearby patterns,
configuration, callers, and tests.
- Use targeted discovery; do not read the entire repository when a smaller
context is sufficient.
- Do not modify files during initial discovery.
Use repository-provided build, test, lint, formatting, and validation commands.
Do not invent project commands when existing instructions are available.
Define the Change
Establish:
- A one-sentence goal.
- In-scope and out-of-scope behavior.
- Observable completion criteria.
- Primary risks and affected boundaries.
Keep this internal for small, clear changes. Present it when ambiguity, risk,
or scope makes user confirmation materially useful.
Select One Route
Fast
Use for clear, low-risk, localized, easily reversible changes that do not
affect public contracts, data models, authentication, authorization, security,
payments, or infrastructure.
- Read the directly relevant implementation and nearby test or example.
- Make the smallest correct change.
- Run the fastest relevant validation.
- Review the diff.
- Report evidence.
Do not create a written plan artifact.
Standard
Use for normal multi-file features, bug fixes, and refactoring where the
architecture remains stable.
- Create a concise implementation plan.
- Identify files, sequence, risks, and verification.
- Read relevant implementation, callers, and tests.
- Implement the plan in scoped increments.
- Run targeted checks, then broader checks when justified.
- Review the complete diff.
- Report evidence and remaining limitations.
Do not add a plan file to the repository unless repository instructions, the
user, or the task explicitly requires one.
Deep
Use for architecture, security, authentication, authorization, payments,
personal data, migrations, public API changes, difficult rollback, large
refactors, major dependencies, or high ambiguity.
- Perform targeted architectural discovery.
- Prepare a written plan with alternatives, tradeoffs, affected boundaries,
rollback considerations, and a verification strategy.
- Resolve product decisions or missing authority before implementation.
- Implement in reviewable checkpoints.
- Run verification appropriate to every affected risk domain.
- Perform a fresh semantic review of the complete diff.
- Use an independent review only when explicitly requested or when applicable
project instructions require and permit it.
- Report evidence, residual risks, and proof gaps.
Run the Bounded Execution Loop
Track these internal state values:
route: fast, standard, or deep.
state: discover, plan, implement, verify, review, recover,
complete, or blocked.
correction_cycles: completed Recovery-to-Verification cycles.
replans: plan replacements caused by new evidence.
last_failure: latest distinct failure.
last_hypothesis: latest tested causal hypothesis.
evidence: compact list of checks and results.
Apply these route budgets:
| Route |
Maximum correction cycles |
Maximum replans |
| Fast |
1 |
0 |
| Standard |
3 |
1 |
| Deep |
5 |
2 |
Run this state loop:
discover: Gather only enough relevant context to act safely.
plan: Produce only the plan detail required by the selected route.
implement: Apply the smallest planned increment.
verify: Run the fastest relevant check before broader checks.
- Move from
verify to review when checks pass.
- Move from
verify or review to recover when evidence shows a defect.
- In
recover, form and test a new causal hypothesis, correct the cause,
increment correction_cycles, and return to verify.
- Return to
plan and increment replans only when evidence invalidates the
current plan.
- Move from
review to complete when the diff is clean and completion
criteria have evidence.
- Move to
blocked when a stop condition applies.
Do not repeat an unchanged command, action, hypothesis, or fix. Treat the same
failure after the same attempted correction as no progress. Change the
hypothesis or stop.
Do not reload unchanged files unless new evidence requires it. Maintain a
compact state summary instead of restating the full history each cycle.
Stop the loop when:
- Completion criteria have sufficient evidence.
- The selected route budget is exhausted.
- No new testable hypothesis remains.
- Required access, credentials, or external availability is missing.
- New authority or a user-owned product decision is required.
- Scope materially expands or an external contract changes unexpectedly.
- Continuing could overwrite unrelated user work or make recovery unsafe.
Apply Implementation Principles
- Prefer the smallest safe solution.
- Apply KISS and YAGNI before introducing abstractions.
- Reuse established project patterns when they fit.
- Avoid speculative code for possible future requirements.
- Stay within the accepted user-visible and architectural scope.
- Match nearby naming, structure, comments, and idioms.
- Preserve backward compatibility unless the request requires otherwise.
- Do not hide failures with silent fallbacks.
- Make necessary fallbacks observable, bounded, and justified.
- Do not hardcode credentials, environment values, URLs, mutable policies,
domain limits, or repeated unexplained literals.
- Do not create configuration or abstraction for local, stable,
self-explanatory literals.
- Do not overwrite or discard unrelated user changes.
Allow technical implementation details to evolve within the accepted scope.
Stop for direction when work requires new authority, expands product scope,
changes an external contract, unexpectedly changes the data model, or
introduces a material architectural decision.
Verify
Select checks by change type and risk. Read
references/verification-matrix.md when the right checks are unclear or the
change affects multiple domains.
Prefer this order:
- Syntax or formatting check.
- Targeted test for changed behavior.
- Module-level typecheck, lint, or test.
- Build or broader integration checks when justified.
- Semantic diff review.
Treat git diff --stat as scope evidence, not functional verification.
Never claim completion without relevant evidence. When a check cannot run,
report the exact unverified behavior, why it could not be verified, available
evidence, and the next check required.
When verification succeeds, continue to review. When it fails, preserve the
failure evidence and enter recover.
Recover from Failure
Enter Recovery when implementation or verification produces an unexpected
failure. Read references/debugging-protocol.md, then:
- Reproduce or isolate the failure.
- Record expected and observed behavior.
- Form a testable root-cause hypothesis.
- Gather evidence before applying a fix.
- Apply the smallest causal correction.
- Add or update a regression test when appropriate.
- Increment
correction_cycles and return to verify.
Do not apply unrelated speculative fixes.
Obey the correction and replan budgets for the selected route. Stop earlier
when the loop makes no progress or any global stop condition applies.
Report Completion
Report:
- What changed.
- Why it was the smallest suitable solution.
- Files or components affected.
- Checks executed and their results.
- Checks not executed and why.
- Remaining risks, limitations, or proof gaps.
Keep the report proportional to the change.
1---2name: plan-implement-verify-recover3description: Execute repository code changes through risk-adaptive planning, targeted context reading, scoped implementation, verification, and a bounded evidence-driven correction loop. Use when Codex is asked to modify an existing codebase, fix a bug, implement a feature, refactor code, integrate an API, change a database, perform a migration, or make architectural or security-sensitive changes. Do not use for read-only explanations, analysis without changes, research, content writing, prompt creation, document summarization, or standalone examples that will not be applied to a repository.4---56# Plan, Implement, Verify, Recover78Apply the smallest workflow that safely completes the requested code change.910Do not expose private reasoning. Communicate only decisions, plans, risks,11blockers, verification evidence, and concise progress useful to the user.1213## Inspect Project Instructions1415Before editing:16171. Read applicable `AGENTS.md` and repository instructions.182. Inspect repository status and preserve unrelated user changes.193. Locate relevant entrypoints, implementation files, nearby patterns,20 configuration, callers, and tests.214. Use targeted discovery; do not read the entire repository when a smaller22 context is sufficient.235. Do not modify files during initial discovery.2425Use repository-provided build, test, lint, formatting, and validation commands.26Do not invent project commands when existing instructions are available.2728## Define the Change2930Establish:3132- A one-sentence goal.33- In-scope and out-of-scope behavior.34- Observable completion criteria.35- Primary risks and affected boundaries.3637Keep this internal for small, clear changes. Present it when ambiguity, risk,38or scope makes user confirmation materially useful.3940## Select One Route4142### Fast4344Use for clear, low-risk, localized, easily reversible changes that do not45affect public contracts, data models, authentication, authorization, security,46payments, or infrastructure.47481. Read the directly relevant implementation and nearby test or example.492. Make the smallest correct change.503. Run the fastest relevant validation.514. Review the diff.525. Report evidence.5354Do not create a written plan artifact.5556### Standard5758Use for normal multi-file features, bug fixes, and refactoring where the59architecture remains stable.60611. Create a concise implementation plan.622. Identify files, sequence, risks, and verification.633. Read relevant implementation, callers, and tests.644. Implement the plan in scoped increments.655. Run targeted checks, then broader checks when justified.666. Review the complete diff.677. Report evidence and remaining limitations.6869Do not add a plan file to the repository unless repository instructions, the70user, or the task explicitly requires one.7172### Deep7374Use for architecture, security, authentication, authorization, payments,75personal data, migrations, public API changes, difficult rollback, large76refactors, major dependencies, or high ambiguity.77781. Perform targeted architectural discovery.792. Prepare a written plan with alternatives, tradeoffs, affected boundaries,80 rollback considerations, and a verification strategy.813. Resolve product decisions or missing authority before implementation.824. Implement in reviewable checkpoints.835. Run verification appropriate to every affected risk domain.846. Perform a fresh semantic review of the complete diff.857. Use an independent review only when explicitly requested or when applicable86 project instructions require and permit it.878. Report evidence, residual risks, and proof gaps.8889## Run the Bounded Execution Loop9091Track these internal state values:9293- `route`: `fast`, `standard`, or `deep`.94- `state`: `discover`, `plan`, `implement`, `verify`, `review`, `recover`,95 `complete`, or `blocked`.96- `correction_cycles`: completed Recovery-to-Verification cycles.97- `replans`: plan replacements caused by new evidence.98- `last_failure`: latest distinct failure.99- `last_hypothesis`: latest tested causal hypothesis.100- `evidence`: compact list of checks and results.101102Apply these route budgets:103104| Route | Maximum correction cycles | Maximum replans |105|---|---:|---:|106| Fast | 1 | 0 |107| Standard | 3 | 1 |108| Deep | 5 | 2 |109110Run this state loop:1111121. `discover`: Gather only enough relevant context to act safely.1132. `plan`: Produce only the plan detail required by the selected route.1143. `implement`: Apply the smallest planned increment.1154. `verify`: Run the fastest relevant check before broader checks.1165. Move from `verify` to `review` when checks pass.1176. Move from `verify` or `review` to `recover` when evidence shows a defect.1187. In `recover`, form and test a new causal hypothesis, correct the cause,119 increment `correction_cycles`, and return to `verify`.1208. Return to `plan` and increment `replans` only when evidence invalidates the121 current plan.1229. Move from `review` to `complete` when the diff is clean and completion123 criteria have evidence.12410. Move to `blocked` when a stop condition applies.125126Do not repeat an unchanged command, action, hypothesis, or fix. Treat the same127failure after the same attempted correction as no progress. Change the128hypothesis or stop.129130Do not reload unchanged files unless new evidence requires it. Maintain a131compact state summary instead of restating the full history each cycle.132133Stop the loop when:134135- Completion criteria have sufficient evidence.136- The selected route budget is exhausted.137- No new testable hypothesis remains.138- Required access, credentials, or external availability is missing.139- New authority or a user-owned product decision is required.140- Scope materially expands or an external contract changes unexpectedly.141- Continuing could overwrite unrelated user work or make recovery unsafe.142143## Apply Implementation Principles1441451. Prefer the smallest safe solution.1462. Apply KISS and YAGNI before introducing abstractions.1473. Reuse established project patterns when they fit.1484. Avoid speculative code for possible future requirements.1495. Stay within the accepted user-visible and architectural scope.1506. Match nearby naming, structure, comments, and idioms.1517. Preserve backward compatibility unless the request requires otherwise.1528. Do not hide failures with silent fallbacks.1539. Make necessary fallbacks observable, bounded, and justified.15410. Do not hardcode credentials, environment values, URLs, mutable policies,155 domain limits, or repeated unexplained literals.15611. Do not create configuration or abstraction for local, stable,157 self-explanatory literals.15812. Do not overwrite or discard unrelated user changes.159160Allow technical implementation details to evolve within the accepted scope.161Stop for direction when work requires new authority, expands product scope,162changes an external contract, unexpectedly changes the data model, or163introduces a material architectural decision.164165## Verify166167Select checks by change type and risk. Read168`references/verification-matrix.md` when the right checks are unclear or the169change affects multiple domains.170171Prefer this order:1721731. Syntax or formatting check.1742. Targeted test for changed behavior.1753. Module-level typecheck, lint, or test.1764. Build or broader integration checks when justified.1775. Semantic diff review.178179Treat `git diff --stat` as scope evidence, not functional verification.180181Never claim completion without relevant evidence. When a check cannot run,182report the exact unverified behavior, why it could not be verified, available183evidence, and the next check required.184185When verification succeeds, continue to `review`. When it fails, preserve the186failure evidence and enter `recover`.187188## Recover from Failure189190Enter Recovery when implementation or verification produces an unexpected191failure. Read `references/debugging-protocol.md`, then:1921931. Reproduce or isolate the failure.1942. Record expected and observed behavior.1953. Form a testable root-cause hypothesis.1964. Gather evidence before applying a fix.1975. Apply the smallest causal correction.1986. Add or update a regression test when appropriate.1997. Increment `correction_cycles` and return to `verify`.200201Do not apply unrelated speculative fixes.202203Obey the correction and replan budgets for the selected route. Stop earlier204when the loop makes no progress or any global stop condition applies.205206## Report Completion207208Report:209210- What changed.211- Why it was the smallest suitable solution.212- Files or components affected.213- Checks executed and their results.214- Checks not executed and why.215- Remaining risks, limitations, or proof gaps.216217Keep the report proportional to the change.