Skip to content

Make Codex Run Autonomously for Hours: A Practical Guide

I was frustrated. Every time I tried to use Codex for a complex task, it would stop halfway through and ask me a question. Or worse, it would pause at a “checkpoint” waiting for my approval. My coding sessions were getting fragmented, and I was spending more time babysitting the AI than actually getting work done.

Then I saw a Reddit post that changed everything. Someone reported Codex running autonomously for 7 hours and 44 minutes on a single task. Another user claimed 6 days of continuous operation. What were they doing differently?

The Three-Element Formula

After digging through user reports and testing extensively, I found that long-running autonomous sessions require three specific elements:

  1. Explicit prompt instructions telling Codex to continue without stopping
  2. A detailed todo document with built-in validation steps
  3. Higher reasoning modes (High or xHigh) for complex tasks

Miss any one of these, and you’ll get interruptions. Get all three right, and you can walk away for hours.

Element 1: Prompt Engineering for Autonomy

Codex defaults to collaborative behavior. It asks clarifying questions. It pauses at checkpoints. This is usually helpful, but it kills autonomous operation.

You need to explicitly override this behavior in your prompt:

autonomous-prompt.md
# Autonomous Task Execution Mode
You are operating in autonomous mode. Follow these rules:
1. **No stopping**: Continue until all todos are complete
2. **No questions**: Make reasonable assumptions based on context
3. **Self-validate**: Run all tests after each change
4. **Iterate**: If a fix doesn't work, try another approach
5. **Document**: Update progress in this file
## Current Task
[Your task description here]
## Todo Checklist
[Your todo items here]
## Completion Criteria
[Definition of done here]

The key phrase is “make reasonable assumptions.” Without this, Codex will default to asking for clarification on every ambiguity.

Element 2: Structured Todo Documents

A plain list of tasks won’t cut it. You need a structured document that includes self-validation steps. Here’s a pattern that works:

fix-auth-regression-todos.md
## Task: Fix Authentication Regression
### Phase 1: Investigation
- [ ] Search codebase for authentication-related files
- [ ] Identify recent changes that could affect auth flow
- [ ] Document root cause in this file
### Phase 2: Implementation
- [ ] Create fix in affected files
- [ ] Add defensive checks for edge cases
- [ ] Update related documentation
### Phase 3: Validation
- [ ] Run unit tests: `npm test`
- [ ] Run integration tests: `npm run test:integration`
- [ ] Run E2E tests: `npx playwright test`
- [ ] Verify CI pipeline passes
- [ ] Check for regressions in auth-related features
### Phase 4: Cleanup
- [ ] Remove any debug code added
- [ ] Update CHANGELOG
- [ ] Verify all tests still pass
### Definition of Done
All tests pass, CI is green, no regressions detected.

Notice the validation phase. This is critical. Codex needs commands it can run to verify its own work. Without these, it has no way to know if a change succeeded.

The Validation Loop Pattern

The most effective todo documents include executable validation:

validation-commands.sh
# Run after each code change
npm run lint && npm test && npm run build
# For frontend changes
npx playwright test --project=chromium
# For API changes
npm run test:api && npm run test:integration

When Codex hits a failing validation, it knows to iterate rather than stop.

Element 3: Reasoning Mode Selection

Not all tasks need the same reasoning level. Here’s what I’ve found works:

ModeBest ForExpected Duration
StandardQuick fixes, simple tasksMinutes
HighComplex refactoring, feature implementation1-2 hours
xHighArchitecture changes, multi-file modifications2-8+ hours

The higher reasoning modes enable better self-correction. When Codex encounters an error in High or xHigh mode, it analyzes the problem more deeply and generates alternative approaches.

What Users Are Reporting

Here’s what developers are achieving with these techniques:

DurationContext
2 hours”Fixed a regression autonomously”
7h 44minLongest single session reported
18 hoursExtended autonomous operation
6 daysMulti-session continuous work

The pattern is consistent: users who provide structured todos with validation steps get the longest autonomous runs.

Environment Preparation

Before starting a long session, I do these checks:

  1. Clear context window — Start fresh to maximize available tokens
  2. Stage dependencies — Ensure packages, tools, and access are ready
  3. Monitor progress — Set up logging so I can see what Codex is doing
session-prep.sh
# Clear any previous context
codex session clear
# Verify dependencies are installed
npm install && npm run build
# Set up progress logging
codex config set logging enabled true
codex config set logging level debug

Common Mistakes That Kill Autonomy

Mistake 1: Vague Completion Criteria

Bad:

- Fix the bug
- Make tests pass

Good:

- Fix the bug in src/auth/login.ts
- All tests in npm test must pass
- CI pipeline must be green
- No regressions in auth flow

Specificity matters. Codex needs to know exactly when it’s done.

Mistake 2: Missing Validation Commands

If your todos don’t include commands to run, Codex can’t verify its own work:

# Bad: No way to verify
- [ ] Fix the component
# Good: Verifiable
- [ ] Fix the component
- [ ] Run `npm test -- ComponentName` and ensure all pass
- [ ] Run `npm run lint` and fix any issues

Mistake 3: Using Low Reasoning Mode for Complex Tasks

I tried running a 4-hour refactoring task in Standard mode. Codex got stuck in a loop, making the same mistakes repeatedly. After switching to High mode, it completed successfully.

The reasoning mode determines how deeply Codex analyzes failures. Higher modes mean better self-correction.

The Complete Setup

Here’s my template for any long-running autonomous task:

autonomous-task-template.md
# Autonomous Task: [Task Name]
## Instructions
Continue working until all todos are complete.
Do not stop to ask questions.
Do not wait for confirmation at checkpoints.
Make reasonable assumptions and proceed.
## Task Description
[Detailed description of what needs to be done]
## Context
- Relevant files: [list key files]
- Dependencies: [list dependencies]
- Constraints: [any constraints or requirements]
## Todo Checklist
### Investigation
- [ ] [Investigation step 1]
- [ ] [Investigation step 2]
### Implementation
- [ ] [Implementation step 1]
- [ ] [Implementation step 2]
### Validation
- [ ] Run `[command 1]` and ensure pass
- [ ] Run `[command 2]` and ensure pass
- [ ] Verify [specific criteria]
### Cleanup
- [ ] Remove debug code
- [ ] Update documentation
- [ ] Final validation: `[final command]`
## Definition of Done
[Specific, measurable criteria for completion]
## Notes
[Space for Codex to document progress]

When It Doesn’t Work

These techniques won’t help if:

  • Your task requires external input — If you need user decisions mid-task, autonomy is impossible
  • Your validation is flaky — Intermittent test failures will confuse Codex
  • Your scope is too large — Even with good structure, there are limits to what can be done autonomously

I’ve found that tasks taking 6-8 hours of focused human work translate well to autonomous Codex sessions. Beyond that, break it into smaller tasks.

Bottom Line

Autonomy isn’t automatic. You need to explicitly configure for it:

  1. Tell Codex to continue without stopping or asking questions
  2. Provide structured todos with executable validation steps
  3. Use appropriate reasoning modes for task complexity

With proper setup, 2-8 hour autonomous sessions are achievable. The longest reported run is 6 days. Your mileage will vary, but the pattern is clear: structure and explicit instructions unlock long-running autonomous operation.

Final Words + More Resources

My intention with this article was to help others share my knowledge and experience. If you want to contact me, you can contact by email: Email me

Here are also the most important links from this article along with some further resources that will help you in this scope:

Oh, and if you found these resources useful, don’t forget to support me by starring the repo on GitHub!

Comments