codebase-memory-mcp cli search_code returns "search failed: temp file" on Windows
On Windows 11 with PowerShell 5.1, running codebase-memory-mcp cli search_code (version 0.5.7) returns {"isError":true} with the text "search failed: temp file", even though the function is visible in the local UI at 127.0.0.1:9749. The same happens in git-bash. What causes this and how do I get around it?
Originally asked on GitHub: https://github.com/DeusData/codebase-memory-mcp/issues/196
5 answers
The thread identifies the cause as a hardcoded temp file path. In src/mcp/mcp.c, write_pattern_file() writes to /tmp/cbm_search_.pat. On Windows, /tmp only resolves if C:/tmp exists. If it does not, fopen() fails and search_code reports "search failed: temp file".
The commenter's immediate workaround is to create the folder:
mkdir C:\tmpA second problem was reported: the grep command built by build_grep_cmd uses Unix shell syntax (single-quoted arguments,
<stdin redirection with xargs,2>/dev/null) passed to _popen(), which cmd and PowerShell do not understand. That can produce zero matches even after the temp file issue is fixed.A contributor said a diff they posted in the thread makes the tool work. Its exact contents are not reproduced here, and the thread does not show a released version containing the fix. The suggested permanent fix is to use GetTempPath2A under _WIN32 for the temp location. The status of the change is not confirmed in the thread beyond the issue being closed as completed.
General advice: build from source with the contributor's patch if you need a fix now, since the reporter was using a prebuilt .exe.
Did this work for you?What a GitHub user tried on GitHub (Didn't work)
Ran
codebase-memory-mcp cli search_code '{"project": "my-project-name", "pattern": "my_function"}'in PowerShell 5.1 on Windows 11 23H2 with version 0.5.7. Got "search failed: temp file". Same result in git-bash.Source: https://github.com/DeusData/codebase-memory-mcp/issues/196 (opens external site)
Did this work for you?What @FabienCont tried on GitHub (Partly worked)
Suggested creating the C:/tmp folder as a quick fix for the hardcoded /tmp path. Also flagged that build_grep_cmd uses Unix shell syntax that cmd and PowerShell cannot run, so matches fail even after the temp file issue is resolved.
Did this work for you?What @LouisMayor tried on GitHub (Outcome unclear)
Suggested using GetTempPath2A under _WIN32 for a permanent temp path fix instead of the hardcoded /tmp.
Did this work for you?What @noctrex tried on GitHub (Outcome unclear)
A contributor said applying their posted diff makes the tool work on Windows.
Did this work for you?
Related questions
- Claude Code hook blocks every Read instead of once per session, how to fix?
- search_code always returns 0 results – ripgrep invoked without explicit path
- Does codebase-memory-mcp support PowerShell (.ps1, .psm1, .psd1) files?
- codebase-memory-mcp install/update fails with 'active CBM sessions could not be stopped safely' after killed processes
- codebase-memory-mcp PreToolUse hook blocks Read/Grep on non-code files