Claude Code sets VIRTUAL_ENV='' which breaks pixi-managed pre-commit hooks

Resolved 💬 5 comments Opened Apr 15, 2026 by aqc-carlodri Closed May 24, 2026

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

View original on GitHub ↗

This issue has 5 comments on GitHub. Read the full discussion on GitHub ↗