[BUG] Cargo creates ./target in workspace even when target-dir is redirected to Docker volume

Resolved 💬 2 comments Opened Apr 1, 2026 by 40tude Closed Apr 2, 2026

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?

Environment

  • Dev container with Docker volume mounted at /home/devuser/rust_target
  • ~/.cargo/config.toml sets target-dir = "/home/devuser/rust_target"
  • Workspace mounted as bind mount at /workspace

Actual behavior

Cargo still creates ./target in the workspace with:

target/
CACHEDIR.TAG
.rustc_info.json
debug/
.cargo-lock
.fingerprint/
build/
deps/
examples/
incremental/

The actual compiled artifacts go to the volume (correct), but these metadata files and empty directories are written to ./target regardless.

What Should Happen?

Expected behavior
With target-dir configured globally in ~/.cargo/config.toml, Cargo should write all output (including metadata) exclusively to the configured path. No ./target directory should be created in the workspace.

The whole point of redirecting target-dir to a Docker volume is to keep build artifacts off the bind-mounted workspace for performance and cleanliness. A partial redirect defeats the purpose.

Error Messages/Logs

None

Steps to Reproduce

  1. Mount a Docker volume at a path outside the workspace (e.g. /home/devuser/rust_target)
  2. Set target-dir in ~/.cargo/config.toml to that path
  3. Run cargo build on any project inside the workspace
  4. Observe that ./target is created in the workspace root despite the redirect

Claude Model

Sonnet (default)

Is this a regression?

I don't know

Last Working Version

_No response_

Claude Code Version

2.1.89

Platform

Anthropic API

Operating System

Ubuntu/Debian Linux

Terminal/Shell

VS Code integrated terminal

Additional Information

_No response_

View original on GitHub ↗

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