feat: @include directive for composable AGENTS.md files
What variant of Codex are you using?
CLI
What feature would you like to see?
Add an @path/to/file.md directive to AGENTS.md that the CLI resolves at instruction-assembly time, inlining referenced file content before sending to the model. This enables modular, maintainable instruction sets - and direct interoperability with Claude Code, which already ships this exact syntax in CLAUDE.md.
The problem
Codex's instruction composition is limited to directory-walk layering: one AGENTS.md per directory level, concatenated root-to-cwd. This creates five concrete problems:
No modular reuse across projects. A developer working across 10+ repos with shared conventions must either duplicate content into each repo's AGENTS.md or maintain a single bloated ~/.codex/AGENTS.md that includes everything regardless of relevance.
No team-level instruction ownership. When different teams own different concerns (frontend style, security policy, deployment conventions), there's no way to split these into independently maintained files composed at load time. Everyone edits one file, merge conflicts ensue, instructions drift.
Cross-tool interoperability gap. Claude Code supports @path/to/file.md imports in CLAUDE.md plus an auto-loaded .claude/rules/ directory. Teams using both tools on the same projects must maintain parallel, divergent instruction files. This undermines AGENTS.md's role as an open cross-tool standard under the Linux Foundation / AAIF.
Dynamic instruction loading is impossible. As raised in #11838, the model cannot reliably follow "read this file next" directives embedded in instruction text - the CLI, not the model, assembles the system prompt. The workaround is shell-side concatenation (cat file1.md file2.md > AGENTS.md), which is fragile and breaks the declarative model.
Context budget waste. Without selective composition, users choose between including everything (wasting context on irrelevant instructions and hitting project_doc_max_bytes truncation) or going without project-specific guidance.
Proposed syntax
# AGENTS.md - project root
@docs/coding-standards.md
@docs/security-policy.md
@~/.codex/instructions/rust-conventions.md
## Project-Specific Instructions
- Use `cargo nextest run` for tests.
- Prefer `tracing` over `log` crate.
Resolution rules
- Relative paths resolve from the directory containing the AGENTS.md
~/resolves to home directory;~/.codex/resolves to$CODEX_HOME- Files inlined in declaration order at the position of the
@line - Missing files emit a warning to stderr, do not block startup
- Circular includes detected and rejected
- Included content counts against
project_doc_max_bytes - Line must start with
@followed by a file path - no inline usage, no globs
Cross-tool interoperability
With this feature, both tools can reference the same underlying files:
project-root/
docs/
coding-standards.md # shared source of truth
security-policy.md # shared source of truth
AGENTS.md # @docs/coding-standards.md
CLAUDE.md # @docs/coding-standards.md
No duplication, no drift. Same @ syntax, same resolution semantics.
Optional extension: auto-load directory
Lower priority, but a .codex/rules/ directory (analogous to .claude/rules/) where all .md files auto-load alongside AGENTS.md at that directory level would provide zero-configuration composition for teams wanting modular ownership without explicit include lines.
Implementation notes
- Purely a CLI-side text transformation during instruction assembly. No model changes, no API changes.
- The
@prefix for file references is established convention in Claude Code, Cursor.mdcfiles, and others. Same syntax maximizes cross-tool familiarity. - Existing
project_doc_max_bytesandproject_doc_fallback_filenamesconfig keys work as-is. Includes resolve before byte-limit truncation. - Skills (introduced April 2026) address reusable workflows but not reusable instructions. Complementary, not competing.
Additional information
Related issues
- #11838 - User cannot chain AGENTS.md files; model ignores "read this file next"; requests CLI-level instruction assembly
- #5983 - Requests
--bypass-agents+ alternative file loading; shell concatenation acknowledged as janky workaround - #3853 - Enterprise request for centralized MDM-managed instruction files outside user home
- #10067 - Named AGENTS.md variants (
--agents review); addresses workflow switching but not modular composition - #6149 - Requests ability to point Codex to a specific AGENTS.md path
- #3540 - Global
preamble_pathignored in interactive sessions
Cross-ecosystem prior art
- Claude Code (production):
@path/to/file.mdimports in CLAUDE.md,.claude/rules/auto-load directory - anthropics/claude-code#13614: Claude Code community requested
@includebefore it shipped - identical pain point - Cursor:
.mdcrule files with frontmatter-based activation and file references - AGENTS.md spec (agents.md, Linux Foundation / AAIF): positions itself as universal cross-tool standard, but modular composition is not yet part of the spec - this feature would be a natural addition
What this unblocks
- Monorepo teams: shared base instructions with package-level specialization, no duplication
- Multi-tool teams: single source of truth consumed by both Codex and Claude Code
- Enterprise: centralized policy files referenced from any project's AGENTS.md
- Individual developers: language/framework instruction libraries composed per-project
- Open source maintainers: AGENTS.md that references structured docs already in the repo
9 Comments
Potential duplicates detected. Please review them and close your issue if it is a duplicate.
Powered by Codex Action
This probably belongs with AGENTS.md GitHub.
Hi,
I ran into the same issue. For visibility, #6038 has a candidate implementation here: https://github.com/openai/codex/compare/main...MOlechowski:codex:feat/at-include-directives
Is this still the preferred direction for
@includesupport, or would maintainers prefer a smaller initial patch? (I'm happy to work on)The
@includepart looks right. The migration snag is usually not file reuse, it's behavior drift: shared files cut duplication, but hooks, lifecycle rules, per-agent metadata, and local MCP wrappers still diverge.It might help if the assembled prompt path were inspectable, even through a debug command or stderr summary. Otherwise teams can share source files and still have no quick way to verify that Codex loaded the instruction set they expected.
There is a concrete AGENTS.md / CLAUDE.md migration write-up here, since this is usually where it breaks in practice:
https://bringyour.ai/agents-md-claude-md
@unitedideas's point on behaviour drift is a good one. I've been building a format converter between AGENTS.md and CLAUDE.md (https://tomevault.io/studio) and the structural layer is the easy bit. The include syntax to flat inline transformation is pretty mechanical. What seems to be tripping people up are the hooks, MCP wrappers, and lifecycle rules like you said that don't have clean equivalents and no amount of "include xyz" guidance is going to fix that.
The inspectable assembled prompt suggestion would have saved me a lot of head-scratching too earlier on. When testing conversions, the main pain was not knowing what actually got loaded versus what you expected. Even a stderr summary of "resolved these files, total X bytes, truncated Y" would help a lot.
The thing I'm less clear on is should this live in the CLI, or does it need to make it into the AGENTS.md spec itself? If it stays Codex-only then the shared source of truth case gets messy. Claude Code would still need to add AGENTS.md support (soon?! lol) before both tools can read the same file with includes working. Has anyone raised this with the AAIF team yet?
Hitting this same wall in a Codex+Claude monorepo, and the asymmetry you described — CLAUDE.md supports @, AGENTS.md doesn’t — is exactly where the duplication starts.
Until @include lands in Codex, the workaround we use is to keep one source of truth and compile it out to each tool’s preferred shape. xcaffold’s kind: context resource lets you author a single markdown body that renders verbatim to CLAUDE.md and AGENTS.md in one apply step, so the two files can’t drift because they’re regenerated from the same input every time. For shared sub-files that should be @-referenced from CLAUDE.md but inlined into AGENTS.md, the kind: rule resource fans the same source out per-target — Claude keeps its @-imports preserved, Codex gets the content flattened in directly. The choice between inline and referenced is the renderer’s problem, not the author’s.
Docs: context kind and the multi-target compilation guide
Doesn’t replace the spec change you’re asking for, but it stops the dual-maintenance bleeding for mixed-tool repos in the meantime.
The
@includeresolver probably needs one more acceptance criterion beyond "can inline files": make the resolution/fidelity observable.A minimal shape that would help migrations:
AGENTS.mdcan inline shared text, but if the shared source came from a Claude workflow that assumes hooks, MCP wrappers, slash commands, or lifecycle events, the compiled Codex target should say "text preserved, behavior not represented"The important distinction for teams using Codex + Claude isn't just include syntax parity. It's proving that the target got the same contract, or explicitly showing where it didn't.
I've been testing this framing in Pluribus as a small fidelity report for generated AI context files. The useful bit is less the tool and more the output model: represented sections, unsupported sections, target files, warnings, and a next step before calling something portable/universal:
https://github.com/caioribeiroclw-pixel/pluribus/blob/main/docs/portability-fidelity-report.md
Adding a concrete user-level case for this.
I tried to keep global Codex instructions modular like this:
Expected:
Codex expands RTK.md into the instruction context at startup.
Actual:
The @ path appears to be passed through as literal text; the agent only sees it if it manually opens the file.
Why it matters:
Claude Code supports @ imports in CLAUDE.md, including absolute paths, so users maintaining both tools need duplicate instruction files or unreliable “read this file” prompts. This makes AGENTS.md less useful as a shared cross-tool instruction layer.
On the observable-resolution point @unitedideas and @caioribeiroclw-pixel raised, it helps to split fidelity into two halves that fail differently. The structural half is knowable before the model runs: which files resolved, what each contributed in bytes, what got truncated against the size cap, and whether an
@import flattened cleanly or silently dropped. A deterministic pass over the assembled set catches all of it, and it is the half that bites on migration, since the dropped section is usually the guardrail at the end of the file. The semantic half is the hooks, MCP wrappers, and lifecycle rules with no equivalent on the target, and there a converter can only mark "text preserved, behaviour not represented" rather than carry anything across.We hit this building conversion between AGENTS.md, CLAUDE.md and the rest, and what proved useful was a per-section report (rendered / unsupported / truncated, with the reason and source file beside each) rather than a single verdict. The one thing I would push into the resolver itself is emitting the structural half by default, a stderr or
--jsonsummary of resolved files, bytes, and what was dropped, because once it is observable the author can self-correct, and while it is silent every consumer rebuilds the same guesswork. (Disclosure: I work on TomeVault, which does this conversion; happy to share the section-classification we landed on.)