claude-code - 💡(How to fix) Fix CWD is polluted with empty boundary files at every session start (package.json, yarn.lock, .env.*, etc.)

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…

Every claude session creates 10+ empty (0-byte) files and a node_modules/ directory in the current working directory (CWD) at startup. These cannot be disabled through any documented setting, including sandbox.enabled: false.

Root Cause

  • Users expect cd ~/my-workspace && claude to leave the workspace untouched.
  • The empty files conflict with real project initialization (npm init, bun init) because they already exist.
  • Users must add all ~18 filenames to .gitignore to prevent pollution in version control.
  • Several of the files (.env*) have security implications — their presence can change how other tools (Next.js, Vite, Docker Compose) interpret the directory.

Fix Action

Fix / Workaround

Workarounds tried

Code Example

.env
.env.development
.env.development.local
.env.local
.env.production
.env.production.local
.env.test
.env.test.local
.gitmodules
.npmrc
.yarnrc
.yarnrc.yml
bunfig.toml
package.json
package-lock.json
pnpm-lock.yaml
yarn.lock
node_modules/.bin/   (empty directory)

---

2026-04-21 11:15:14.378440534 +0900 .env
2026-04-21 11:15:14.378440534 +0900 .env.development
2026-04-21 11:15:14.378440534 +0900 package.json
2026-04-21 11:15:14.378440534 +0900 bunfig.toml
...
RAW_BUFFERClick to expand / collapse

Summary

Every claude session creates 10+ empty (0-byte) files and a node_modules/ directory in the current working directory (CWD) at startup. These cannot be disabled through any documented setting, including sandbox.enabled: false.

Environment

  • Claude Code version: 2.1.116
  • OS: Linux 6.6.87.2-microsoft-standard-WSL2 (Ubuntu on WSL2)
  • Shell: bash

Reproduction

  1. mkdir /tmp/repro && cd /tmp/repro
  2. claude (any session, even with no prompt)
  3. ls -la in CWD

Expected

CWD remains untouched unless the user explicitly creates files.

Actual

The following 0-byte files and directory are created at startup (all with the same nanosecond timestamp, indicating a single programmatic burst):

.env
.env.development
.env.development.local
.env.local
.env.production
.env.production.local
.env.test
.env.test.local
.gitmodules
.npmrc
.yarnrc
.yarnrc.yml
bunfig.toml
package.json
package-lock.json
pnpm-lock.yaml
yarn.lock
node_modules/.bin/   (empty directory)

Additionally, bind-mounts (character devices owned by nobody:nogroup) are placed over common user config files (.bashrc, .zshrc, .gitconfig, .mcp.json, .idea, .vscode, scripts, etc.) at initial CWD entry.

Hypothesis (unverified)

The Claude Code binary appears to be compiled with bun build --compile. strings on the installed binary reveals:

  • JavaScriptCore / Bun runtime symbols (JSLexicalEnvironment_variables, JSC::FTL::...)
  • The exact filenames above embedded as literals
  • Bun compile flags: --no-compile-autoload-dotenv, --no-compile-autoload-bunfig, --no-compile-autoload-package-json

This suggests the embedded Bun runtime's autoload discovery (or a related isolation layer) is responsible, but the precise creation path is opaque to end users.

Why this matters

  • Users expect cd ~/my-workspace && claude to leave the workspace untouched.
  • The empty files conflict with real project initialization (npm init, bun init) because they already exist.
  • Users must add all ~18 filenames to .gitignore to prevent pollution in version control.
  • Several of the files (.env*) have security implications — their presence can change how other tools (Next.js, Vite, Docker Compose) interpret the directory.

Workarounds tried

  1. Setting "sandbox": { "enabled": false } in both ~/.claude/settings.json and ./.claude/settings.local.jsonno effect, files still created.
  2. Disabling all plugins — no effect.
  3. Custom SessionStart hooks — cannot prevent, only react.

Request

Please provide one of:

  1. A documented setting to disable boundary-file creation (e.g. "workspace": { "isolateCwd": false }).
  2. An environment variable (e.g. CLAUDE_CODE_NO_CWD_MARKERS=1).
  3. Runtime CLI flags that pass through to the embedded Bun's --no-compile-autoload-* family.
  4. At minimum, documentation explaining which files are created, why, and that users should run claude only in disposable or dedicated directories.

Additional info

All files created in a single syscall burst — example stat output:

2026-04-21 11:15:14.378440534 +0900 .env
2026-04-21 11:15:14.378440534 +0900 .env.development
2026-04-21 11:15:14.378440534 +0900 package.json
2026-04-21 11:15:14.378440534 +0900 bunfig.toml
...

extent analysis

TL;DR

The issue can be mitigated by running claude in a dedicated or disposable directory to avoid polluting the current working directory with auto-generated files.

Guidance

  • Investigate the --no-compile-autoload-* family of flags for the embedded Bun runtime to see if any can be passed through to disable the creation of specific files.
  • Consider setting up a custom SessionStart hook to immediately clean up the generated files, although this is not a prevention but rather a reaction.
  • Look into the possibility of using environment variables or undocumented settings that might control the behavior of the Claude Code binary, such as CLAUDE_CODE_NO_CWD_MARKERS.
  • Review the documentation and source code of Claude Code and the embedded Bun runtime for any clues on how to disable or customize this behavior.

Example

No specific code example can be provided without further information on the internal workings of the Claude Code binary and its interaction with the Bun runtime. However, a potential approach could involve using a hook or script to clean up the generated files:

# Example cleanup script
claude_cleanup() {
  # List of files to remove
  files_to_remove=(.env .env.development package.json bunfig.toml)
  for file in "${files_to_remove[@]}"; do
    rm -f "$file"
  done
  # Remove the node_modules directory
  rm -rf node_modules
}

# Run claude_cleanup after each claude session
claude; claude_cleanup

Notes

The provided information suggests that the issue is deeply rooted in how the Claude Code binary is compiled with the Bun runtime and its autoload discovery mechanism. Without direct access to the source code or more detailed documentation, finding a definitive solution might be challenging.

Recommendation

Apply a workaround by running claude in a dedicated or disposable directory to avoid polluting the current working directory. This approach, while not a direct fix, mitigates the issue by containing the auto-generated files within a controlled environment.

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…

Still need to ship something?

×6

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

Back to top recommendations

TRENDING

claude-code - 💡(How to fix) Fix CWD is polluted with empty boundary files at every session start (package.json, yarn.lock, .env.*, etc.)