Local code intelligence for developers and AI agents. Connect code, docs and infrastructure in a persistent graph, with CBM Lens, MCP tools, agent integrations and change-aware test selection.
C aiderastclaude-codecode-analysiscode-intelligencecodexcursorcypherdeveloper-toolsgemini-cligraph-visualizationkilocodeknowledge-graphmcpmcp-servermodel-context-protocolopencodesqlitetree-sitterwindsurf
fix(cli): forward CBM_CACHE_DIR to the Codex-spawned server (#1562)
Martin Vogel63f26f4ce1d5
diff --git a/src/cli/cli.c b/src/cli/cli.cindex 8f6b25adf..f07c0ca6a 100644--- a/src/cli/cli.c+++ b/src/cli/cli.c@@ -3278,8 +3278,22 @@ int cbm_upsert_codex_mcp(const char *binary_path, const char *config_path) {return CLI_ERR;}char block[CLI_BUF_8K];+ /* #1562: Codex sanitizes the environment of stdio MCP subprocesses, passing+ * through only the names listed in env_vars. Without CBM_CACHE_DIR the+ * Codex-spawned server silently falls back to the DEFAULT cache while the+ * account daemon uses the configured one; the two disagree and the+ * handshake closes during initialization, so Codex exposes no cbm tools at+ * all.+ *+ * The name is listed unconditionally rather than only when the variable is+ * set at install time: env_vars names variables to FORWARD IF PRESENT, so+ * listing it costs nothing when unset and keeps working for someone who+ * sets it after installing — which install-time detection would silently+ * fail to cover. */int written = snprintf(block, sizeof(block),- CODEX_CMM_SECTION "\ncommand = \"%s\"\nargs = []\n", escaped);+ CODEX_CMM_SECTION "\ncommand = \"%s\"\nargs = []\n"+ "env_vars = [\"CBM_CACHE_DIR\"]\n",+ escaped);if (written < 0 || (size_t)written >= sizeof(block) ||cbm_remove_codex_legacy_mcp(config_path) != 0) {return CLI_ERR;diff --git a/tests/test_cli.c b/tests/test_cli.cindex 311bf6397..74a065432 100644--- a/tests/test_cli.c+++ b/tests/test_cli.c@@ -10122,6 +10122,11 @@ TEST(cli_upsert_codex_mcp_fresh) {ASSERT_NOT_NULL(data);ASSERT(strstr(data, "[mcp_servers.codebase-memory-mcp]") != NULL);ASSERT(strstr(data, "/usr/local/bin/codebase-memory-mcp") != NULL);+ /* #1562: Codex passes only the names listed in env_vars into a stdio MCP+ * subprocess. Without CBM_CACHE_DIR the spawned server uses the DEFAULT+ * cache while the daemon uses the configured one, the two disagree, and the+ * handshake closes — Codex then shows no cbm tools at all. */+ ASSERT(strstr(data, "env_vars = [\"CBM_CACHE_DIR\"]") != NULL);test_rmdir_r(tmpdir);PASS();