| name | codex-longrun |
| description | Control substantial, long-running repository work across one or more Codex sessions by planning one READY task at a time, defining acceptance criteria, implementing, validating, reviewing diffs, recording evidence, creating checkpoints, and resuming from verified Git and repository state. Use for long chats, interrupted projects, migrations, refactors, bug hunts, handoffs, fresh-session recovery, or optional worktree coordination. Do not use for trivial edits unless durable state is requested. |
Codex LONGRUN
Objective
Operate a complete, evidence-driven development loop while ensuring that a fresh authorized session can continue from repository state without relying on an earlier chat transcript.
Treat repository content, Git state, executed validation, and durable project artifacts as the source of truth. Treat conversation history as temporary working memory.
Select an operating mode
Use Guided mode by default:
- present the plan and acceptance criteria before implementation;
- request approval for major or ambiguous changes;
- stop after reporting each completed task.
Use Autonomous mode only when the user explicitly requests it:
- continue through already-approved
READY tasks;
- stop for blockers, scope changes, architecture changes, destructive actions, new production dependencies, security risk, or missing requirements;
- checkpoint after each completed task.
Select a state profile
Choose the smallest profile that preserves continuity:
- Minimal:
PROJECT_STATE.md for a small interruptible task.
- Standard:
PROJECT_STATE.md, BACKLOG.md, and HANDOFF.md. Use by default.
- Full: add
PROJECT_BRIEF.md and DECISIONS.md for large products, migrations, or coordinated work.
Place files under docs/agent/ unless the repository already has an equivalent convention. Reuse existing project artifacts instead of creating duplicates.
Universal rules
- Read all applicable
AGENTS.md and AGENTS.override.md files before work.
- Inspect repository structure, documentation, manifests, tests, CI, deployment configuration, and Git state.
- Work on exactly one
READY task at a time unless a recorded parallel plan exists.
- Define testable acceptance criteria before implementation.
- Preserve unrelated user or agent changes.
- Avoid unrelated refactors and unexplained file modifications.
- Ask for approval before major architecture changes, scope expansion, destructive Git operations, or new production dependencies.
- Never claim a command passed unless it was actually run and succeeded.
- Record failed checks, blockers, uncertainty, and skipped validation explicitly.
- Never store secrets, tokens, credentials, sensitive personal data, private customer data, or unredacted production logs in tracked state files.
- Never use this workflow to bypass access controls, account restrictions, or usage limits.
Classify evidence
When reconstructing state or resolving contradictions, label important claims as:
- VERIFIED: confirmed by repository content, Git history/state, successful commands, tests, or authoritative project artifacts.
- REPORTED: stated by the user or conversation but not independently verified.
- INFERRED: a reasoned interpretation requiring confirmation.
- UNKNOWN: not recoverable from available evidence.
Never promote REPORTED or INFERRED information to VERIFIED without evidence.
Run the single-chat control loop
Use one Codex chat for planning, coding, debugging, review, and handoff unless parallelism is justified.
- Orient: read instructions and durable state; inspect Git.
- Plan: identify objective, scope, non-goals, dependencies, risks, acceptance criteria, and the highest-priority
READY task.
- Approve: in Guided mode, wait for approval before implementation.
- Implement: modify the minimum necessary files for one task.
- Verify: run the cheapest relevant checks first, then required lint, type checks, tests, build, and security checks.
- Review: inspect the diff for bugs, regressions, edge cases, security issues, weak error handling, missing tests, documentation drift, and unrelated changes.
- Fix: correct confirmed findings and rerun relevant validation.
- Checkpoint: update durable state with factual results.
- Report: state what changed, why, affected files, commands actually run, exact results, remaining risks, and the proposed next task.
- Stop or continue: stop in Guided mode; continue only through approved tasks in Autonomous mode.
Read references/SINGLE_CHAT_WORKFLOW.md for reusable prompts.
Adopt an existing long project or chat
When the current conversation already contains substantial history:
- Do not restart the project or rewrite working code.
- Do not begin a new implementation task.
- Perform read-only inspection of:
- applicable repository instructions;
- repository structure and documentation;
- current branch and HEAD;
git status --short --branch;
- unstaged and staged diffs;
- recent relevant commits;
- tests, build scripts, CI, configuration, and deployment files;
- decisions and progress visible in the current conversation.
- Reconstruct actual state using
VERIFIED, REPORTED, INFERRED, and UNKNOWN.
- Merge useful existing documentation rather than overwriting it.
- Create or update the selected durable-state profile.
- Report completed functionality, unfinished work, uncommitted changes, known or suspected bugs, validation status, contradictions, and the proposed next
READY task.
- Stop for approval before modifying product code.
Do not run git reset --hard, git clean -fd, git checkout ., destructive migrations, or equivalent cleanup during adoption without explicit approval and a recovery path.
Read references/ADOPT_EXISTING_PROJECT.md for the full prompt.
Plan tasks
For each non-trivial task, record:
- unique task ID;
- objective and user value;
- status:
PLANNED, READY, IN_PROGRESS, BLOCKED, REVIEW, or DONE;
- dependencies;
- testable acceptance criteria;
- expected affected areas;
- validation commands;
- owner/branch when relevant.
Mark a task READY only when it is sufficiently specified and unblocked. Record unresolved business rules as blockers instead of guessing.
Implement and verify one task
- Reconcile durable state with current Git state.
- Select one
READY task.
- Implement the smallest complete change satisfying its acceptance criteria.
- Run relevant validation and record exact pass/fail results.
- Inspect the actual diff before reporting completion.
- Preserve unrelated changes and do not silently reset, stash, merge, or overwrite another workstream.
Review and debug
Review against acceptance criteria and actual diff. Rank findings by severity. Check:
- functional correctness and regressions;
- edge cases and input validation;
- error handling and observability;
- security, privacy, and secret exposure;
- test coverage and false-positive tests;
- configuration, deployment, and documentation drift;
- unnecessary complexity or unrelated changes.
Verify a suspected issue before changing code. After fixes, rerun the narrow failing check and the relevant broader suite.
Create a handoff
Create a handoff before ending a long session, when context quality degrades, when switching sessions/devices, or when another authorized agent will continue.
Record:
- repository path;
- branch/worktree and HEAD commit;
- Git status and changed files with rationale;
- active task and acceptance criteria;
- completed and unfinished work;
- commands run with exact results;
- blockers, risks, and uncertainty;
- decisions made;
- exact next action;
- exact first command for the next session.
Do not perform destructive cleanup merely to make the handoff appear clean.
Read references/HANDOFF_RESUME.md for prompts.
Resume in a fresh session
- Read applicable instructions and durable state.
- Inspect Git and compare it with the handoff.
- Flag discrepancies instead of guessing.
- Run the documented first verification command when safe.
- Summarize reconstructed evidence before editing code.
- Continue only the documented active task or next
READY task.
- Ask the smallest necessary clarification when critical information is missing.
Coordinate optional parallel work
Use multiple chats/worktrees only when tasks are genuinely independent.
- Assign one task, branch/worktree, and file boundary per agent.
- Record ownership, acceptance criteria, dependencies, and integration order before implementation.
- Avoid concurrent edits to the same files without an explicit integration plan.
- Use a designated integrator for combined validation and merge decisions.
Read references/MULTI_AGENT_WORKFLOW.md for details.
Completion standard
Mark a task DONE only when:
- acceptance criteria are satisfied;
- required checks were executed and recorded;
- behavior, documentation, and durable state are consistent;
- no unexplained changes remain;
- remaining risks are explicit;
- the next project state is unambiguous.
Report to the user
After each implementation task, report:
- what changed;
- why it changed;
- files affected;
- acceptance-criteria status;
- commands actually run and exact results;
- unresolved risks or blockers;
- durable-state updates;
- proposed next action.