[BUG] CLAUDE_CODE_SUBPROCESS_ENV_SCRUB creates empty ~/.bash_profile, ~/.zshrc, package.json, .env* etc. on the host, breaking login shells

Aperta
#112,840 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
25/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
bash, zsh
Ambito
cli, security

Direzione di ricerca

Start from the sandbox start-up code that runs when CLAUDE_CODE_SUBPROCESS_ENV_SCRUB is set and opens each protected path in append mode, which creates empty placeholders in $HOME and the working directory. Run the reproduction in the report with a temp HOME and cwd, then use find -empty to see what gets created. Done means no new files appear in the user's real HOME or project folder, and any placeholders are removed on exit. The maintainers have not chosen between the three options, so confirm the approach in the thread before writing a patch.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

area:sandbox bug has repro platform:linux platform:wsl
Preflight Checklist
  • I have searched existing issues and this hasn't been reported yet
  • This is a single bug report
  • I am using the latest version of Claude Code
What's Wrong?

When CLAUDE_CODE_SUBPROCESS_ENV_SCRUB=1 is set, Claude Code creates empty placeholder files and folders in the real $HOME and in the working directory at start-up, apparently as bind-mount targets for the bubblewrap subprocess sandbox. It opens each path in append mode, so any file that is missing is created empty, and it never removes them.

On a developer machine (not a throwaway CI runner) this silently breaks the user's shell. On Debian/Ubuntu, ~/.bash_profile normally does not exist, and bash login shells read ~/.profile, which sources ~/.bashrc. Once an empty ~/.bash_profile exists, bash reads that instead and skips ~/.profile entirely. Every login shell then loses the user's PATH: nvm, ~/.local/bin, and so on.

What happened to me: one local claude -p run with the variable set (an agent rehearsing a GitHub Actions workflow on the same machine) created ~/.bash_profile. Nothing visible happened until the next reboot. After it, a desktop app that reads PATH from bash -ilc couldn't find claude, codex, opencode or node, and the Claude CLI process exited with code 127. It took a long time to trace back to an empty 0-byte file created a day earlier.

The working directory is also littered with empty package.json, package-lock.json, yarn.lock, pnpm-lock.yaml, .gitmodules, .npmrc, eight .env* files and node_modules/.bin. In an empty folder that is mostly noise, but an empty package.json or lockfile makes npm/yarn/pnpm fail.

What Should Happen?

Enabling the scrub/sandbox should not modify the user's real files. Options:

  • create mount points only inside the sandbox's own mount namespace or tmpfs, not on the host filesystem; or
  • skip protecting paths that don't exist (a path that doesn't exist has nothing to protect; deny creating it instead); or
  • at minimum, remove the placeholders it created on exit, and never create shell startup files (.bash_profile, .bash_login, .profile, .zshrc, …), because their mere existence changes shell behaviour.
Error Messages/Logs
# no error; the symptom appears later, in other programs:
$ bash -ilc 'command -v node'      # nothing: ~/.profile is no longer read
Claude Code process exited with code 127 before it started.
Steps to Reproduce
H=$(mktemp -d); W=$(mktemp -d); cd "$W"
env -i HOME="$H" PATH=/usr/bin:/bin CLAUDE_CODE_SUBPROCESS_ENV_SCRUB=1 claude -p hi </dev/null
# (it can fail to authenticate; the files are created before that)
find "$H" "$W" -empty

Result with 2.1.332 (Linux, bubblewrap installed):

$HOME: .bash_profile .bash_aliases .bashrc .profile .zshrc .gitconfig .netrc .npmrc .yarnrc .yarnrc.yml .bunfig.toml
       dirs: .config/gh .config/git .config/glab-cli .config/pip .pip
cwd:   package.json package-lock.json yarn.lock pnpm-lock.yaml .gitmodules .npmrc .yarnrc .yarnrc.yml bunfig.toml
       .env .env.local .env.development .env.development.local .env.test .env.test.local .env.production .env.production.local
       dirs: .claude/agents .claude/commands node_modules/.bin

All of these are 0 bytes, and none existed before.

Claude Model

Other (not model-related)

Is this a regression?

I don't know

Claude Code Version

2.1.332 (Claude Code)

Platform

Anthropic API

Operating System

Ubuntu/Debian Linux (Ubuntu 26.04 under WSL2)

Additional Information

Workaround for affected users: delete the 0-byte files, especially ~/.bash_profile. To make a machine immune, give ~/.bash_profile real content such as [ -f ~/.profile ] && . ~/.profile, since append-mode opening leaves existing files unchanged.

Lingua principale
TypeScript
Stelle
157k
Fork
25.1k
Merge medio
20h 25m
PR unite (30g)
4

Preparare l'ambiente

Apri in Codespaces

Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.

  • Nessun Dockerfile né file Docker Compose
  • Nessun modello di pull request
  • Nessuna guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di anthropics/claude-code

Tutte le issue di anthropics/claude-code

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.