`AGENTS.md` is silently truncated without any warning within the TUI
What version of Codex is running?
0.63.0
What subscription do you have?
Pro
Which model were you using?
gpt-5.1-codex-max extra high
What platform is your computer?
macOS
What issue are you seeing?
I always thought whatever I add to AGENTS.md is consumed as-is by codex. I kept noticing that it's ignoring core instructions I've appended to my document (AGENTS.md for me is quite large, around 40kb - that's okay because the project requires specific instructions and I'm alright with losing context tokens because the work I perform for this one repo is very specific and I'm left with 93% with ~40kb of tokens).
After looking at the source code I stumbled upon:
/// Maximum number of bytes of the documentation that will be embedded. Larger
/// files are *silently truncated* to this size so we do not take up too much of
/// the context window.
pub(crate) const PROJECT_DOC_MAX_BYTES: usize = 32 * 1024; // 32 KiB
in [src/config/mod.rs](/core/src/config/mod.rs)!
It seems I completely missed out on the project_doc_max_bytes config.toml setting, this can be customized but I wasn't aware.
What steps can reproduce the bug?
Create a large AGENTS.md > 32kb
What is the expected behavior?
TUI should warn me within /stats next to the AGENT.md - silently truncating the text is bad UX. In comparison, Claude Code very visibly and clearly warns you when CLAUDE.md is too large (the moment you launch the CLI).
Additional information
_No response_
18 Comments
Thanks for the feature request. If we add this, we'll need to figure out how to surface this across all surfaces including the TUI,
exec, and VS Code extension.@etraut-openai thank you - it's difficult to classify this as a feature, it probably also is not a bug but it does indeed _lead_ to bugs. Primarily, for weeks I was under the impression codex isn't adhering to instructions given in AGENTS.md and I kept repeating myself within each session start, only to find out that codex silently truncates
AGENTS.mdwhich means important instructions are being clipped / dropped off and codex continues to do the wrong thing when applying fixes (our instructions include specific commands of running and inspecting unit tests and it would get these wrong 100% of the times).With
project_doc_max_bytesset to 80kb it now _fixes_ this for me but this resulted in numerous other issues as you can see.At the very least, we should document the AGENTS.md behavior more clearly.
Yes, that would be helpful. On that front, I'll note that there are probably 5 separate documents (some on github, some on openai.com) that describe AGENTS.md, all slightly different and none of them being clearly the authoritative comprehensive version. Also, I personally find http://agents.md/ pretty useless as a source of information so am a little annoyed how often it's referenced in the docs as a place to find more detailed information. What the user wants to know is specifically how AGENTS.md is handled in the codex harness (e.g. this very important truncation parameter), not the generic philosophy behind it.
I'm also not authoritative but here's what I understand on how this works:
If codex is started in a sub-directory of the repository, or you use the
-cd <dir>option (/status reports it as Directory), then CLI searches that cwd and all directories down to the root of the project, in that order, for AGENTS.override.md and if that doesn't exist for AGENTS.md (per directory).You can copy the roots AGENTS.md to AGENTS.override.md and then edit it to be more like what you need/want (maybe make it shorter). That file is already in .gitignore
I start mine with:
just to be sure - but that is how it should already be.
I am not sure of the 32kB truncation is per-file or for all AGENTS*.md's combined. If it is per file you can use the above to split it up in multiple AGENTS.md files with instructions limited to those specific to that (sub)directory.
You should also be able to add a $CODEX_HOME/AGENTS.md (the default of CODEX_HOME being ~/.codex). For even more general instructions that apply to every project.
I noted that the following works:
allowing me to add instructions / explanations per-(feature)-branch.
Wow, I didn’t even realize it currently works this way — thank you, @guidedways, for surfacing it.
The only workaround I’ve found so far is to explicitly reference important sub-Markdown files from
AGENTS.mdand then ask Codex to read them during bootstrap.This approach slows down the initial response to up to ~10 minutes on a context-dense project, but at least everything gets loaded without truncation into the context window, and Codex actually pays attention to those referenced
.mdfiles.However, when the context usage reaches around ~30% and ~50%, some background compaction seems to happen, and I have to ask it to re-read those initial instructions again, because Codex starts to “forget” the essential parts of
AGENTS.md(for me, they’re indispensable).The worst case scenario is when the context window is ~85% full: the session basically “resets” during the answer, like a Groundhog Day wake-up. Hopefully it re-reads every instruction from the beginning, again, but from the user’s perspective it feels like starting over.
Honestly, I’d be totally fine with
AGENTS.mdtaking up to 80% of the context, leaving only ~20% for a single “shot”, rather than having to rely on these workarounds.How does codex know what the "root of the project" is? What if I start codex in a random directory that isn't a git repo, does it just go up the file tree until it's at
/? That seems unlikely.@nwalke If you don't use
-cd <dir>, then whatever directory you're in when you start CodexEdit: I went back and re-read the doc that was added last month. I must have completely spaced on this as it answers my question.
Apologies for the noise :)
This feature request hasn't received any upvotes in three months, so I'm going to close.
I think the existing upvotes were hoping this would get resolved 😅 This is one of those 'hidden' bugs many aren't even aware of, so perhaps a lot of people running into this just feel their AGENT.md is sometimes being ignored.
Files are read in order from root to leaf and joined together with blank lines. Empty files are skipped, and very large files are truncated once the combined size reaches 32 KiB (the default [project_doc_max_bytes](https://github.com/openai/codex/docs/config.md#project_doc_max_bytes) limit). If you need more space, split guidance across nested directories or raise the limit in your configuration.This seems to be a contradiction. Lets say
R/is the root of the project and you start Codex inR/S/T/then I understand that the Codex CLI catenatesR/AGENTS.md+ empty line +R/S/AGENTS.md+ empty line +R/S/T/AGENTS.md. If the total of that size goes overproject_doc_max_bytesthen this is silently truncated (yup, no idea why that has to be silent due to a "lack of votes" - you could also just fix it). The result is sent upstream as system message.Then "if you need more space use nested directories". Huh? Those are catenated, so how is that helping?
I agree - truncating AGENTS should not be silent. If AGENTS is large, it's because the user wants to give the agent more instructions. Honestly, I feel it shouldn't be truncated at all, but if it's going to, there absolutely needs to be a warning.
@etraut-openai can the decision to close this issue be reconsidered?
@etraut-openai another point, recently I saw you push a change where the prompt was limited to 1MB (to match the max context window size - given larger prompts just don't make sense) - a fix to this would simply compliement that commit; I fear silently trimming
AGENT.mdis terrible UX for the end-user.@guidedways, you can open a new feature request if you'd like. As you know, we generally prioritize feature requests based on upvotes. If a feature request doesn't get enough upvotes or receives no upvotes in a long time, that means it's either not a high priority for the Codex community or the description of the feature request wasn't compelling enough to attract upvotes. By opening a new feature request, you can give it a new title and description and see if that might attract more upvotes.
@etraut-openai thank you! I'll try and re-word in the process, and hope that it attracts more eyeballs this time 👀
Dear upvoters of the current issue, please unleash a flurry of votes here: https://github.com/openai/codex/issues/13386
😅