fix(claude-code-mcp): make run_mcp.sh bootstrap idempotent on Windows#1565
Open
ottopichlhoefer wants to merge 1 commit into
Open
fix(claude-code-mcp): make run_mcp.sh bootstrap idempotent on Windows#1565ottopichlhoefer wants to merge 1 commit into
ottopichlhoefer wants to merge 1 commit into
Conversation
The interpreter probe `[ -x "${VENV}/bin/python" ]` never matches on a
Windows-built venv, where the file is `python.exe` and bash's `-x` test
does not honor PATHEXT. As a result the bootstrap branch fired on every
session start, and `python -m venv` collided with the previously spawned
MCP server still holding `python3.exe`/`pip.exe` open, surfacing as
"Failed to reconnect to plugin:hindsight-memory:hindsight." in Claude
Code.
This change:
- Probes both `bin/python` and `bin/python.exe`, exposing the resolved
interpreter as `${PY}`/`${PIP}` for the rest of the script.
- Splits venv creation from pip-sync. Pip now reruns only when the
requirements cache is missing, requirements drifted, or `mcp` is not
importable from the venv — so warm starts skip pip entirely and avoid
re-running it over a venv that's already in use.
- Aborts with a clear stderr message if venv creation produces no usable
interpreter (rather than failing later inside `exec`).
Fixes vectorize-io#1564.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
bin/pythonandbin/python.exe. On Windows-built venvs the file ispython.exe, and bash's[ -x ]test does not honor PATHEXT — so the previous probe never matched and the bootstrap branch fired on every session start.mcpis not importable from the venv. Warm starts now skip both venv recreation and pip install, which also stops the cascade where re-running pip over the in-use venv hitERROR_SHARING_VIOLATIONon Windows and left orphanpip.exe/python3.exeprocesses locking the venv files.exec.Fixes #1564.
Why
On Windows (msys2 bash +
C:\msys64\mingw64\bin\python.exe), Claude Code loggedFailed to reconnect to plugin:hindsight-memory:hindsight.at every session start.bash -x scripts/run_mcp.shshowed the bootstrap branch firing every time, falling back topython -m venvover an in-use venv, and erroring[Errno 13] Permission denied: '.../venv/bin/python3.exe'. Full reproduction in #1564.Test plan
bash -n hindsight-integrations/claude-code/scripts/run_mcp.sh— clean.execreachesmcp_server.py.mcpimportable): both bootstrap probes short-circuit; script reachesexecwithout touching pip or recreating the venv. Verified on Windows 11 / msys2 5.2.37 / Python 3.12.11.Notes
bin/pythonexists as an extensionless symlink (Linux/macOS) is unchanged: the first branch ofresolve_pystill hits../scripts/hooks/lint.sh.hindsight-integrations/claude-code/tests/covers Python modules, not the bootstrap shell. Happy to wire up a tiny shell-test harness if you want it.