Skip to content

Connecting CodeNavi to OpenAI Codex CLI

Codex CLI talks to CodeNavi over MCP. The integration ships as a bundle, plugins/codex/ (included in every air-gapped package, MIT-licensed). It has two parts because Codex separates them:

  1. The MCP server → ~/.codex/config.toml. This is what gives Codex the 35 tools (43 with the crawler). By default the server lists semantic search, the call graph (find_callers, impact_analysis, diff_impact), the codebase overview and the index tools, and runs the rest, including grep_search and read_file, on demand: reveal_tools() lists the hidden groups, reveal_tools(call="<tool>", args='{…}') reveals and runs one in a single step.
  2. The codenavi Codex plugin → the using-codenavi and compliance-check skills, eleven task skills invoked as $codenavi:<name> (search, status, overview, codebases, reindex, review, crawl, compliance, doctor, setup, agents-md, feedback), and two hooks: one tells Codex at session start that the index is up (or that the licence has run out and the tools refuse, with the way back), the other, when you turn it on, answers a grep of an indexed tree from the index (CODENAVI_HOOK_GREP=hint; CODENAVI_HOOK_GREP=block exported denies that grep instead, Plugins → Grep hook). Codex runs plugin hooks only after you trust them with /hooks.

Codex ≠ Claude Code. Codex reads ~/.codex/config.toml; it does not read Claude Code's .mcp.json. Wiring one does nothing for the other.

Fast path

cd plugins/codex
./connect-codenavi.sh --env-file ../../.env

connect-codenavi.sh is idempotent: it backs up config.toml, writes the [mcp_servers.codenavi] block, writes the CodeNavi usage rules into ~/.codex/AGENTS.md (see Usage rules below), checks the auth token, and verifies an authenticated tools/list against the exact URL before declaring success. Then export the token and restart Codex:

echo 'export CODENAVI_AUTH_TOKEN=$(grep "^CODENAVI_AUTH_TOKEN=" /path/to/install/.env | cut -d= -f2-)' >> ~/.bashrc
source ~/.bashrc
# restart Codex, then run /mcp — 'codenavi' should be listed

On macOS the shell is zsh and the file is ~/.zprofile, not ~/.bashrc; a Mac that connects to a server elsewhere copies the token first (CodeNavi on macOS). Without the variable Codex starts normally but the CodeNavi tools are simply absent: check /mcp when they are missing.

Windows, or the ChatGPT desktop app. A desktop app never reads ~/.bashrc. Set the token once for your Windows user, in PowerShell:

setx CODENAVI_AUTH_TOKEN <token>

