{"id":2950,"date":"2026-04-25T10:27:05","date_gmt":"2026-04-25T10:27:05","guid":{"rendered":"https:\/\/aiopsschool.com\/blog\/?p=2950"},"modified":"2026-04-25T10:41:05","modified_gmt":"2026-04-25T10:41:05","slug":"codex-save-context-memory-with-codex-a-complete-guide-codex-memories","status":"publish","type":"post","link":"https:\/\/aiopsschool.com\/blog\/codex-save-context-memory-with-codex-a-complete-guide-codex-memories\/","title":{"rendered":"Codex &#8211; Complete Guide to ~\/.codex\/memories\/: How to Save and Use Memory in Codex"},"content":{"rendered":"\n<h1 class=\"wp-block-heading\"><\/h1>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"319\" src=\"https:\/\/aiopsschool.com\/blog\/wp-content\/uploads\/2026\/04\/image-6-1024x319.png\" alt=\"\" class=\"wp-image-2956\" srcset=\"https:\/\/aiopsschool.com\/blog\/wp-content\/uploads\/2026\/04\/image-6-1024x319.png 1024w, https:\/\/aiopsschool.com\/blog\/wp-content\/uploads\/2026\/04\/image-6-300x94.png 300w, https:\/\/aiopsschool.com\/blog\/wp-content\/uploads\/2026\/04\/image-6-768x240.png 768w, https:\/\/aiopsschool.com\/blog\/wp-content\/uploads\/2026\/04\/image-6-1536x479.png 1536w, https:\/\/aiopsschool.com\/blog\/wp-content\/uploads\/2026\/04\/image-6-2048x639.png 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Codex can now remember useful context from earlier work and reuse it in future sessions. This guide explains what <code>~\/.codex\/memories\/<\/code> is, how to enable it, how to use it correctly, what to save, what not to save, and how to combine it with <code>AGENTS.md<\/code> for a reliable long-term workflow.<\/p>\n\n\n\n<p>Codex Memories are currently <strong>off by default<\/strong>. When enabled, they help Codex remember stable preferences, workflows, tech stacks, project conventions, and known pitfalls across threads. OpenAI recommends treating memory as a helpful local recall layer, not as the only source of important rules. Required instructions should still live in <code>AGENTS.md<\/code> or checked-in documentation. (<a href=\"https:\/\/developers.openai.com\/codex\/memories\">OpenAI Developers<\/a>)<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">1. What is <code>~\/.codex\/memories\/<\/code>?<\/h2>\n\n\n\n<p><code>~\/.codex\/memories\/<\/code> is the local folder where Codex stores memory-related files.<\/p>\n\n\n\n<p>By default, Codex uses this home directory:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>~\/.codex\n<\/code><\/pre>\n\n\n\n<p>The main memory files live here:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>~\/.codex\/memories\/\n<\/code><\/pre>\n\n\n\n<p>These files can include summaries, durable memory entries, recent inputs, and supporting evidence from prior Codex threads. OpenAI describes these files as generated state: you can inspect them, especially for troubleshooting, but you should not treat manual editing as the main way to control Codex behavior. (<a href=\"https:\/\/developers.openai.com\/codex\/memories\">OpenAI Developers<\/a>)<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">2. What problem does Codex Memory solve?<\/h2>\n\n\n\n<p>Without memory, you may need to repeat the same context every time:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>This is a Laravel project.\nUse Pest for tests.\nDo not edit generated files.\nAlways check routes first.\nPrefer small commits.\nDo not touch payment logic without asking.\n<\/code><\/pre>\n\n\n\n<p>With memory enabled, Codex can gradually learn stable working context from previous sessions, so future sessions can start with better background knowledge. It is useful for recurring preferences, coding style, common project structure, repeated debugging patterns, and known mistakes to avoid. (<a href=\"https:\/\/developers.openai.com\/codex\/memories\">OpenAI Developers<\/a>)<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">3. Memory is not the same as <code>AGENTS.md<\/code><\/h2>\n\n\n\n<p>This is the most important concept.<\/p>\n\n\n\n<p>Use <strong>Codex Memory<\/strong> for:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Useful background Codex can remember from previous work.\n<\/code><\/pre>\n\n\n\n<p>Use <strong>AGENTS.md<\/strong> for:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Rules Codex must reliably follow every time.\n<\/code><\/pre>\n\n\n\n<p>For example, this belongs in memory:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>The developer usually prefers small, targeted pull requests.\n<\/code><\/pre>\n\n\n\n<p>This belongs in <code>AGENTS.md<\/code>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Never commit secrets.\nAlways run tests before finishing.\nDo not modify generated files.\n<\/code><\/pre>\n\n\n\n<p>Codex reads <code>AGENTS.md<\/code> before doing work, and OpenAI recommends using it for reusable repository guidance such as repo layout, test commands, conventions, constraints, and verification steps. (<a href=\"https:\/\/developers.openai.com\/codex\/guides\/agents-md\">OpenAI Developers<\/a>)<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">4. Where is <code>~\/.codex\/memories\/<\/code> located?<\/h2>\n\n\n\n<p>On Linux or macOS:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>~\/.codex\/memories\/\n<\/code><\/pre>\n\n\n\n<p>On a Linux server, <code>~<\/code> depends on the current user.<\/p>\n\n\n\n<p>For a normal user:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/home\/username\/.codex\/memories\/\n<\/code><\/pre>\n\n\n\n<p>For root:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/root\/.codex\/memories\/\n<\/code><\/pre>\n\n\n\n<p>Check your actual home directory:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>echo ~\n<\/code><\/pre>\n\n\n\n<p>Then check the Codex folder:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ls -la ~\/.codex\n<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">5. Enable Codex Memories<\/h2>\n\n\n\n<p>Create the Codex config directory:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>mkdir -p ~\/.codex\n<\/code><\/pre>\n\n\n\n<p>Open the config file:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>nano ~\/.codex\/config.toml\n<\/code><\/pre>\n\n\n\n<p>Add:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;features]\nmemories = true\n<\/code><\/pre>\n\n\n\n<p>Save the file.<\/p>\n\n\n\n<p>Codex user-level configuration lives in <code>~\/.codex\/config.toml<\/code>, and project-level overrides can live in <code>.codex\/config.toml<\/code> inside a repository. Codex loads configuration from multiple layers, with CLI overrides taking highest priority, followed by profiles, trusted project config, user config, system config, and built-in defaults. (<a href=\"https:\/\/developers.openai.com\/codex\/config-basic\">OpenAI Developers<\/a>)<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">6. Avoid duplicate <code>[features]<\/code> blocks<\/h2>\n\n\n\n<p>Before adding anything, inspect your config:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>cat ~\/.codex\/config.toml\n<\/code><\/pre>\n\n\n\n<p>Bad example:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;features]\nmemories = true<\/code><\/pre>\n\n\n<p>[features]<\/p>\n\n\n\n<p>codex_hooks = true<\/p>\n\n\n\n<p>Good example:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;features]\nmemories = true\ncodex_hooks = true\n<\/code><\/pre>\n\n\n\n<p>A TOML config should not have repeated identical table headers unless the format explicitly expects arrays of tables. For normal Codex feature flags, keep all feature flags under one <code>[features]<\/code> section.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">7. Confirm the memory folder<\/h2>\n\n\n\n<p>After enabling memory, run:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ls -la ~\/.codex\/memories\n<\/code><\/pre>\n\n\n\n<p>If it does not exist yet, that can be normal.<\/p>\n\n\n\n<p>Codex does not necessarily create memory files immediately. It can skip active or short-lived sessions, redact secrets from generated memory fields, and update memories later instead of immediately when a thread ends. Memories may not update until a thread has been idle long enough. (<a href=\"https:\/\/developers.openai.com\/codex\/memories\">OpenAI Developers<\/a>)<\/p>\n\n\n\n<p>You can also check:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>find ~\/.codex -maxdepth 3 -type d -print\n<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">8. Basic memory workflow<\/h2>\n\n\n\n<p>A simple workflow looks like this:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>1. Enable memories in ~\/.codex\/config.toml\n2. Use Codex normally\n3. Give Codex stable context during real work\n4. Let Codex generate memory over time\n5. Keep hard rules in AGENTS.md\n6. Review memory files when troubleshooting\n<\/code><\/pre>\n\n\n\n<p>Example first memory-seeding prompt:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Remember this for future Codex work:\n\nI usually prefer small, targeted changes.\nBefore editing, inspect only the files relevant to the task.\nDo not refactor unrelated code.\nWhen a task is ambiguous, make a short plan first.\nWhen changing code, explain what changed and how to test it.\n<\/code><\/pre>\n\n\n\n<p>This kind of prompt gives Codex reusable context without locking critical rules only inside memory.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">9. What should you save in Codex Memory?<\/h2>\n\n\n\n<p>Good memory candidates are durable, reusable, and not secret.<\/p>\n\n\n\n<p>Examples:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>The user prefers small, focused changes.\nThe user prefers minimal dependencies.\nThe main backend is Laravel.\nThe frontend uses React and Tailwind.\nTests should be run with npm test.\nThe project uses PostgreSQL locally.\nThe team prefers conventional commits.\nThe user likes short explanations after code changes.\nThe codebase has legacy modules that should not be refactored casually.\n<\/code><\/pre>\n\n\n\n<p>These are useful because they apply across multiple future sessions.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">10. What should not go into Codex Memory?<\/h2>\n\n\n\n<p>Do not intentionally store secrets or sensitive operational data.<\/p>\n\n\n\n<p>Avoid saving:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>API keys\nDatabase passwords\nSSH private keys\nProduction tokens\nOAuth secrets\nCustomer data\nPrivate financial data\nCredentials from .env files\nOne-time incident details\nTemporary debugging output\n<\/code><\/pre>\n\n\n\n<p>OpenAI says Codex redacts secrets from generated memory fields, but you should still avoid storing secrets and review memory files before sharing your Codex home directory or generated memory artifacts. (<a href=\"https:\/\/developers.openai.com\/codex\/memories\">OpenAI Developers<\/a>)<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">11. How to use <code>\/memories<\/code> inside Codex<\/h2>\n\n\n\n<p>Inside the Codex app or TUI, use:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/memories\n<\/code><\/pre>\n\n\n\n<p>This lets you control memory behavior for the current thread.<\/p>\n\n\n\n<p>You can decide whether the current thread can:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Use existing memories\nGenerate future memories\n<\/code><\/pre>\n\n\n\n<p>Thread-level choices do not change your global memory settings. (<a href=\"https:\/\/developers.openai.com\/codex\/memories\">OpenAI Developers<\/a>)<\/p>\n\n\n\n<p>Use this when you are working on sensitive or temporary tasks.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">12. Recommended beginner config<\/h2>\n\n\n\n<p>For most users:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;features]\nmemories = true\n<\/code><\/pre>\n\n\n\n<p>That is enough to start.<\/p>\n\n\n\n<p>Then use Codex normally and let memories build over time.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">13. Recommended practical config<\/h2>\n\n\n\n<p>For users who want memory but want to avoid saving externally sourced or tool-heavy threads:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;features]\nmemories = true<\/code><\/pre>\n\n\n<p>[memories]<\/p>\n\n\n\n<p>use_memories = true generate_memories = true disable_on_external_context = true min_rollout_idle_hours = 6 max_rollout_age_days = 30 max_unused_days = 30<\/p>\n\n\n\n<p>Meaning:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>use_memories = true\n<\/code><\/pre>\n\n\n\n<p>Codex can inject existing memories into future sessions.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>generate_memories = true\n<\/code><\/pre>\n\n\n\n<p>New threads can become memory-generation inputs.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>disable_on_external_context = true\n<\/code><\/pre>\n\n\n\n<p>Threads that used external context such as MCP tool calls, web search, or tool search are excluded from memory generation.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>min_rollout_idle_hours = 6\n<\/code><\/pre>\n\n\n\n<p>Codex waits before considering a thread for memory generation.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>max_rollout_age_days = 30\n<\/code><\/pre>\n\n\n\n<p>Codex only considers recent threads up to the configured age.<\/p>\n\n\n\n<p>The official config reference documents these memory settings, including <code>generate_memories<\/code>, <code>use_memories<\/code>, <code>disable_on_external_context<\/code>, <code>max_rollout_age_days<\/code>, <code>max_unused_days<\/code>, and <code>min_rollout_idle_hours<\/code>. (<a href=\"https:\/\/developers.openai.com\/codex\/config-reference\">OpenAI Developers<\/a>)<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">14. Advanced memory settings explained<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\"><code>memories.use_memories<\/code><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;memories]\nuse_memories = true\n<\/code><\/pre>\n\n\n\n<p>When true, Codex can use existing memories in future sessions.<\/p>\n\n\n\n<p>To temporarily stop Codex from using existing memories:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;memories]\nuse_memories = false\n<\/code><\/pre>\n\n\n\n<p>When false, Codex skips injecting existing memories into future sessions. (<a href=\"https:\/\/developers.openai.com\/codex\/config-reference\">OpenAI Developers<\/a>)<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\"><code>memories.generate_memories<\/code><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;memories]\ngenerate_memories = true\n<\/code><\/pre>\n\n\n\n<p>When true, Codex can use newly created threads as inputs for future memory generation.<\/p>\n\n\n\n<p>To stop creating new memories:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;memories]\ngenerate_memories = false\n<\/code><\/pre>\n\n\n\n<p>When false, newly created threads are not stored as memory-generation inputs. (<a href=\"https:\/\/developers.openai.com\/codex\/config-reference\">OpenAI Developers<\/a>)<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\"><code>memories.disable_on_external_context<\/code><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;memories]\ndisable_on_external_context = true\n<\/code><\/pre>\n\n\n\n<p>This is useful when you use MCP tools, web search, or other external context and do not want those threads used for memory generation. (<a href=\"https:\/\/developers.openai.com\/codex\/config-reference\">OpenAI Developers<\/a>)<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\"><code>memories.min_rollout_idle_hours<\/code><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;memories]\nmin_rollout_idle_hours = 6\n<\/code><\/pre>\n\n\n\n<p>This controls how long a thread must be idle before Codex considers it for memory generation. The documented default is 6 hours, with a clamped range of 1 to 48 hours. (<a href=\"https:\/\/developers.openai.com\/codex\/config-reference\">OpenAI Developers<\/a>)<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\"><code>memories.max_rollout_age_days<\/code><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;memories]\nmax_rollout_age_days = 30\n<\/code><\/pre>\n\n\n\n<p>This controls the maximum age of threads considered for memory generation. The documented default is 30 days, with a clamped range of 0 to 90 days. (<a href=\"https:\/\/developers.openai.com\/codex\/config-reference\">OpenAI Developers<\/a>)<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\"><code>memories.max_unused_days<\/code><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;memories]\nmax_unused_days = 30\n<\/code><\/pre>\n\n\n\n<p>This controls how long an unused memory remains eligible for consolidation. The documented default is 30 days, with a clamped range of 0 to 365 days. (<a href=\"https:\/\/developers.openai.com\/codex\/config-reference\">OpenAI Developers<\/a>)<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">15. How to inspect memories<\/h2>\n\n\n\n<p>List memory files:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ls -la ~\/.codex\/memories\n<\/code><\/pre>\n\n\n\n<p>Find files:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>find ~\/.codex\/memories -maxdepth 3 -type f -print\n<\/code><\/pre>\n\n\n\n<p>Preview safely:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>find ~\/.codex\/memories -maxdepth 3 -type f -print -exec sed -n '1,80p' {} \\;\n<\/code><\/pre>\n\n\n\n<p>Check folder size:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>du -sh ~\/.codex\/memories\n<\/code><\/pre>\n\n\n\n<p>Search for a keyword:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>grep -R \"Laravel\" ~\/.codex\/memories\n<\/code><\/pre>\n\n\n\n<p>Search for possible secrets before sharing:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>grep -R -i \"password\\|secret\\|token\\|api_key\\|apikey\\|private key\" ~\/.codex\/memories\n<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">16. How to delete memories<\/h2>\n\n\n\n<p>Delete all memories:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>rm -rf ~\/.codex\/memories\n<\/code><\/pre>\n\n\n\n<p>Recreate the folder:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>mkdir -p ~\/.codex\/memories\n<\/code><\/pre>\n\n\n\n<p>This deletes existing memory files, but it does not necessarily disable memory. If this remains enabled:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;features]\nmemories = true\n<\/code><\/pre>\n\n\n\n<p>Codex may create new memories later.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">17. How to disable memory completely<\/h2>\n\n\n\n<p>Edit:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>nano ~\/.codex\/config.toml\n<\/code><\/pre>\n\n\n\n<p>Set:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;features]\nmemories = false<\/code><\/pre>\n\n\n<p>[memories]<\/p>\n\n\n\n<p>use_memories = false generate_memories = false<\/p>\n\n\n\n<p>Then remove existing memory files if desired:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>rm -rf ~\/.codex\/memories\n<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">18. How to pause memory for sensitive work<\/h2>\n\n\n\n<p>Inside Codex:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/memories\n<\/code><\/pre>\n\n\n\n<p>Disable memory generation for that thread.<\/p>\n\n\n\n<p>Use this for:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Production debugging\nSecret rotation\nSecurity incidents\nCustomer-specific debugging\n.env inspection\nDatabase credential work\nPayment provider debugging\nPrivate logs\n<\/code><\/pre>\n\n\n\n<p>You can also make your config stricter:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;features]\nmemories = true<\/code><\/pre>\n\n\n<p>[memories]<\/p>\n\n\n\n<p>use_memories = true generate_memories = true disable_on_external_context = true<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">19. Combine memory with <code>AGENTS.md<\/code><\/h2>\n\n\n\n<p>A strong setup uses both.<\/p>\n\n\n\n<p>Create global instructions:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>mkdir -p ~\/.codex\n\ncat &gt; ~\/.codex\/AGENTS.md &lt;&lt;'EOF'\n# Global Codex working rules\n\n- Prefer small, focused changes.\n- Explain what files you changed and why.\n- Do not edit unrelated files.\n- Do not expose secrets.\n- Ask before adding new production dependencies.\n- Run relevant tests when possible.\n- If a task is complex, make a short plan before editing.\nEOF\n<\/code><\/pre>\n\n\n\n<p>Codex reads global guidance from the Codex home directory, usually <code>~\/.codex<\/code>, and also reads project-level <code>AGENTS.md<\/code> files when present. More specific files closer to the working directory override earlier guidance because they appear later in the combined prompt. (<a href=\"https:\/\/developers.openai.com\/codex\/guides\/agents-md\">OpenAI Developers<\/a>)<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">20. Create project-specific <code>AGENTS.md<\/code><\/h2>\n\n\n\n<p>Inside a repo:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>cat &gt; AGENTS.md &lt;&lt;'EOF'\n# Project instructions\n\n## Project layout\n- app\/ contains application code\n- tests\/ contains automated tests\n- docs\/ contains documentation\n\n## Commands\n- Run tests with: npm test\n- Run lint with: npm run lint\n- Run build with: npm run build\n\n## Rules\n- Do not edit generated files.\n- Do not change public APIs without explaining the impact.\n- Keep changes small and reviewable.\n- Update tests when behavior changes.\n\n## Done means\n- Relevant tests pass.\n- No unrelated files are changed.\n- The final response explains what changed and how to verify it.\nEOF\n<\/code><\/pre>\n\n\n\n<p>This is better than relying only on memory because <code>AGENTS.md<\/code> is explicit, reviewable, shareable with a team, and automatically loaded as project guidance. OpenAI\u2019s best-practices guide describes <code>AGENTS.md<\/code> as the best place to encode how a team wants Codex to work in a repository. (<a href=\"https:\/\/developers.openai.com\/codex\/learn\/best-practices\">OpenAI Developers<\/a>)<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">21. How to seed memory properly<\/h2>\n\n\n\n<p>Do not just say:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Remember my project.\n<\/code><\/pre>\n\n\n\n<p>That is too vague.<\/p>\n\n\n\n<p>Use structured context:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Remember this for future Codex sessions:\n\nMy coding preferences:\n- Prefer small, targeted changes.\n- Do not refactor unrelated code.\n- Explain assumptions before editing.\n- Prefer existing project conventions over introducing new patterns.\n\nMy review preferences:\n- Summarize changed files.\n- Mention tests run.\n- Mention any risks or follow-up work.\n\nMy safety preferences:\n- Never print secrets.\n- Avoid reading .env unless explicitly necessary.\n- Ask before adding production dependencies.\n<\/code><\/pre>\n\n\n\n<p>This gives Codex stable, reusable information.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">22. Good memory prompts<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">For personal coding style<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>Remember for future Codex work:\nI prefer minimal, focused patches. Avoid broad refactors unless I explicitly ask for them. When making changes, explain the exact files changed and the test command to run.\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">For a tech stack<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>Remember for future Codex work:\nMost of my backend projects use Laravel, MySQL, and Blade. When debugging Laravel, check routes, controllers, models, migrations, middleware, config, and logs only as needed.\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">For frontend preferences<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>Remember for future Codex work:\nFor frontend work, I prefer React with Tailwind, simple components, accessible markup, and minimal new dependencies.\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">For review behavior<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>Remember for future Codex work:\nWhen reviewing code, focus on correctness, security, edge cases, performance, and maintainability. Give actionable fixes, not only comments.\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">For cost control<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>Remember for future Codex work:\nBefore scanning a large repository, identify the most likely files first. Avoid reading vendor, node_modules, build output, cache directories, logs, and generated files unless explicitly needed.\n<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">23. Bad memory prompts<\/h2>\n\n\n\n<p>Avoid vague prompts:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Remember everything about this repo.\n<\/code><\/pre>\n\n\n\n<p>Avoid secrets:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Remember my production database password is ...\n<\/code><\/pre>\n\n\n\n<p>Avoid temporary facts:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Remember I am debugging this issue today at 3 PM.\n<\/code><\/pre>\n\n\n\n<p>Avoid unstable assumptions:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Remember this API is always broken.\n<\/code><\/pre>\n\n\n\n<p>Better:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Remember that this codebase has had recurring issues around API timeout handling. When debugging API failures, check retry logic, timeout configuration, and error logging.\n<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">24. Memory workflow for large codebases<\/h2>\n\n\n\n<p>For a large codebase, memory should help Codex avoid rediscovering the same structure every time.<\/p>\n\n\n\n<p>Example memory prompt:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Remember this large-repo workflow:\n\n1. First identify the relevant module.\n2. Avoid scanning the whole repository.\n3. Check README, AGENTS.md, routes, entry points, and tests first.\n4. Ignore dependencies, generated files, build output, logs, and cache directories.\n5. Before editing, state the small set of files to inspect.\n6. Make the smallest safe change.\n<\/code><\/pre>\n\n\n\n<p>Then encode hard rules in <code>AGENTS.md<\/code>.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">25. Memory workflow for teams<\/h2>\n\n\n\n<p>For teams, do not depend on one developer\u2019s local memory.<\/p>\n\n\n\n<p>Use this pattern:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Team-wide required behavior \u2192 AGENTS.md\nPersonal preferences \u2192 ~\/.codex\/AGENTS.md\nHelpful previous context \u2192 ~\/.codex\/memories\/\nTemporary task details \u2192 current prompt\n<\/code><\/pre>\n\n\n\n<p>Example:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>~\/.codex\/AGENTS.md\n<\/code><\/pre>\n\n\n\n<p>Personal preferences.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>project\/AGENTS.md\n<\/code><\/pre>\n\n\n\n<p>Team and repository rules.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>~\/.codex\/memories\/\n<\/code><\/pre>\n\n\n\n<p>Generated recall from prior work.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Current prompt\n<\/code><\/pre>\n\n\n\n<p>Task-specific instructions.<\/p>\n\n\n\n<p>This keeps the workflow reliable and shareable.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">26. Memory and config precedence<\/h2>\n\n\n\n<p>Codex config can come from several places. In general, one-off CLI flags and <code>--config<\/code> overrides take priority over profiles, then project config, then user config, then system config, then defaults. (<a href=\"https:\/\/developers.openai.com\/codex\/config-basic\">OpenAI Developers<\/a>)<\/p>\n\n\n\n<p>This matters because memory might be enabled globally but disabled for one run:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>codex -c features.memories=false\n<\/code><\/pre>\n\n\n\n<p>Or memory might be enabled globally but overridden by a profile.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">27. Project-level memory behavior<\/h2>\n\n\n\n<p>You can keep general memory enabled globally:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;features]\nmemories = true\n<\/code><\/pre>\n\n\n\n<p>Then control project behavior using project config:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>mkdir -p .codex\nnano .codex\/config.toml\n<\/code><\/pre>\n\n\n\n<p>Example:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;memories]\ngenerate_memories = false\n<\/code><\/pre>\n\n\n\n<p>This is useful for sensitive repositories.<\/p>\n\n\n\n<p>Project-scoped <code>.codex\/config.toml<\/code> files are loaded only for trusted projects. (<a href=\"https:\/\/developers.openai.com\/codex\/config-basic\">OpenAI Developers<\/a>)<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">28. Advanced: reduce accidental parent-folder context<\/h2>\n\n\n\n<p>For large workspaces or monorepos, configure project root markers carefully.<\/p>\n\n\n\n<p>Codex discovers project configuration by walking up from the working directory until it reaches a project root. By default, a directory containing <code>.git<\/code> is treated as a project root. You can customize this with <code>project_root_markers<\/code>. (<a href=\"https:\/\/developers.openai.com\/codex\/config-advanced\">OpenAI Developers<\/a>)<\/p>\n\n\n\n<p>Example:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>project_root_markers = &#91;\".git\", \"composer.json\", \"package.json\"]\n<\/code><\/pre>\n\n\n\n<p>Or force Codex to treat only the current directory as the root:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>project_root_markers = &#91;]\n<\/code><\/pre>\n\n\n\n<p>This can help prevent Codex from accidentally loading broader parent-level context in unusual folder structures.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">29. Troubleshooting<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">Problem: <code>~\/.codex\/memories\/<\/code> does not exist<\/h3>\n\n\n\n<p>Check config:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>cat ~\/.codex\/config.toml\n<\/code><\/pre>\n\n\n\n<p>Confirm:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;features]\nmemories = true\n<\/code><\/pre>\n\n\n\n<p>Then use Codex normally. The folder may appear later.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">Problem: memory folder exists but is empty<\/h3>\n\n\n\n<p>This can happen when:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Memories were just enabled.\nThreads were too short.\nThreads are still active.\nIdle time has not passed.\nMemory generation is disabled.\nThe current region\/account does not support memories.\n<\/code><\/pre>\n\n\n\n<p>Codex may wait before creating memory because it avoids summarizing work that may still be in progress. (<a href=\"https:\/\/developers.openai.com\/codex\/memories\">OpenAI Developers<\/a>)<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">Problem: Codex remembers wrong information<\/h3>\n\n\n\n<p>Correct it in the next session:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>The previous memory is outdated. Update your understanding:\nThis project now uses PostgreSQL, not MySQL.\nUse pnpm, not npm.\nRun tests with pnpm test.\n<\/code><\/pre>\n\n\n\n<p>Then add hard rules to <code>AGENTS.md<\/code>.<\/p>\n\n\n\n<p>If needed, delete memory files:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>rm -rf ~\/.codex\/memories\n<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">Problem: Codex ignores memory<\/h3>\n\n\n\n<p>Check whether memory usage is disabled:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>grep -n \"use_memories\\|generate_memories\\|memories\" ~\/.codex\/config.toml\n<\/code><\/pre>\n\n\n\n<p>Look for:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;memories]\nuse_memories = false\n<\/code><\/pre>\n\n\n\n<p>Set it back to:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;memories]\nuse_memories = true\n<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">Problem: You want memory only sometimes<\/h3>\n\n\n\n<p>Keep global memory enabled:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;features]\nmemories = true\n<\/code><\/pre>\n\n\n\n<p>Use <code>\/memories<\/code> inside Codex to disable memory for specific sensitive threads. (<a href=\"https:\/\/developers.openai.com\/codex\/memories\">OpenAI Developers<\/a>)<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">30. Recommended final setup<\/h2>\n\n\n\n<p>For most developers:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># ~\/.codex\/config.toml<\/code><\/pre>\n\n\n<p>[features]<\/p>\n\n\n\n<p>memories = true<\/p>\n\n\n<p>[memories]<\/p>\n\n\n\n<p>use_memories = true generate_memories = true disable_on_external_context = true min_rollout_idle_hours = 6 max_rollout_age_days = 30 max_unused_days = 30<\/p>\n\n\n\n<p>Create global instructions:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>mkdir -p ~\/.codex\n\ncat &gt; ~\/.codex\/AGENTS.md &lt;&lt;'EOF'\n# Global Codex instructions\n\n- Prefer small, focused changes.\n- Do not refactor unrelated code.\n- Do not expose secrets.\n- Ask before adding major dependencies.\n- Explain changed files and verification steps.\n- Use the project\u2019s existing conventions.\nEOF\n<\/code><\/pre>\n\n\n\n<p>Inside each serious project, create:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>AGENTS.md\n<\/code><\/pre>\n\n\n\n<p>with project-specific rules.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\">Final mental model<\/h1>\n\n\n\n<p>Think of Codex context like this:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Current prompt\n= what you want now\n\nAGENTS.md\n= rules Codex should reliably follow\n\n~\/.codex\/config.toml\n= how Codex should behave\n\n~\/.codex\/memories\/\n= useful context Codex learned over time\n<\/code><\/pre>\n\n\n\n<p>Memory is powerful, but it should not be your only control system. Use it to reduce repetition. Use <code>AGENTS.md<\/code> for rules. Use <code>config.toml<\/code> for behavior. Use clear prompts for the task at hand.<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Codex can now remember useful context from earlier work and reuse it in future sessions. This guide explains what ~\/.codex\/memories\/ [&hellip;]<\/p>\n","protected":false},"author":4,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-2950","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/aiopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/2950","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/aiopsschool.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/aiopsschool.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/aiopsschool.com\/blog\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/aiopsschool.com\/blog\/wp-json\/wp\/v2\/comments?post=2950"}],"version-history":[{"count":4,"href":"https:\/\/aiopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/2950\/revisions"}],"predecessor-version":[{"id":2957,"href":"https:\/\/aiopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/2950\/revisions\/2957"}],"wp:attachment":[{"href":"https:\/\/aiopsschool.com\/blog\/wp-json\/wp\/v2\/media?parent=2950"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/aiopsschool.com\/blog\/wp-json\/wp\/v2\/categories?post=2950"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/aiopsschool.com\/blog\/wp-json\/wp\/v2\/tags?post=2950"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}