claude-code - 💡(How to fix) Fix [BUG] vscode extension incorrectly prepends /usr/bin to PATH [1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
anthropics/claude-code#56047Fetched 2026-05-05 05:59:34
View on GitHub
Comments
0
Participants
1
Timeline
4
Reactions
0
Participants
Timeline (top)
labeled ×4

When claudeCode.usePythonEnvironment is enabled (the default), the VS Code extension detects the system Python prefix (/usr) as a virtual environment and sets VIRTUAL_ENV=/usr, which prepends /usr/bin to PATH. This changes the PATH ordering for all tool/bash calls within Claude Code sessions.

This happens in projects that have nothing to do with Python and are unaware of this setting, leading to subtle hard-to-diagnose issues which don't reproduce in the user's terminal (or in terminal claude sessions) due to incorrect binary selection (since newer versions are conventionally installed in locations like /usr/local/bin).

Error Message

Error Messages/Logs

Root Cause

In extension.js, the usePythonEnvironment feature (enabled by default) calls into Python environment detection. When no virtual environment is found, it falls back to the system Python, whose sys.prefix is /usr. The venv activation logic then does path.join(VIRTUAL_ENV, "bin")/usr/bin and prepends it to PATH.

This only affects session launches (not the initial auth status call, which uses a different code path).

Fix Action

Workaround

Add to .vscode/settings.json:

{
    "claudeCode.usePythonEnvironment": false
}

Code Example

VIRTUAL_ENV=/usr
PATH=/usr/bin:$PATH

---



---

{
    "claudeCode.usePythonEnvironment": false
}
RAW_BUFFERClick to expand / collapse

Preflight Checklist

  • I have searched existing issues and this hasn't been reported yet (except once where it was closed as stale)
  • This is a single bug report (please file separate reports for different bugs)
  • I am using the latest version of Claude Code

What's Wrong?

Summary

When claudeCode.usePythonEnvironment is enabled (the default), the VS Code extension detects the system Python prefix (/usr) as a virtual environment and sets VIRTUAL_ENV=/usr, which prepends /usr/bin to PATH. This changes the PATH ordering for all tool/bash calls within Claude Code sessions.

This happens in projects that have nothing to do with Python and are unaware of this setting, leading to subtle hard-to-diagnose issues which don't reproduce in the user's terminal (or in terminal claude sessions) due to incorrect binary selection (since newer versions are conventionally installed in locations like /usr/local/bin).

Actual behavior

The extension's Python environment activation logic sets:

VIRTUAL_ENV=/usr
PATH=/usr/bin:$PATH

This causes /usr/bin to appear first in PATH, ahead of /usr/local/bin and any other user-configured entries.

Root cause

In extension.js, the usePythonEnvironment feature (enabled by default) calls into Python environment detection. When no virtual environment is found, it falls back to the system Python, whose sys.prefix is /usr. The venv activation logic then does path.join(VIRTUAL_ENV, "bin")/usr/bin and prepends it to PATH.

This only affects session launches (not the initial auth status call, which uses a different code path).

Impact

  • Programs installed in /usr/local/bin may be shadowed by /usr/bin versions
  • Breaks user expectations about PATH ordering, especially for users who install newer tool versions to /usr/local/bin
  • Does not occur when launching claude from the CLI directly

What Should Happen?

PATH ordering should match the user's login shell. On a typical Ubuntu system with /etc/environment setting PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:..., the user expects /usr/local/bin to come before /usr/bin.

Error Messages/Logs

Steps to Reproduce

  1. Open a project in VS Code that has no Python virtual environment (no .venv, no venv, no conda env)
  2. System Python's sys.prefix is /usr (standard on Debian/Ubuntu)
  3. Start a Claude Code session via the VS Code extension
  4. Run echo $PATH in a Claude bash tool call
  5. Observe /usr/bin is prepended to PATH

Claude Model

None

Is this a regression?

I don't know

Last Working Version

No response

Claude Code Version

2.1.87 (Claude Code)

Platform

Anthropic API

Operating System

Ubuntu/Debian Linux

Terminal/Shell

Other

Additional Information

Workaround

Add to .vscode/settings.json:

{
    "claudeCode.usePythonEnvironment": false
}

Environment

  • Claude Code extension v2.1.87
  • VS Code on Linux (Ubuntu)
  • No Python virtual environment in project
  • System Python at /usr/bin/python3 with sys.prefix = /usr

Refiling #41081, which was closed as stale. The bug still reproduces on the latest version.

extent analysis

TL;DR

Disabling the claudeCode.usePythonEnvironment setting in VS Code can prevent the incorrect modification of the PATH environment variable.

Guidance

  • The issue is caused by the usePythonEnvironment feature in the Claude Code extension, which incorrectly prepends /usr/bin to the PATH when no virtual environment is found.
  • To verify the issue, run echo $PATH in a Claude bash tool call and check if /usr/bin is prepended to the PATH.
  • To mitigate the issue, add the following setting to .vscode/settings.json: json { "claudeCode.usePythonEnvironment": false }
  • This workaround will prevent the modification of the PATH environment variable, ensuring that the user's expected PATH ordering is maintained.

Example

No code snippet is necessary for this issue, as the solution involves modifying a VS Code setting.

Notes

This workaround may have unintended consequences, such as disabling Python environment detection in the Claude Code extension. Further investigation is needed to determine the root cause and develop a more comprehensive solution.

Recommendation

Apply the workaround by disabling the claudeCode.usePythonEnvironment setting, as it is a straightforward and effective solution to prevent the incorrect modification of the PATH environment variable.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

claude-code - 💡(How to fix) Fix [BUG] vscode extension incorrectly prepends /usr/bin to PATH [1 participants]