setx reaches only programs started after it: open a new terminal, and quit the Codex app from the tray icon before you start it again (closing the window leaves it running). If Codex still says the variable is not set (openai/codex#41378), replace the bearer_token_env_var line in config.toml with http_headers = { Authorization = "Bearer <token>" }. That keeps the token in plain text in the file, so use it only as the fallback.

On Codex 0.162 or newer the connect script also installs the plugin, the same way Claude Code gets its plugin: from the git marketplace the server serves at http://<server>:8765/plugins/codex.git (needs git on the client; without it the script uses its own folder). After a server update, refresh it. From the git marketplace:

codex plugin marketplace upgrade codenavi && codex plugin add codenavi@codenavi

From a folder or the .zip, upgrade fails with "marketplace codenavi is not configured as a Git marketplace". Fetch the new bundle, then add it again:

codex plugin marketplace remove codenavi
codex plugin marketplace add <folder>/codenavi-plugin-codex
codex plugin add codenavi@codenavi

Then, in Codex, run /hooks once and trust the codenavi hooks (again after each update). Older Codex builds install the plugin by hand (offline):

codex plugin marketplace add ./plugins/codex
# in Codex:  /plugins install codenavi@codenavi

Codex on another machine than the server? The server hands the bundle out itself, no token needed: git clone http://<server-ip>:8765/plugins/codex.git && cd codex (no git? curl -O http://<server-ip>:8765/plugins/codex.zip, which unpacks to codenavi-plugin-codex/). Then export CODENAVI_AUTH_TOKEN=<token> and run ./connect-codenavi.sh --host <server-ip> --port 8765, there is no .env on the client, so no --env-file. The plugin's hooks find the server only through CODENAVI_HOST / CODENAVI_PORT, not config.toml, so the script also prints export CODENAVI_HOST=… lines for a server that isn't on localhost:8765: add them to ~/.bashrc next to the token, or setx them on Windows and for the Codex desktop app.

Usage rules (AGENTS.md)

config.toml wires the MCP server, but Codex does not inject config keys like instructions= / user_instructions= into the model-visible prompt (confirmed via codex debug prompt-input), so on its own, Codex only reaches for CodeNavi when you name a tool explicitly. connect-codenavi.sh therefore also writes a compact, sentinel-delimited block of CodeNavi usage rules into ~/.codex/AGENTS.md, the durable behavioral surface. Re-runs replace only that block; the rest of your AGENTS.md is left untouched (it also warns if an AGENTS.override.md sits alongside it).

  • --no-agents-md: skip this step (wire the MCP server only).
  • --project: write the rules to a repo-local ./AGENTS.md instead of the global ~/.codex/AGENTS.md, when you only want this one project to get CodeNavi-aware behavior.
  • --agents-file PATH: target a specific file (override for testing).

Manual config.toml

If you'd rather not run the script, append plugins/codex/mcp/config.toml.snippet to ~/.codex/config.toml. The minimal block:

[mcp_servers.codenavi]
url = "http://localhost:8765/mcp"
bearer_token_env_var = "CODENAVI_AUTH_TOKEN"

The things that bite people

  1. bearer_token_env_var is the NAME of an env var, not the token. Paste the token value and Codex fails at startup with "Environment variable <token> for MCP server 'codenavi' is not set." Keep CODENAVI_AUTH_TOKEN and export it.
  2. Use the unscoped /mcp path unless you know the codebase name. /mcp/<name> returns "Unknown codebase ''" (404) unless <name> is configured, a single-codebase install is usually named default. Check with list_codebases.
  3. Edit config.toml, not .mcp.json. The latter is Claude Code's.
  4. The plugin does not add the server. It brings the skills and hooks only. Without the [mcp_servers.codenavi] block in config.toml, the skills have no tools to call.

Tool approvals

connect-codenavi.sh auto-approves the read-only query tools (semantic_search, symbol_search, find_callers, impact_analysis, find_references, read_file, …) by writing [mcp_servers.codenavi.tools.<tool>] approval_mode = "approve". Without this, Codex prompts on every call (interactive) or auto-cancels it (non-interactive codex exec), which silently kills the structural tools and makes CodeNavi look broken. The mutating tools (reindex*, crawl, backup, restore, submit_feedback) are deliberately left gated, a destructive or outbound action should stay a conscious approval.

The server also marks each tool with the standard MCP hints (read-only, destructive). Codex always asks before a tool marked destructive: reindex_full, restore, delete_note and cancel_reindex. The full list of hints is in the API reference.

Under the default tool profile the wiki, notes, grep and remaining call-graph tools (find_references, graph_neighborhood, …) run through reveal_tools(call=…), and connect-codenavi.sh auto-approves reveal_tools too, so they work in codex exec. That is safe because, since server 1.3.61, reveal_tools refuses the destructive and outbound tools (reindex_full, cancel_reindex, reindex_docs, backup, restore, delete_note, crawl, cancel_crawl): call those by name, and Codex asks before each one. Against a server older than 1.3.61, reveal_tools could still run them: keep the plugin and the server on the same release.

$codenavi:status in the sandbox

Codex's default sandbox (workspace-write) gives shell commands no network. So the /health check that $codenavi:status runs from the shell fails, while the MCP calls work. The report then says reachable over MCP at <url>; /health probe failed from this shell. That is expected, and the server is fine. You do not need to turn on sandbox network access for it.

Statusline

Codex 0.172 and newer can show the CodeNavi badge in the footer: ✦ <codebase> when the folder is indexed, ◔ 34% while it indexes, 🔒 ✦ when the token is missing, ✦ ✗ when the server does not answer, and the licence expiry. Codex reads it from a small status line provider that connect-codenavi.sh installs in ~/.codenavi/codex/ and selects for you. Skip it with --no-statusline. Switch back to the built-in footer with /statusline → Choose a status line provider → Default status line. The feature is experimental in Codex (tui_extensions_statusline); the script turns it on.

Codex does not report which tools a turn used, so the badge has no 🟢 (CodeNavi used this turn) mark as in Claude Code.

Codex shows no CodeNavi tools, but codex exec works? Codex runs its sessions through a background daemon, and MCP servers get the daemon's environment. A daemon that started before you exported CODENAVI_AUTH_TOKEN starts CodeNavi without it, and the footer shows 🔒 ✦. Close Codex, then run codex app-server daemon restart from a terminal where the token is set. connect-codenavi.sh warns when it finds such a daemon.

The Codex IDE extension

The Codex extension for VS Code, Cursor, Windsurf and JetBrains reads the same ~/.codex/config.toml as the CLI, not the editor's own MCP settings. Wiring the CLI (the script above or codex mcp add) wires both; reload the extension if servers don't appear. The per-editor configs in connecting-vscode.md are for those editors' native MCP clients, not for Codex.

The ChatGPT desktop app (Codex)

Codex in the ChatGPT desktop app reads the same config.toml (on Windows, %USERPROFILE%\.codex\config.toml) and uses the same installed plugin. Wire the CLI and install the plugin as above, and the app gets both: Settings → MCP servers lists codenavi, and $codenavi:status works in an app thread. Verified on Windows with Codex 0.163.

  • No server in the app, but codex mcp list shows it? Update Codex and quit the app from the tray, then start it again. That fixed it in our Windows test.
  • The app's Add server form offers only No auth or OAuth. CodeNavi uses a static token, not OAuth. Choose No auth and save, then add bearer_token_env_var = "CODENAVI_AUTH_TOKEN" to the new [mcp_servers.codenavi] block in config.toml by hand.
  • ChatGPT's Apps dialog is a different surface. It asks for a server URL or tunnel ID and an icon, and it connects from OpenAI's cloud, so it rejects a LAN http:// address ("Some app settings were rejected"). Use config.toml for CodeNavi.

Other MCP clients

Cursor, Windsurf, VS Code, and other MCP-capable clients connect to the same http://localhost:8765/mcp endpoint, but the config shape differs per client (Windsurf uses serverUrl, Cursor needs no type, VS Code uses servers). See connecting-vscode.md for the exact per-client config.