Skip to content

AGENTS.md is silently truncated without any warning within the TUI #7138

Closed as not planned

Description

@guidedways

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!

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

Activity

  1. added
    bug
    on Nov 22, 2025
  2. added
    enhancement
    TUI
    on Nov 22, 2025
  3. added a commit that references this issue on Nov 22, 2025
    cf5d52a
  4. etraut-openai commented on Nov 22, 2025

    @etraut-openai
    Contributor

    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.

  5. guidedways commented on Nov 22, 2025

    @guidedways
    ContributorAuthor

    @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.md which 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_bytes set to 80kb it now fixes this for me but this resulted in numerous other issues as you can see.

  6. etraut-openai commented on Nov 22, 2025

    @etraut-openai
    Contributor

    At the very least, we should document the AGENTS.md behavior more clearly.

  7. duckSquirrelPilot commented on Nov 22, 2025

    @duckSquirrelPilot

    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.

  8. CarloWood commented on Nov 23, 2025

    @CarloWood

    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.

    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:

    AGENTS.override.md -this file- is the authoritative set. Follow this and ignore AGENTS.md in the same directory.
    

    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:

    ### Additional instructions
    
    - If a file exists in the root of the project with the name `README-<current_branch>.md` then follow the instructions inside of it as well.
      Instructions in that file are more important than those in this file, because they are specific to what is being worked on at this moment.
    

    allowing me to add instructions / explanations per-(feature)-branch.

  9. nos1609 commented on Nov 25, 2025

    @nos1609

    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.md and 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 .md files.

    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.md taking up to 80% of the context, leaving only ~20% for a single “shot”, rather than having to rely on these workarounds.

  10. nwalke commented on Nov 26, 2025

    @nwalke

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

    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.

  11. jonahdk commented on Nov 30, 2025

    @jonahdk

    @nwalke If you don't use -cd <dir>, then whatever directory you're in when you start Codex

  12. nwalke commented on Nov 30, 2025

    @nwalke

    Edit: 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.

    • The search starts at the repository root and continues down to your current directory. If a Git root is not found, only the current directory is checked.
    • In each directory along that path, Codex looks for AGENTS.override.md first, then AGENTS.md, and then any fallback names listed in your Codex configuration (see project_doc_fallback_filenames). At most one file per directory is included.
    • 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 limit). If you need more space, split guidance across nested directories or raise the limit in your configuration.

    Apologies for the noise :)

  13. removed
    bug
    on Dec 1, 2025
  14. etraut-openai commented on Mar 2, 2026

    @etraut-openai
    Contributor

    This feature request hasn't received any upvotes in three months, so I'm going to close.

  15. guidedways commented on Mar 3, 2026

    @guidedways
    ContributorAuthor

    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.

  16. CarloWood commented on Mar 3, 2026

    @CarloWood

    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 in R/S/T/ then I understand that the Codex CLI catenates R/AGENTS.md + empty line + R/S/AGENTS.md + empty line + R/S/T/AGENTS.md. If the total of that size goes over project_doc_max_bytes then 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?

  17. jonahdk commented on Mar 3, 2026

    @jonahdk

    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.

  18. guidedways commented on Mar 3, 2026

    @guidedways
    ContributorAuthor

    @etraut-openai can the decision to close this issue be reconsidered?

  19. guidedways commented on Mar 3, 2026

    @guidedways
    ContributorAuthor

    @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.md is terrible UX for the end-user.

  20. etraut-openai commented on Mar 3, 2026

    @etraut-openai
    Contributor

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

  21. guidedways commented on Mar 3, 2026

    @guidedways
    ContributorAuthor

    @etraut-openai thank you! I'll try and re-word in the process, and hope that it attracts more eyeballs this time 👀

  22. guidedways commented on Mar 3, 2026

    @guidedways
    ContributorAuthor

    Dear upvoters of the current issue, please unleash a flurry of votes here: #13386

    😅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    TUIenhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions