fix: prefer project-scoped env vars over CLAUDE_FLOW_CWD fallback#1618
Open
shaun0927 wants to merge 2 commits intoruvnet:mainfrom
Open
fix: prefer project-scoped env vars over CLAUDE_FLOW_CWD fallback#1618shaun0927 wants to merge 2 commits intoruvnet:mainfrom
shaun0927 wants to merge 2 commits intoruvnet:mainfrom
Conversation
The installer-level CLAUDE_FLOW_CWD fallback is useful for bootstrapping away from / and System32, but it should not outrank project-specific runtime env vars once the host can provide them. This change makes the resolver prefer project-scoped env vars first and adds a regression test covering that priority order. Constraint: Global MCP installs still need a safe fallback when process.cwd() is unusable Rejected: Remove CLAUDE_FLOW_CWD entirely | would reintroduce the bootstrap failures tracked in earlier cwd bugs Confidence: high Scope-risk: narrow Reversibility: clean Directive: Keep getProjectCwd project-scoped; installer fallbacks must never mask richer runtime context Tested: bun import reproduction before/after for session_save path resolution; bunx vitest run v3/@claude-flow/cli/__tests__/mcp-tools-project-cwd.test.ts Not-tested: Real Claude Code/Codex MCP host behavior on Windows/macOS with upstream binaries Related: ruvnet#1617
The PR code already prefers project-scoped env vars over the installer fallback, but the initial regression test only exercised part of that priority chain. This follow-up locks down the highest-priority `CLAUDE_FLOW_PROJECT_DIR` case so future refactors cannot accidentally reintroduce fallback masking. Constraint: Keep the PR scope narrow and avoid touching runtime logic beyond test coverage Rejected: Expand this into broader resolver hardening | would dilute the focused fix under review Confidence: high Scope-risk: narrow Reversibility: clean Directive: If getProjectCwd precedence changes, update tests for every supported env tier together Tested: bunx vitest run v3/@claude-flow/cli/__tests__/mcp-tools-project-cwd.test.ts Not-tested: End-to-end MCP host launches on real Claude Code/Codex clients Related: ruvnet#1617
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
Fixes the project-boundary bug described in #1617.
getProjectCwd()currently prefers the installer fallbackCLAUDE_FLOW_CWDbefore project-scoped runtime env vars. On global MCP installs, that means the fallback can mask richer host context and send session/task/agent state into one shared home-scoped.claude-flow/tree.This PR keeps the scope intentionally narrow: it only changes the resolver priority order and adds a regression test for that order.
Changes
v3/@claude-flow/cli/src/mcp-tools/types.tsCLAUDE_FLOW_PROJECT_DIR,CLAUDE_PROJECT_DIR,INIT_CWD) before the installer fallbackCLAUDE_FLOW_CWDv3/@claude-flow/cli/__tests__/mcp-tools-project-cwd.test.tsWhy this scope
Recent cwd fixes addressed bootstrap failures when MCP servers start at
/orSystem32. This PR targets the narrower follow-up problem: once the host does provide a project directory, the installer fallback should no longer win.That keeps the patch small, reviewable, and low-risk.
Test plan
bunx vitest run v3/@claude-flow/cli/__tests__/mcp-tools-project-cwd.test.tsCLAUDE_FLOW_CWDpinned to a fake home dir,session_savefrom two different projects wrote into the same shared.claude-flow/sessionsdirectoryCLAUDE_PROJECT_DIRset per project andCLAUDE_FLOW_CWDstill pinned to the fake home dir,session_savewrites into each project's local.claude-flow/sessionsdirectory insteadNotes
CLAUDE_FLOW_CWD; it remains the bootstrap fallback for global installs.main.Closes #1617