Appearance
Dynamic Context (Codex CLI)
Codex CLI does not provide "memory" in the human sense. Instead, its behavior comes from session history, explicitly read files, and configuration files like AGENTS.md
or ~/.codex/config.toml
. OpenAI formally introduced AGENTS.md as the place to encode project-level rules and workflows, so you can guide coding agents without restating everything in every prompt.
The practical mechanic is what we might call dynamic context: temporarily editing or swapping AGENTS.md
(or related instruction files), having Codex reload them, and then restoring the original state when the task is done.
Safe ways to manage AGENTS.md
- Git versioning Commit or stash your
AGENTS.md
before making changes, then roll back when finished. - File duplication Keep a
AGENTS.backup.md
alongside your working copy for quick restores. - Explicit file reads Use Codex to
read AGENTS.md
again after edits to ensure the new content is loaded. Codex does not automatically ingest changed files mid-session without being told. - Session restart Starting a new Codex session guarantees a fresh load of your current
AGENTS.md
.
Quick context swaps during a session
Codex requires explicit reloads of instructions:
- Ask: "Read AGENTS.md again and update context accordingly."
- Run
/context
to check token usage and verify that instructions are present. - Restart the session if you need a guaranteed clean state.
Unlike OpenAI Codex's "dynamic memory," there's no hidden persistence layer—this is context engineering with files.
Multi-context workflows
A reliable way to separate contexts is to run parallel sessions in different directories, each with its own AGENTS.md
.
Benefits:
- Context isolation — each directory carries its own rules.
- No reload friction — Codex automatically reads from the active directory when you tell it.
- Parallel processing — multiple sessions can run specialized tasks without overlap.
- Less contamination — rules from one context don't bleed into another.
For finer control, configure MCP filesystem servers in ~/.codex/config.toml
to expose only the directories you want Codex to see.
Best practices
- Keep the top-level
AGENTS.md
minimal and generic. Place specialized rules in subdirectories. - Always explicitly read or reload after editing, rather than assuming automatic ingestion.
- Use Read Only approvals (
/approvals
) while planning with a new context, then switch to Auto only when you are ready to execute.
Mechanic Benefits
- Flexible context injection — swap rules without rewriting long prompts.
- Controlled persistence — you decide when Codex should re-read instructions.
- Context isolation — use directories or backups to separate workflows.
- Reduced contamination — smaller, task-specific contexts improve clarity and efficiency.
System thinking
Think of dynamic context as configuration discipline, not AI memory. By structuring and reloading AGENTS.md
deliberately, you minimize Codex's guesswork, cut down redundant prompts, and maintain clean execution paths. It's about engineering predictable, reusable states rather than relying on hidden persistence.
Sources
- OpenAI announcement — Codex can be guided by
AGENTS.md
files. - AGENTS.md repository — reference format for agent guidance.
- Codex CLI docs — approvals (
/approvals
), safety model, OS support. - Community analysis — Codex does not auto-reload modified files; explicit reads or restarts required.
- Codex repo —
config.toml
with MCP server config (filesystem, fetch, etc.).