Make Codex /goal runs stop drifting.
Codex /goal can run for a long time, but the objective is short and easy to overinterpret. This repo gives Codex a better operating pattern: write the real goal into GOAL.md, put durable loop rules in AGENTS.md, and launch /goal with a short command that points at those files.
Inside Codex:
/skills install --repo rendrag-git/codex-goal-loop --path .
Restart Codex after installation.
Then ask:
Use the goal-loop skill to help me write GOAL.md and the /goal command for this repo.
The skill helps you write GOAL.md first, then gives you a short /goal command.
Recommended command shape:
/goal Pursue the current goal in GOAL.md under the Goal-Loop Conventions in AGENTS.md. Re-read GOAL.md before each iteration, keep its state concise, verify before checking acceptance items, and call update_goal complete only when every acceptance item is proven with evidence.
That command should stay short. The full spec belongs in GOAL.md, not in the slash command.
Codex /goal turns a thread into a self-continuing loop. After every idle turn, Codex injects a continuation prompt and keeps going until the goal is complete, budget-limited, paused, cleared, interrupted, or plan mode suppresses continuation.
The loop has two common failure modes:
- The objective text is wrapped as task data. It can still steer the model, but durable rules belong in
AGENTS.md. - The loop follows the last piece of evidence. Without a state file, it can keep polishing a local artifact while the real product target stalls.
This pattern fixes both.
Add three things to the repo you want Codex to work in:
-
Goal-loop rules in
AGENTS.mdCodex re-reads project instructions. Durable loop rules go there. -
A structured
GOAL.mdThis is the source of truth for the outcome, non-goals, acceptance criteria, blockers, and evidence. -
A short
/goalcommand The command points atGOAL.mdandAGENTS.md. It does not restate the full spec.
The installed skill can do this for you.
- Reads repo docs before asking questions.
- Helps write or repair
GOAL.md. - Produces a short
/goalcommand that does not conflict with the docs. - Adds goal-loop conventions to
AGENTS.md. - Keeps
GOAL.mdas a state tracker, not an action log. - Checks that completed acceptance items have evidence.
- Supports optional SQLite state for users who do not use Linear.
- Explains token budgets and stopped-loop behavior.
Instead of this:
/goal Build the app, keep working until it is fully done, make sure tests pass, update docs, track everything, do not forget deployment, do not drift...
Use this:
/goal Pursue the current goal in GOAL.md under the Goal-Loop Conventions in AGENTS.md. Re-read GOAL.md before each iteration, keep its state concise, verify before checking acceptance items, and call update_goal complete only when every acceptance item is proven with evidence.
Then put the real detail in GOAL.md:
## Required Capabilities
1. **CAP-1: Working user path**
Acceptance:
- [ ] CAP-1.1 User can complete the happy path.
- [ ] CAP-1.2 Failure cases show clear errors.
- [ ] CAP-1.3 Verification command passes and is recorded in Progress.More examples:
Users without Linear can mirror goal state into a local SQLite DB:
python3 scripts/goal_loop.py init-db --db .goal-loop/state.sqlite
python3 scripts/goal_loop.py import-md --goal GOAL.md --db .goal-loop/state.sqlite
python3 scripts/goal_loop.py audit --goal GOAL.md --db .goal-loop/state.sqliteKeep .goal-loop/ gitignored in the target repo. SQLite is a local machine-readable mirror. GOAL.md remains canonical if they disagree.
The /goal slash command does not expose token_budget. Use a normal chat instruction:
Use the create_goal tool. objective: "Pursue the current goal in GOAL.md under the Goal-Loop Conventions in AGENTS.md. Re-read GOAL.md before each iteration, keep its state concise, verify before checking acceptance items, and call update_goal complete only when every acceptance item is proven with evidence." token_budget: 2000000.
create_goal fails if the thread already has an active goal. Use a fresh thread, or clear, pause, or reset the existing goal first.
Run:
python3 scripts/goal_loop.py audit --goal GOAL.mdThe audit catches common problems:
- checked items without evidence
- missing Bridge notes
- verbose Progress entries
- SQLite and
GOAL.mdstatus mismatches
Then ask Codex:
Use the goal-loop skill to repair this GOAL.md before continuing the /goal run.
Copy-paste launch posts are in docs/share-posts.md.
MIT.