Claude Code sets VIRTUAL_ENV='' which breaks pixi-managed pre-commit hooks
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/withlanguage: system
Steps to reproduce
- Have a project using Pixi for environment management with a pre-commit hook that calls
pixi run ... ty check - Open Claude Code in that project
- Ask Claude to commit — Claude calls
git commit, which triggers pre-commit, which callspixi run -e dev ty check src/ tyfails with:
``VIRTUAL_ENV
ty failed
Cause: Failed to discover local Python environment
Cause: Invalid 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:
- 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 - More broadly, Claude Code should be aware that pixi environments are conda-style (identified by
CONDA_PREFIX), not virtualenv-style (identified byVIRTUAL_ENV). When running in a pixi environment, Claude Code should not set or assumeVIRTUAL_ENV
Expected behavior
- Claude Code should leave
VIRTUAL_ENVunset if there is no active virtualenv - Claude Code should recognize pixi/conda environments via
CONDA_PREFIXrather thanVIRTUAL_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
This issue has 5 comments on GitHub. Read the full discussion on GitHub ↗