claude-code - 💡(How to fix) Fix Claude Code sets VIRTUAL_ENV='' which breaks pixi-managed pre-commit hooks [4 comments, 3 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#48467Fetched 2026-04-16 06:59:20
View on GitHub
Comments
4
Participants
3
Timeline
10
Reactions
0
Timeline (top)
commented ×4labeled ×4mentioned ×1subscribed ×1

When Claude Code runs in a shell where VIRTUAL_ENV is unset, it explicitly sets VIRTUAL_ENV to an empty string ("") via ~/.claude/settings.json's env section. This empty string propagates to all subprocess calls, including pre-commit hooks, breaking tools that inspect VIRTUAL_ENV.

Root Cause

Claude Code's settings.json had "env": {"VIRTUAL_ENV": ""}, which explicitly sets VIRTUAL_ENV to an empty string for the Claude Code process. Pixi passes environment variables through to child processes without filtering, so ty (and any other tool that checks VIRTUAL_ENV) receives an invalid empty path.

The issue has two parts:

  1. Claude Code should not set VIRTUAL_ENV="" — an empty string is worse than leaving it unset, because tools treat "" as an invalid path rather than ignoring it
  2. More broadly, Claude Code should be aware that pixi environments are conda-style (identified by CONDA_PREFIX), not virtualenv-style (identified by VIRTUAL_ENV). When running in a pixi environment, Claude Code should not set or assume VIRTUAL_ENV

Fix Action

Workaround

Wrap git/pixi commands with env -u VIRTUAL_ENV bash -c '...' via a PreToolUse hook to ensure subprocesses don't inherit the invalid value.

🤖 Reported via Claude Code

Code Example

ty failed
     Cause: Failed to discover local Python environment
     Cause: Invalid `VIRTUAL_ENV` environment variable ``: does not point to a directory on disk
RAW_BUFFERClick to expand / collapse

Summary

When Claude Code runs in a shell where VIRTUAL_ENV is unset, it explicitly sets VIRTUAL_ENV to an empty string ("") via ~/.claude/settings.json's env section. This empty string propagates to all subprocess calls, including pre-commit hooks, breaking tools that inspect VIRTUAL_ENV.

Environment

  • OS: Linux (Ubuntu)
  • Package manager: Pixi (conda-based, not virtualenv)
  • Type checker: ty (from Astral)
  • Pre-commit hook: pixi run -e dev ty check src/ with language: system

Steps to reproduce

  1. Have a project using Pixi for environment management with a pre-commit hook that calls pixi run ... ty check
  2. Open Claude Code in that project
  3. Ask Claude to commit — Claude calls git commit, which triggers pre-commit, which calls pixi run -e dev ty check src/
  4. ty fails with:
    ty failed
      Cause: Failed to discover local Python environment
      Cause: Invalid `VIRTUAL_ENV` environment variable ``: does not point to a directory on disk

Root cause

Claude Code's settings.json had "env": {"VIRTUAL_ENV": ""}, which explicitly sets VIRTUAL_ENV to an empty string for the Claude Code process. Pixi passes environment variables through to child processes without filtering, so ty (and any other tool that checks VIRTUAL_ENV) receives an invalid empty path.

The issue has two parts:

  1. Claude Code should not set VIRTUAL_ENV="" — an empty string is worse than leaving it unset, because tools treat "" as an invalid path rather than ignoring it
  2. More broadly, Claude Code should be aware that pixi environments are conda-style (identified by CONDA_PREFIX), not virtualenv-style (identified by VIRTUAL_ENV). When running in a pixi environment, Claude Code should not set or assume VIRTUAL_ENV

Expected behavior

  • Claude Code should leave VIRTUAL_ENV unset if there is no active virtualenv
  • Claude Code should recognize pixi/conda environments via CONDA_PREFIX rather than VIRTUAL_ENV

Workaround

Wrap git/pixi commands with env -u VIRTUAL_ENV bash -c '...' via a PreToolUse hook to ensure subprocesses don't inherit the invalid value.

🤖 Reported via Claude Code

extent analysis

TL;DR

To fix the issue, modify Claude Code's settings.json to not set VIRTUAL_ENV to an empty string when it's unset, and consider recognizing pixi/conda environments via CONDA_PREFIX.

Guidance

  • Verify that the VIRTUAL_ENV variable is not being set in Claude Code's settings.json to prevent it from being propagated to subprocesses.
  • Use the env -u VIRTUAL_ENV bash -c '...' wrapper as a PreToolUse hook to ensure subprocesses don't inherit the invalid VIRTUAL_ENV value.
  • Consider updating Claude Code to recognize pixi/conda environments via CONDA_PREFIX instead of relying on VIRTUAL_ENV.
  • Test the changes by running the pre-commit hook and verifying that ty no longer fails due to an invalid VIRTUAL_ENV variable.

Example

// settings.json update
{
  "env": {
    // Remove or comment out the VIRTUAL_ENV setting
    // "VIRTUAL_ENV": ""
  }
}

Notes

This solution assumes that the issue is caused by Claude Code setting VIRTUAL_ENV to an empty string. If the issue persists after applying the workaround, further investigation may be needed to determine the root cause.

Recommendation

Apply the workaround by using the env -u VIRTUAL_ENV bash -c '...' wrapper as a PreToolUse hook, as this provides a safe and effective way to prevent the invalid VIRTUAL_ENV value from being propagated to subprocesses.

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…

FAQ

Expected behavior

  • Claude Code should leave VIRTUAL_ENV unset if there is no active virtualenv
  • Claude Code should recognize pixi/conda environments via CONDA_PREFIX rather than VIRTUAL_ENV

Still need to ship something?

×6

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

Back to top recommendations

TRENDING