Fixes · Checked on 2026-10-04
cargo: failed to remove file, Access is denied. (os error 5)
The code compiled. Cargo couldn't replace the program, because it's still running.
The error
> cargo build
Compiling app v0.1.0 (C:\code\app)
error: failed to remove file `C:\code\app\target\debug\app.exe`
Caused by:
Access is denied. (os error 5)
Why it happens
Windows locks the .exe of a running program, so it can't be deleted. Cargo deletes the old
.exe before writing the new one, so the build fails if anything is still running it: a server
you started earlier, a daemon, or a copy an agent started in another terminal and left running.
cargo test hits it too when the package has integration tests, because it builds the binary for
them.
The fix
Find what's running it, and stop it the way it's meant to be stopped:
Get-Process app | Select-Object Id, Path
If you can't stop it (a daemon you're using, or one you don't own), build into another target folder instead. The first build there compiles everything from scratch:
$env:CARGO_TARGET_DIR = 'target-alt' # PowerShell
cargo build
CARGO_TARGET_DIR=target-alt cargo build # bash
How DMN learned it
It came up, and was fixed, in 3 of our own sessions, while DMN's own daemon was running. DMN kept the fix
as one line:
When `cargo test -p ide-studio-daemon` fails with "failed to remove file
target\debug\ide-studio-daemon.exe", a running daemon locks it; set $env:CARGO_TARGET_DIR='target-alt'
and rerun.
DMN reads your agents' past sessions on your machine. When the same error is fixed the same way in two or more of them, it keeps the fix as a one-line lesson. When the error turns up again, Claude Code is told the fix straight away, and any agent can search what earlier sessions found. How DMN keeps what agents learn.