Hmbown/CodeWhale · error
failed to enter ACP session cwd
Error message
failed to enter ACP session cwd {}: {err} What it means
ScopedCurrentDir::new switches the process working directory to the ACP session's cwd and returns this error if std::env::set_current_dir fails (e.g. the directory does not exist or is not accessible). The guard restores the prior directory on Drop.
Solutions
- Verify the session cwd path exists and is a directory before sending session/new
- Create the directory or correct the cwd value sent by the ACP client
- Check filesystem permissions on the target directory
- Re-mount the volume if the path lives on an unmounted mount point
Example fix
// before: ACP client sends stale cwd
{"cwd": "/home/user/removed-project"}
// after: ensure it exists client-side
if !Path::new(&cwd).is_dir() { fs::create_dir_all(&cwd)?; } Defensive patterns
Strategy: validation
Validate before calling
fn ensure_session_cwd(cwd: &Path) -> std::io::Result<()> {
if cwd.as_os_str().is_empty() { return Ok(()); }
let meta = std::fs::metadata(cwd)?;
if !meta.is_dir() {
return Err(std::io::Error::new(std::io::ErrorKind::NotADirectory, "not a directory"));
}
std::env::set_current_dir(cwd) // probe accessibility
} Type guard
fn cwd_is_usable(p: &PathBuf) -> bool {
!p.as_os_str().is_empty() && p.is_dir()
} Try / catch
match ScopedCurrentDir::new(&cwd) {
Ok(guard) => { /* run session work */ }
Err(e) => eprintln!("cannot enter session cwd: {e:#}; check the path exists and is accessible"),
} Prevention
- Validate session cwd on session creation and persist an existing path
- Re-check the path before session resume (it may have been deleted)
- Mount all client-referenced paths into containers
- Avoid sending relative or empty paths except intentionally
When it happens
Trigger: Starting or resuming an ACP session whose cwd PathBuf points to a deleted, renamed, permission-restricted, or non-directory path (empty cwd is allowed and skips the change).
Common situations: Client sends a session/new or load request with a cwd that was deleted since registration, a typo'd path, or a path on an unmounted volume; running in a container where the host path was never mounted.
Related errors
- owned skill anchor does not exist
- owned skill parent does not exist
- already exists; pass --force to overwrite it
- Android loaded image
- approval log has no parent
AI-assisted analysis of Hmbown/CodeWhale@73e0f67d83 (2026-09-22).
Data as JSON: /api/errors/7f01f0ed8fe43a54.
Report an issue: GitHub.
Appendix: source
Thrown at crates/tui/src/acp_server.rs:2408
"sessionId": session_id,
"update": update
}
});
write_json_line(writer, notification).await
}
struct ScopedCurrentDir {
prior: PathBuf,
}
impl ScopedCurrentDir {
fn new(cwd: &PathBuf) -> Result<Self> {
let prior = std::env::current_dir()?;
if cwd.as_os_str().is_empty() {
return Ok(Self { prior });
}
std::env::set_current_dir(cwd)
.map_err(|err| anyhow!("failed to enter ACP session cwd {}: {err}", cwd.display()))?;
Ok(Self { prior })
}
}
impl Drop for ScopedCurrentDir {
fn drop(&mut self) {
let _ = std::env::set_current_dir(&self.prior);
}
}
impl AcpError {
fn invalid_params(message: impl Into<String>) -> Self {
Self {
code: -32602,
message: message.into(),
}
}
View on GitHub (pinned to 73e0f67d83)