Skip to content

Learn from the Constraint (Codex CLI)

Large context windows can feel like a ceiling. In practice, they're a training ground: working under limits forces you to curate inputs, structure tasks, and reset context deliberately—skills that make Codex faster, cheaper, and more reliable. OpenAI's own guidance emphasizes steering agents with project docs and approvals rather than "dumping everything" into the window. (OpenAI)


The training effect

Operating under token budgets develops fundamentals:

  • Explicit file selection. Include only what Codex needs; avoid whole-repo dumps. Codex is designed to be guided by a concise AGENTS.md that spells out rules, commands, and project norms. (OpenAI)
  • Clear task definition. Ask for concrete steps and a rationale first (plan), then approve execution (do) via approval modes. (OpenAI)
  • Context-sized chunking. Break a big objective into smaller passes; reset or compact conversation state between phases. (OpenAI notes compaction support to help long sessions.) (OpenAI)
  • Compact examples. Provide minimal, representative examples and counter-examples in AGENTS.md. (GitHub)
  • Priority-first ordering. Put must-follow rules and critical files first; defer nice-to-have context.

These habits translate directly to better adherence and lower costs because pricing is per-token—less noise means less spend. (OpenAI)


Why less context can perform better

Peer-reviewed work shows LLMs struggle as contexts grow cluttered: accuracy drops when key details sit "in the middle," and retrieval gets brittle as haystacks grow. In other words, longer isn't automatically better—signal-to-noise and placement matter. Use small, targeted contexts and fresh sessions when needed. (ACL Anthology)


A Codex pattern to practice

  1. Pin the rails. Put invariants and boundaries in AGENTS.md (e.g., what files to touch, how to test, forbidden edits). Ask Codex to read it at session start. (OpenAI)
  2. Plan before you run. Start in Read-only approval mode to get a numbered plan and risk/rollback. Approve only the step you're ready to execute. (OpenAI)
  3. Work in passes. Execute a small diff, run tests, then either continue or compact/reset the thread to keep context lean. (OpenAI)
  4. Audit token spend. Fewer files + shorter messages = fewer tokens (and dollars). Treat pricing as a feedback signal to simplify prompts and examples. (OpenAI)

Skills that scale

  • Identify essentials and aggressively filter the rest.
  • Encode process once in AGENTS.md; reuse across sessions and teammates. (GitHub)
  • Separate project-specific context (your docs, tests, scripts) from general knowledge the model already has.
  • Choose examples strategically to teach patterns, not exhaust cases.

These skills make you more effective even when context windows grow, because you'll keep signal high and iteration tight. (ACL Anthology)


The paradox

Unlimited context can breed sloppy habits (oversharing, vague asks, reliance on the model to sift noise). Teams that embrace constraints become sharper collaborators: they write better AGENTS.md, plan first, and ship more reliable diffs with fewer tokens. Codex's design—project docs + approvals + compaction—rewards exactly that discipline. (GitHub)


Sources

  • Introducing Codex (project-doc guidance; AGENTS.md). (OpenAI)
  • AGENTS.md (official repo) — "README for agents." (GitHub)
  • Introducing upgrades to Codex (approval modes; compaction for long sessions). (OpenAI)
  • Lost in the Middle (long-context degradation). (ACL Anthology)
  • Needle-in-a-Haystack overview (long-context retrieval testing). (Arize AI)
  • OpenAI Pricing (per-token cost model). (OpenAI)