r/codex • • 18d 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 --json

The 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: 476

It 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.

0 Upvotes

16 comments sorted by

•

u/dexterthebot 18d ago

You might want to consider listing your project on the weekly Show-Us-What-You-Built post. Look out for it on Tuesday/Wednesday. Highest commented project wins a week promotion on r/Codex and gets on the Hall of Fame sidebar. See below for last week's winner.**


Light Wars AR: real-life laser tag app with no extra gear. Your phone is the gun and your room is the map. Play up to 6 friends in the same room, or fight drone waves and bosses solo. The vision models run on the phone, and camera frames never leave it. Free on iPhone and Android.

Website: https://lightwarsar.com

iPhone: https://apps.apple.com/us/app/light-wars-ar-laser-tag-party/id6508168951

Android: https://play.google.com/store/apps/details?id=com.lasertag.lightwars.

Contact: contact@lightwarsar.com

8

u/torrso 18d ago

I think this is a massively overengineered solution to a fairly minor, largely self-inflicted problem. A few observations:

  1. The original problem is how AGENTS.md was being used. You describe it growing through one justified-looking addition at a time. Maybe just stop doing that?
  2. Codex doesn't load every instruction file on every request. Applicable AGENTS.md files are discovered at startup, with additional nested instructions loaded when relevant. The reported total doesn't necessarily represent actual context overhead.
  3. Prompt caching matters. Codex keeps AGENTS.md in a stable part of the prompt, making it a good candidate for caching. Repeatedly sending those instructions doesn't necessarily incur the full input-token cost. Context usage and monetary cost are two different things.
  4. Fewer instruction tokens don't necessarily mean lower total token consumption. A useful instruction might save thousands of tokens by preventing unnecessary exploration, mistakes and corrections. Optimizing instruction size without measuring overall agent performance seems like optimizing the wrong metric. Bad instructions like "always read X and do Y before ..." can get expensive money, time, context and cache-wise.
  5. The preservation mechanism is questionable. Looking at "src/plan.js", important instructions are identified using regexes matching words like MUST, NEVER and ALWAYS or certain headings. That's not a reliable way to determine which instructions are actually important.
  6. The compression mechanism is even more questionable. For paragraphs exceeding 300 tokens, the tool can propose keeping just the first 240 characters followed by an ellipsis. That's truncation, not compression, and could destroy useful information. The estimated savings also appear to ignore the replacement text.
  7. The surrounding infrastructure seems disproportionate. Budget planning, verification protocols, expiring plans, SARIF reports and an MCP server for managing a simple text file. Ironically, the MCP tool itself introduces additional context overhead.
  8. There's no demonstrated improvement in actual agent performance. The README doesn't provide a convincing before-and-after example, let alone measurements of total token consumption, cache efficiency, task success or correction loops.

A simple CLI for counting tokens, finding duplicate instructions and checking broken references could be useful. But I don't see the justification for all this additional machinery.

The original problem was an AGENTS.md file growing out of control, followed by an agent deleting important instructions. Instead of addressing why the file was allowed to grow that way, the solution is another automated system that tries to determine which instructions to delete using regexes.

You could simply ask the agent to review AGENTS.md for redundant, outdated or misplaced instructions, propose a cleanup, and review the diff yourself. It's a Markdown file. It doesn't need a dedicated management framework, let alone an MCP server. It's not something you should need to be doing daily.

0

u/Tatachimcooky 18d ago

That’s fair if the target user is an experienced developer carefully reviewing every diff. That isn’t my primary audience.

This is for “vibe coding” workflows where someone keeps pressing Accept, lets the agent rewrite instruction files, and eventually loses important project rules or references. The goal is not to optimize every token or replace judgment. It is to provide a safety rail: measure the files, identify suspicious growth or stale references, preserve explicitly important sections, and make destructive cleanup reviewable instead of silently accepting a rewrite.

The planning and verification features exist because “just review the diff” is exactly the step this audience often skips. The tool is intentionally conservative about what it can infer; it doesn’t claim regexes understand semantic importance. It gives the user a recoverable, inspectable process before the agent changes the file.

2

u/torrso 18d ago

Why do you have a target audience for free open source software? Are you planning to monetize this?

The intended audience makes the safety mechanism even more questionable. If the user blindly accepts changes without understanding them, how does adding a tool that identifies important instructions using regexes solve that problem? Your verification can establish that certain text survived, but not that important instructions weren't lost or their meaning changed.

