Building an Infinite Coding Agent
How we forked Codex CLI and added two flags that changed everything
What if your coding agent never stopped? What if, after completing a task, it automatically found the next thing to do and kept going indefinitely?
That's exactly what we built. By adding two simple flags to OpenAI's Codex CLI, we created an autonomous coding agent that runs forever—continuously improving your codebase, fixing bugs, adding features, and even brainstorming new ideas.
The Problem: Agents That Stop
Traditional coding agents work in a request-response pattern. You give them a task, they complete it, and they stop. Want more? You have to come back, think of the next task, and prompt them again.
This creates friction. The agent has all the context about your codebase. It knows what it just did. It could easily identify what to do next. But it waits for you.
The most productive developers aren't the ones who code fastest—they're the ones who never lose momentum.
The Solution: Two Powerful Flags
We forked the OpenAI Codex CLI and added two flags that fundamentally change how the agent behaves:
--auto-next-steps
After completing each task, automatically continue with testing, documentation, edge cases, and remaining work.
--auto-next-idea
After completing work, brainstorm and implement new improvements, optimizations, features, or address technical debt.
How It Works
The implementation is elegant. When the agent completes a response, instead of waiting for user input, it automatically queues a follow-up prompt:
// In chatwidget.rs - the auto-prompt logic
if self.auto_next_steps {
let auto_prompt = format!(
"Continue working autonomously on the natural next steps. \
Consider testing, documentation, edge cases, and remaining work.\n\n\
Previous work summary: {}",
summary
);
self.submit_text_message(auto_prompt);
} else if self.auto_next_idea {
let auto_prompt = format!(
"Brainstorm and implement new improvement ideas. \
Consider enhancements, optimizations, new features, \
or technical debt.\n\n\
Previous work summary: {}",
summary
);
self.submit_text_message(auto_prompt);
}
The key insight: we pass the summary of previous work into the next prompt. This maintains context and creates a coherent chain of improvements.
Running Forever
To run the agent in fully autonomous mode:
# Build the CLI
cargo build --release -p codex-cli
# Run with both flags for full autonomy
./codex --auto-next-steps --auto-next-idea --yolo3
# Or use the installed version
codex --auto-next-steps --auto-next-idea
The --yolo3 flag bypasses sandboxing and timeouts—essential for long-running autonomous operation. Use with caution (or in an isolated environment).
What Happens in Practice
When you launch an infinite agent on a real codebase, something magical happens:
- Initial task completes — "Add user authentication"
- Auto-next-steps kicks in — Agent writes tests for the auth system
- Continues autonomously — Adds error handling, input validation
- Auto-next-idea activates — "What if we added rate limiting?"
- Implements the idea — Adds rate limiting with tests
- Keeps going — Improves logging, adds metrics, refactors...
Left running overnight, the agent might make dozens of meaningful improvements. Each building on the last, each with full context of what came before.
The Swarm Effect
Here's where it gets interesting. Run multiple infinite agents on the same codebase:
# Terminal 1
codex --auto-next-steps "Focus on backend API improvements"
# Terminal 2
codex --auto-next-idea "Focus on frontend UX enhancements"
# Terminal 3
codex --auto-next-steps "Focus on test coverage and CI/CD"
Each agent works on its domain, making commits, and the others see and build upon those changes. It's like having a team of tireless developers working 24/7.
Safety Considerations
Running an agent forever requires trust. We recommend:
- Isolated environments — Run in containers or VMs
- Git safety net — All changes are commits you can revert
- Resource limits — Set token/API budgets
- Review cadence — Check in periodically on what it's done
- Good AGENTS.md — Give the agent clear guidelines
Try It Yourself
The code is open source. Clone our fork and start experimenting:
git clone https://github.com/lee101/codex
cd codex
cargo build --release -p codex-cli
./codex-rs/target/release/codex --auto-next-steps --auto-next-idea
Or use Codex Infinity's cloud platform to run infinite agents without managing infrastructure:
What's Next
We're working on:
- Smarter ideation — ML-guided prioritization of next tasks
- Cross-agent coordination — Agents that communicate and divide work
- Goal-oriented loops — "Keep improving until benchmarks hit X"
- Human-in-the-loop checkpoints — Pause for approval on major changes
The future of coding isn't just AI assistance—it's AI that never stops improving your code.
Want to run infinite agents in the cloud? Try Codex Infinity—we handle the infrastructure so your agents can run forever.
← Back to Home
Codex