Codex CLI
Your Codex agent remembers past decisions, finds relevant context, and learns from every session, across all your AI tools.
For your agent
Give this line to your agent. It should read the live guide before changing anything:
Read https://mem.nowledge.co/docs/integrations/codex-cli.mdx, then help me install or update Nowledge Mem for Codex CLI. Use the recommended path first, verify the setup with the success check in the guide, and summarize what changed.Hybrid Codex setup
Best result on modern Codex: install the plugin, keep the bundled Nowledge Mem MCP server enabled, and run the hook setup once. The plugin starts Codex with the right memory guidance, MCP gives it low-friction retrieval and write tools, and the Stop hook captures the real Codex transcript.
Switch between Codex, Claude Code, Gemini, and Cursor without losing context. The Codex package gives you a reliable Working Memory bootstrap, a bundled local MCP server, search and distill skills, and automatic thread capture. Codex still decides when to use memory, but modern Codex tends to follow MCP tools more proactively than skill-only guidance. That is why the recommended setup is hybrid: plugin + MCP + hook.
How you'll know it's working
Start a session and ask "What was I working on?" You should see your recent focus areas and priorities. Then ask a continuation-style question such as "What did we decide before about this release?" On a healthy setup, Codex should move from Working Memory into retrieval instead of stopping at the briefing. After a short turn, nmem t search "phrase from that turn" --source codex should find the captured Codex thread.
Before You Start
- Nowledge Mem running locally (installation) or a reachable remote Mem server
- Codex CLI installed
nmemCLI in yourPATH
Setup
Install nmem
# Option 1: uvx
curl -LsSf https://astral.sh/uv/install.sh | sh
uvx --from nmem-cli nmem --version
# Option 2: pip
pip install nmem-cliIf Nowledge Mem is already running on the same machine through the desktop app, the cleanest setup is Settings → Preferences → Developer Tools → Install CLI.
Install the plugin
Use marketplace-first setup
If you run into older instructions that copy files into ~/.codex/plugins/cache/local/..., treat that as legacy fallback only. The primary path is: add the marketplace, install the plugin from Codex /plugins, then enable it in config.
codex plugin marketplace add nowledge-co/communityIf your Codex build only supports the legacy top-level subcommand:
codex marketplace add nowledge-co/communityOpen Codex /plugins and install nowledge-mem@nowledge-community.
Enable the plugin
Put this in ~/.codex/config.toml:
[features]
plugins = true
hooks = true
plugin_hooks = true
[plugins."nowledge-mem@nowledge-community"]
enabled = trueRestart Codex after installation.
What the plugin includes
The current package includes a local Nowledge Mem MCP server at http://127.0.0.1:14242/mcp/. Codex user config wins if you define your own mcp_servers.nowledge-mem, so remote Mem and custom local ports stay explicit.
Enable automatic thread capture
Codex uses hooks for automatic thread capture. hooks = true enables lifecycle hooks, and plugin_hooks = true lets Codex load hooks shipped inside installed plugins. Run the plugin's hook setup once after install or update:
HOOK_SETUP="$(find ~/.codex/plugins/cache -path '*/nowledge-mem/*/scripts/install_hooks.py' -print 2>/dev/null | sort | tail -1)"
if [ -z "$HOOK_SETUP" ]; then
echo "Hook setup was not found. Open Codex, run /plugins, install nowledge-mem@nowledge-community, then retry."
else
python3 "$HOOK_SETUP"
fiThe Stop hook runs after Codex turns and calls nmem t save --from codex. It reads the local Codex transcript, then uploads through your normal nmem client configuration. That means local Mem and remote Mem use the same setup. MCP is helpful for retrieval and memory writes, but it is not required for this automatic thread capture path. If Codex sees both the plugin hook and the host-level fallback, the hook skips the duplicate save for the same transcript state.
The same setup also checks your nmem client configuration. If nmem has a saved API key or a non-default endpoint, it writes a managed Codex MCP block into ~/.codex/config.toml so Codex uses the same Mem server as the CLI.
On Windows PowerShell, run the installed setup script with the Python launcher:
$HookSetup = Get-ChildItem "$env:USERPROFILE\.codex\plugins\cache" -Recurse -Filter install_hooks.py |
Where-Object { $_.FullName -like "*nowledge-mem*" } |
Sort-Object FullName |
Select-Object -Last 1
if ($null -eq $HookSetup) {
Write-Host "Hook setup was not found. Open Codex, run /plugins, install nowledge-mem@nowledge-community, then retry."
} else {
py -3 $HookSetup.FullName
}Optionally add project-level guidance
Copy or merge the plugin's AGENTS.md into your project root for stronger default memory behavior:
git clone https://github.com/nowledge-co/community.git /tmp/nowledge-community
cp /tmp/nowledge-community/nowledge-mem-codex-plugin/AGENTS.md ./AGENTS.md
rm -rf /tmp/nowledge-communityIf your project already has an AGENTS.md, merge the Nowledge section instead of overwriting. This is the clean way to make Codex do more than the basic Working Memory bootstrap on continuation-heavy repos.
Do not edit installed plugin files
Use your repo's own AGENTS.md as the override layer. Treat the package AGENTS.md as source text to copy or merge, not as a file to patch inside the Codex plugin install directory.
Configure remote Mem when needed
nmem config client set url https://mem.example.com
nmem config client set api-key nmem_your_keynmem resolves connection settings in this order:
--api-url/--api-keyflagsNMEM_API_URL/NMEM_API_KEY~/.nowledge-mem/config.json- defaults
If Mem is remote, override the bundled local MCP server in ~/.codex/config.toml too:
nmem config mcp show --host codexPaste the generated TOML into ~/.codex/config.toml, or rerun the hook setup if your installed plugin is 0.1.11 or newer. Direct MCP clients do not read ~/.nowledge-mem/config.json automatically; this keeps Codex MCP and nmem pointed at the same Mem server. MCP gives Codex direct tools; nmem still powers the plugin-side fallback flows and real save-thread.
Repo-level install (alternative)
Instead of a shared marketplace source, you can bundle the plugin in a project repo using a local Codex marketplace file. This makes the plugin available to anyone who clones the repo.
git clone https://github.com/nowledge-co/community.git /tmp/nowledge-community
mkdir -p .agents
cp -r /tmp/nowledge-community/nowledge-mem-codex-plugin ./.agents/nowledge-mem
rm -rf /tmp/nowledge-community
mkdir -p .agents/pluginsCreate .agents/plugins/marketplace.json:
{
"name": "local",
"plugins": [
{
"name": "nowledge-mem",
"source": {
"source": "local",
"path": "./.agents/nowledge-mem"
},
"policy": {
"installation": "INSTALLED_BY_DEFAULT",
"authentication": "ON_INSTALL"
},
"category": "Productivity"
}
]
}The path is relative to the repo root, not to the marketplace file. For this local setup, use:
[plugins."nowledge-mem@local"]
enabled = trueThen run the hook setup from the repo-local plugin:
python3 ./.agents/nowledge-mem/scripts/install_hooks.pyUpdate
If you installed the Codex package before 0.1.13, refresh the marketplace first. Current Codex builds may refresh the marketplace checkout without reinstalling the already-installed package cache, so the hook setup file or bundled hook changes may still be missing until the package itself is updated from /plugins.
codex plugin marketplace upgrade nowledge-communityOpen Codex, run /plugins, update or reinstall nowledge-mem@nowledge-community, then restart Codex.
After the package itself is updated, refresh the hook runtime:
HOOK_SETUP="$(find ~/.codex/plugins/cache -path '*/nowledge-mem/*/scripts/install_hooks.py' -print 2>/dev/null | sort | tail -1)"
if [ -z "$HOOK_SETUP" ]; then
echo "Hook setup is still missing. Reinstall nowledge-mem@nowledge-community from Codex /plugins, then retry."
else
python3 "$HOOK_SETUP"
fiIf the marketplace is not registered yet, run:
codex plugin marketplace add nowledge-co/community || codex marketplace add nowledge-co/communityThen restart Codex. If you are using a repo-local @local source, update that local source path instead.
Skills
The plugin skills still matter in the hybrid setup. They teach Codex when to use memory at all, while MCP gives Codex a lower-friction execution path once it decides to act.
| Skill | Trigger | What it does |
|---|---|---|
$nowledge-mem:working-memory | Session start, "what am I working on" | Loads your daily Working Memory briefing and prefers MCP read_working_memory when available |
$nowledge-mem:search-memory | Prior work, past decisions, "why did we..." | Searches memories and threads with progressive inspection, preferring MCP retrieval when available |
$nowledge-mem:save-thread | Manual save request, or hook setup unavailable | Real Codex transcript import via nmem t save --from codex |
$nowledge-mem:distill-memory | Decisions, learnings, procedures emerge | Proactively saves durable insights to memory, preferring MCP writes when available |
$nowledge-mem:status | "Is Mem working?", errors | Checks server connectivity and configuration |
Nowledge FS for Codex
Nowledge FS is the shared path-first layer behind Knowledge Tree. It is not a Codex-only feature. Codex can use the same layer through the MCP server with mem_fs, a path-first view across memories, threads, wiki pages, working memory, activities, sources, and artifacts.
mem_fs: recall "why did we change token refresh?" --in /memories -k 5
mem_fs: cat /memories/by-id/<id>.memory.md
mem_fs: ls /memories/by-label/authIf MCP is not available, use the CLI:
nmem fs recall "session token strategy" --in /memories -k 5
nmem fs grep "JWT rotation" /memories
nmem fs cat /memories/by-id/<id>.memory.mdUse recall for fuzzy intent, find for metadata constraints, grep for exact strings, stat before loading large bodies, and cat after a useful path has been found. This preview release is API-backed and works in desktop, web, and remote setups; mounting it as a real folder is planned for a later phase.
Direct nmem Use
nmem remains the universal fallback and the real Codex thread-import path. The Stop hook uses the same command automatically:
nmem --json wm read
nmem --json m search "auth token rotation" --mode deep
nmem --json t save --from codex -p . -s "Finished the auth refactor."
nmem --json m add "JWT refresh failures came from clock skew." --title "JWT refresh failures traced to clock skew" --importance 0.9 --unit-type learning -l auth -s codexBy default, nmem t save --from codex reads sessions from ~/.codex. If your Codex home lives somewhere else, set CODEX_HOME and the save path follows automatically.
Migrating from Custom Prompts
If you previously used nowledge-mem-codex-prompts, the plugin covers everything the prompts did:
- Install the plugin (see Setup above).
- Remove old prompts:
rm ~/.codex/prompts/{read_working_memory,search_memory,save_session,distill}.md - The plugin skills replace the prompts one-to-one.
| Old prompt | New skill |
|---|---|
/prompts:read_working_memory | $nowledge-mem:working-memory |
/prompts:search_memory | $nowledge-mem:search-memory |
/prompts:save_session | $nowledge-mem:save-thread |
/prompts:distill | $nowledge-mem:distill-memory |
| (none) | $nowledge-mem:status |
Troubleshooting
"Command not found: nmem"
Install with pip install nmem-cli or use uvx --from nmem-cli nmem. See Getting Started.
"Cannot connect to server"
Run nmem status and nmem config client show for remote setups. See Remote Access.
Skills not appearing
Restart Codex after installing the plugin. Verify three things: the marketplace was added, nowledge-mem@nowledge-community was installed from /plugins, and ~/.codex/config.toml has [features] plugins = true, hooks = true, plugin_hooks = true, and [plugins."nowledge-mem@nowledge-community"] enabled = true. If you intentionally use a repo-local source, use [plugins."nowledge-mem@local"].
Codex threads are not appearing automatically
Run the hook setup again, then restart Codex:
HOOK_SETUP="$(find ~/.codex/plugins/cache -path '*/nowledge-mem/*/scripts/install_hooks.py' -print 2>/dev/null | sort | tail -1)"
test -n "$HOOK_SETUP" && python3 "$HOOK_SETUP"The setup enables both hook gates in ~/.codex/config.toml and keeps a host-level fallback for Codex builds that still need ~/.codex/hooks.json. If Codex shows /hooks, make sure the Nowledge Mem Stop hook is enabled there.
codex mcp list shows Not logged in
Update nmem so it matches your Mem app/server, install the CLI config from the desktop app if you use local desktop Mem, then rerun the hook setup:
pip install -U nmem-cli
nmem status
HOOK_SETUP="$(find ~/.codex/plugins/cache -path '*/nowledge-mem/*/scripts/install_hooks.py' -print 2>/dev/null | sort | tail -1)"
test -n "$HOOK_SETUP" && python3 "$HOOK_SETUP"Do not run codex mcp login nowledge-mem. That command is for OAuth MCP servers. Nowledge Mem uses the URL and headers generated by nmem config mcp show --host codex.
"plugin is not installed"
Run codex plugin marketplace add nowledge-co/community (or codex marketplace add nowledge-co/community on legacy Codex), install nowledge-mem@nowledge-community from /plugins, then verify the plugin key in ~/.codex/config.toml.
It only reads Working Memory, but never searches or distills
That usually means Codex is only seeing the plugin bootstrap path. Confirm the bundled nowledge-mem MCP server is visible in Codex, then merge the package AGENTS.md into your project root. If Mem is remote or not on the default local port, add mcp_servers.nowledge-mem in ~/.codex/config.toml to override the bundled endpoint.