[BUG] Large shell environment from nix/direnv causes loss of color and cursor
Preflight Checklist
- [x] I have searched existing issues and this hasn't been reported yet
- [x] This is a single bug report (please file separate reports for different bugs)
- [x] I am using the latest version of Claude Code
What's Wrong?
When Claude Code starts in a directory where direnv + nix-direnv loads a mkShell with many packages, the session loses all color (renders black and white) and the text cursor disappears. The issue persists across new sessions in the same directory but does not affect other directories or the terminal itself.
nix-direnv exports all of mkShell's build-time internals into the shell environment — variables like buildInputs, nativeBuildInputs, phases, stdenv, NIX_CFLAGS_COMPILE, NIXPKGS_CMAKE_PREFIX_PATH, PYTHONPATH, DIRENV_DIFF, etc. With enough packages, this balloons the total environment well beyond what a typical shell has.
Workaround
- Split heavy packages (PyTorch/ROCm) into a separate
devShells.mlactivated on-demand vianix develop .#ml, keeping the direnv-loaded default shell lean - Aggressively
unsetnix build internals in.envrcafteruse flake:
use flake
# Clean up nix mkShell build internals that leak into the environment
unset buildInputs nativeBuildInputs propagatedBuildInputs propagatedNativeBuildInputs
unset buildPhase phases configureFlags cmakeFlags mesonFlags
unset stdenv name out outputs builder
unset depsBuildBuild depsBuildBuildPropagated depsBuildTarget depsBuildTargetPropagated
unset depsHostHost depsHostHostPropagated depsTargetTarget depsTargetTargetPropagated
unset doCheck doInstallCheck dontAddDisableDepTrack preferLocalBuild strictDeps
unset patches __structuredAttrs
unset NIX_CFLAGS_COMPILE NIX_LDFLAGS NIX_ENFORCE_NO_NATIVE NIX_HARDENING_ENABLE
unset NIX_BUILD_CORES NIX_STORE SOURCE_DATE_EPOCH DETERMINISTIC_BUILD
unset NIXPKGS_CMAKE_PREFIX_PATH CMAKE_INCLUDE_PATH CMAKE_LIBRARY_PATH
unset NIX_CC NIX_BINTOOLS CONFIG_SHELL
unset AR AS CC CXX LD NM OBJCOPY OBJDUMP RANLIB READELF SIZE STRINGS STRIP
unset JAVA_HOME CLASSPATH IN_NIX_SHELL HOST_PATH
unset shell shellHook system
What Should Happen?
Expected behavior
Claude Code should render colors and show the cursor regardless of environment size. TERM, COLORTERM, and NO_COLOR are all correct throughout — the terminal capabilities are not affected, only Claude Code's rendering.
Error Messages/Logs
| Configuration | Env size | Color/cursor |
|---|---|---|
| No direnv (base NixOS shell) | ~10 KB | Works |
| direnv + full mkShell (with PyTorch/ROCm) | ~63 KB | **Broken** |
| direnv + full mkShell + unset build internals | ~35 KB | **Broken** |
| direnv + lean mkShell (no PyTorch) + unset build internals | ~30 KB | Works |
| direnv denied entirely | ~10 KB | Works |
The threshold appears to be somewhere between 30–35 KB of total environment size.
The largest individual variables in the full environment:
- `DIRENV_DIFF`: 12 KB (base64-encoded env delta)
- `PYTHONPATH`: 10 KB (nix store paths for all Python packages)
- `NIXPKGS_CMAKE_PREFIX_PATH`: 9 KB
- `PATH`: 6 KB (88 nix store entries)
- `NIX_CFLAGS_COMPILE`: 4 KB
- `NIX_LDFLAGS`: 3 KB
Steps to Reproduce
- Create a nix flake with
mkShellcontaining many packages (see list below) - Use
direnvwithuse flakein.envrc - Start
claudein the directory
Package list that reproduces the issue
This is an FPGA/SoC development environment. The base packages alone work fine — adding ML training packages (PyTorch with ROCm, scikit-learn) pushed the environment over the threshold:
Base packages (works):
- Xilinx Vivado (FHS wrapper via
buildFHSEnv) - LiteX ecosystem:
litex,litex-boards,litedram,liteeth,litespi,litescope,litesdcard,litevideo pythondata-cpu-vexriscv- RISC-V cross-compiler:
pkgsCross.riscv32-embeddedgcc + binutils yosys,openocd- Python libs:
pyyaml,jsonschema,matplotlib,numpy - Serial:
picocom,screen,pyserial - Simulation:
verilator,cocotb - SpinalHDL:
jdk17,sbt - Build tools:
gnumake,cmake,git,dtc,gcc
Packages that pushed it over the limit (broken when added):
python3Packages.torchWithRocmpython3Packages.scikit-learn
Claude Model
Opus
Is this a regression?
I don't know
Last Working Version
_No response_
Claude Code Version
2.1.74
Platform
Anthropic API
Operating System
Other Linux
Terminal/Shell
Xterm
Additional Information
- Claude Code: 2.1.74
- OS: NixOS, Linux 6.19.2
- Node: v22.22.0
- Terminal: xterm-256color, COLORTERM=truecolor
NO_COLORis not set
This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