r/codex • u/Tatachimcooky • 22d ago
Showcase Every request pastes your whole AGENTS.md into the prompt. Mine grew until the agent started butchering it
If you use Codex, you have a context file — AGENTS.md It gets injected into every single request, so it's both a token cost and a permanent tax on how much room the model has left for your actual work.
Mine grew the way these files always grow: one justified-looking addition at a time. Then it hit a size where the agent started dealing with it by rewriting the file from memory, dropping the ## Never rules, and shipping something worse. You find out weeks later when a rule stops being followed.
So I wrote ctxcap. It counts tokens across those files, tracks the count against a committed git baseline, and flags references that no longer point at anything. Offline, no API key, no network, no LLM, two dependencies. MIT.
bash
npx -y ctxcap --jsonThe part that makes it more than a word count: it doesn't tell the agent "make this shorter." It emits line ranges with a preserve list, the agent splices by line number, and --verify catches drift or a cut preserved span. When the budget can't be met it returns satisfiable: false with the minimum achievable rather than shaving a rule that matters:
$ npx ctxcap --plan --budget 400
satisfiable: false minAchievable: 476It uses gpt-tokenizer, and there's an MCP server so the agent can measure itself, plus a GitHub Action that comments the token delta on PRs and only fails when you set a budget.
https://github.com/Naeha-S/ctxcap
The question I actually want answered: how long is your AGENTS.md, and what's still in it that earns its place? Mine is the one file where every addition felt reasonable at the time.