-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
fix: resolve Claude CLI not found on Windows - PATH, prompt size, cwd (#1661) #1843
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
4bb2e56
d646c84
63ef050
90df55c
17345df
17eb196
3f617a0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | |||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -22,10 +22,10 @@ | ||||||||||||||||||||||||||||
| import { buildMemoryEnvVars } from '../memory-env-builder'; | |||||||||||||||||||||||||||||
| import { readSettingsFile } from '../settings-utils'; | |||||||||||||||||||||||||||||
| import type { AppSettings } from '../../shared/types/settings'; | |||||||||||||||||||||||||||||
| import { getOAuthModeClearVars } from './env-utils'; | |||||||||||||||||||||||||||||
| import { getOAuthModeClearVars, normalizeEnvPathKey, mergePythonEnvPath } from './env-utils'; | |||||||||||||||||||||||||||||
Check noticeCode scanning / CodeQL Unused variable, import, function or class Note
Unused import normalizeEnvPathKey.
Copilot AutofixAI 1 day ago In general, to fix an unused import, remove the unused symbol from the import clause, or, if all imported symbols are unused, remove the entire import statement. This avoids confusion and keeps the module’s dependency surface minimal. Here, only Concretely:
Suggested changeset
1
apps/frontend/src/main/agent/agent-process.ts
Copilot is powered by AI and may make mistakes. Always verify output.
Refresh and try again.
|
|||||||||||||||||||||||||||||
| import { getAugmentedEnv } from '../env-utils'; | |||||||||||||||||||||||||||||
| import { getToolInfo, getClaudeCliPathForSdk } from '../cli-tool-manager'; | |||||||||||||||||||||||||||||
| import { killProcessGracefully, isWindows } from '../platform'; | |||||||||||||||||||||||||||||
| import { killProcessGracefully, isWindows, getPathDelimiter } from '../platform'; | |||||||||||||||||||||||||||||
| import { debugLog } from '../../shared/utils/debug-logger'; | |||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||
| /** | |||||||||||||||||||||||||||||
|
|
@@ -679,15 +679,25 @@ | ||||||||||||||||||||||||||||
| }, | |||||||||||||||||||||||||||||
| }); | |||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||
| // Parse Python commandto handle space-separated commands like "py -3" | |||||||||||||||||||||||||||||
| // Merge PATH from pythonEnv with augmented PATH from env. | |||||||||||||||||||||||||||||
| // pythonEnv may contain its own PATH (e.g., on Windows with pywin32_system32 prepended). | |||||||||||||||||||||||||||||
| // Simply spreading pythonEnv after env would overwrite the augmented PATH (which includes | |||||||||||||||||||||||||||||
| // npm globals, homebrew, etc.), causing "Claude code not found" on Windows (#1661). | |||||||||||||||||||||||||||||
| // mergePythonEnvPath() normalizes PATH key casing and prepends pythonEnv-specific paths. | |||||||||||||||||||||||||||||
| const mergedPythonEnv = { ...pythonEnv }; | |||||||||||||||||||||||||||||
| const pathSep = getPathDelimiter(); | |||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||
| mergePythonEnvPath(env as Record<string, string | undefined>, mergedPythonEnv as Record<string, string | undefined>, pathSep); | |||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||
| // Parse Python command to handle space-separated commands like "py -3" | |||||||||||||||||||||||||||||
| const [pythonCommand, pythonBaseArgs] = parsePythonCommand(this.getPythonPath()); | |||||||||||||||||||||||||||||
| let childProcess; | |||||||||||||||||||||||||||||
| try { | |||||||||||||||||||||||||||||
| childProcess = spawn(pythonCommand, [...pythonBaseArgs, ...args], { | |||||||||||||||||||||||||||||
| cwd, | |||||||||||||||||||||||||||||
| env: { | |||||||||||||||||||||||||||||
| ...env, // Already includes process.env, extraEnv, profileEnv, PYTHONUNBUFFERED, PYTHONUTF8 | |||||||||||||||||||||||||||||
| ...pythonEnv, // Include Python environment (PYTHONPATH for bundled packages) | |||||||||||||||||||||||||||||
| ...mergedPythonEnv, // Python env with merged PATH (preserves augmented PATH entries) | |||||||||||||||||||||||||||||
| ...oauthModeClearVars, // Clear stale ANTHROPIC_* vars when in OAuth mode | |||||||||||||||||||||||||||||
| ...apiProfileEnv // Include active API profile config (highest priority for ANTHROPIC_* vars) | |||||||||||||||||||||||||||||
| } | |||||||||||||||||||||||||||||
|
Comment on lines
696
to
703
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
# Find pythonEnvManager.getPythonEnv() calls and implementation
rg -n "getPythonEnv" --type=ts -A5 -B5 | head -100Repository: AndyMik90/Auto-Claude Length of output: 10363 🏁 Script executed: #!/bin/bash
# Look for pythonEnvManager definition and initialization
rg -n "pythonEnvManager\s*=" --type=ts -A3 -B3Repository: AndyMik90/Auto-Claude Length of output: 615 🏁 Script executed: #!/bin/bash
# Check the file where pythonEnvManager is defined
fd pythonEnvManager --type=tsRepository: AndyMik90/Auto-Claude Length of output: 234 🏁 Script executed: #!/bin/bash
# Read the getPythonEnv() method implementation
sed -n '690,750p' apps/frontend/src/main/python-env-manager.tsRepository: AndyMik90/Auto-Claude Length of output: 3204 🏁 Script executed: #!/bin/bash
# Read more of the getPythonEnv() implementation to see all returned keys
sed -n '690,800p' apps/frontend/src/main/python-env-manager.tsRepository: AndyMik90/Auto-Claude Length of output: 4692 🏁 Script executed: #!/bin/bash
# Look at agent-process.ts to see mergedPythonEnv construction and context
sed -n '700,750p' apps/frontend/src/main/agent/agent-process.tsRepository: AndyMik90/Auto-Claude Length of output: 2573 🏁 Script executed: #!/bin/bash
# Look at env construction before it's passed to spawn
sed -n '650,730p' apps/frontend/src/main/agent/agent-process.ts | head -100Repository: AndyMik90/Auto-Claude Length of output: 3992 🏁 Script executed: #!/bin/bash
# Check what extraEnv, profileEnv, and other env components contain
rg -n "extraEnv|profileEnv|oauthModeClearVars" apps/frontend/src/main/agent/agent-process.ts -B2 -A2 | head -80Repository: AndyMik90/Auto-Claude Length of output: 3624 🏁 Script executed: #!/bin/bash
# Check setupProcessEnvironment to see what's set in env
sed -n '176,260p' apps/frontend/src/main/agent/agent-process.tsRepository: AndyMik90/Auto-Claude Length of output: 4017 Clarify redundant Python environment variable overrides and document override semantics.
🤖 Prompt for AI Agents |
|||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Edge case: when
max_claude_md_chars <= 0, full CLAUDE.md is included untruncated.If
base_prompt+WINDOWS_TRUNCATION_MESSAGEalready exceedsWINDOWS_MAX_SYSTEM_PROMPT_CHARS, the> 0guard skips truncation and the entire CLAUDE.md is appended — which will definitely exceed the Windows limit. Whilebase_promptis currently short (~400 chars), this is a latent bug if the prompt grows.Proposed fix: omit CLAUDE.md when budget is exhausted
if is_windows(): max_claude_md_chars = ( WINDOWS_MAX_SYSTEM_PROMPT_CHARS - len(base_prompt) - len(WINDOWS_TRUNCATION_MESSAGE) ) - if len(claude_md_content) > max_claude_md_chars > 0: + if max_claude_md_chars <= 0: + claude_md_content = "" + print( + " - CLAUDE.md: omitted (base prompt already near Windows limit)" + ) + was_truncated = True + elif len(claude_md_content) > max_claude_md_chars: claude_md_content = ( claude_md_content[:max_claude_md_chars] + WINDOWS_TRUNCATION_MESSAGE )🤖 Prompt for AI Agents