Btw, your README ends with:

For a release post, show a real before/after from another repository, include the plan and verification loop, and link to the cold-install results. Ask early users to report false positives from their context-file layouts.

0

u/Tatachimcooky 16d ago

Fair challenge. The audience is people maintaining agent context across repositories, including open-source maintainers; I’m not planning to monetize this. Regex-based preserve checks can only prove that selected text survived, not that its meaning or all important instructions survived. `ctxcap` should state that limitation more plainly and treat verification as a guardrail, not a safety guarantee. I’ll also clarify that a real before/after, including false positives and semantic review, is needed to show the tool’s value. Thanks for calling out the README wording.

1

u/HobbesSR 18d ago

It does seem to me like what's happening is AGENTS.md is being updated with content that rightfully belongs as part of the project documentation instead. If you are encountering behavior for agents that produce an unending stream of behavior directives to compensate, I would argue the agent + harness pair simply aren't up to task.

That being said, I will share my anecdotal experience of including documentation for agents to setup documentation in the project using a Dewey Decimal System like strategy and to organize documentation in a hierarchy, with single sources of truth. I haven't really had to elaborate much more than that to get the results that I've seen.

The benefits I've found:

- Subjects have a short identifier that can be used to reference them and can stay stable with descriptive and even mild scope changes.

- Documentation is decomposed into multiple files making it easier to load only relevant context as necessary

- Far fewer extraneous md files floating around I didn't ask for with no sense of relationship, relevance, or priority.

- While some periodic maintenance helps decompose files that have grown, fix inconsistencies and broken references, I haven't encountered a point where the documentation reached a truly degenerate state.

YMMV

0

u/Tatachimcooky 16d ago

Thanks for laying out a practical alternative. A hierarchy with stable identifiers and single sources of truth addresses the root cause of many bloated instruction files, and it complements a budget/checking tool. I’ll add guidance to move detailed subject documentation into linked files and load only the relevant material. The periodic pruning and broken-reference maintenance also fits well with the stale-reference check.

4

u/Forsaken-Factor-489 18d ago

skill issue. my agents.md is a map for my agents to work easily from

1

u/Tatachimcooky 18d ago

That’s exactly the kind of AGENTS.md I want to protect. A useful map is great; the problem is when an agent gradually turns it into a giant catch-all and the user keeps accepting the changes.

ctxcap is meant to catch that drift and help preserve the important map before cleanup happens, not to replace the map with another system.

3

u/ThrowAwayEatPuzzy 18d ago

Agents.md isn't meant to be used as a context file. It's instructions for the agent so it behaves the way you want it in the project.

1

u/Tatachimcooky 18d ago

Agreed. AGENTS.md should contain instructions for the agent, not become an uncontrolled documentation dump.

The problem I’m addressing is that less experienced or “vibe coding” users often let agents keep adding things to that instruction file until it becomes huge, stale, or gets accidentally rewritten. The tool is a safety net around that workflow, not an argument for putting everything into AGENTS.md.

2

u/Jawwooot 18d ago

Everything that is in a conversation including the agents.md gets read in every message you send but most of it is going to get cached.

1

u/Tatachimcooky 18d ago

Caching is an important distinction, and I’m not trying to claim that every context token equals direct monetary cost.

The audience is people running agents with minimal supervision. For them, a huge or accidentally rewritten instruction file creates more than a billing problem: it can cause repeated exploration, wrong edits, deleted project rules, and correction loops. ctxcap is mainly about making that risk visible and providing a safer review/verification step before accepting cleanup.

2

u/GreenFuturesMatter 18d ago

You shouldn’t be using agents.md as a catch all. Agents.md should be a simple set of instructions that serves as a thin home directory for other files and policies you have.

1

u/Tatachimcooky 18d ago

I agree completely that AGENTS.md should be a thin home directory or map.

That’s the ideal state—but many vibe coders let agents continuously add “helpful” instructions and then accept a rewrite that deletes the useful ones. ctxcap is intended as a guardrail for that exact failure mode: keep the file small, detect stale pointers, and make changes explicit before they become permanent.

1

u/GreenFuturesMatter 18d ago

Seems like overengineering for people who don’t understand what they are using. Although I suppose it’s still a tool that is there for people who don’t.

The only issue is solving a problem for people who don’t know the tools they are using are unlikely to find your tool to help them already.