helix-editor/helix · error · anyhow::Error
Could not change working directory to '{}': {err}
Error message
Could not change working directory to '{}': {err} What it means
After parse_first_arg_as_dir resolves the target (argument with '~' expanded, '-' as previous dir, or home as default), apply_directory_change calls Editor::set_cwd, which canonicalizes the path and switches the process into it via helix_stdx::env::set_current_working_dir. A nonexistent directory, a path that is a file, or an OS-level permission failure is reported as 'Could not change working directory to <path>: <err>'.
Source
Thrown at helix-term/src/commands/typed.rs:1329
.set_status(cx.editor.registers.clipboard_provider_name());
Ok(())
}
/// Helper function to parse the first argument as a directory
#[inline]
fn parse_first_arg_as_dir(args: &Args, last_cwd: Option<PathBuf>) -> anyhow::Result<PathBuf> {
match args.first().map(AsRef::as_ref) {
Some("-") => last_cwd.ok_or_else(|| anyhow!("No previous working directory")),
Some(path) => Ok(helix_stdx::path::expand_tilde(Path::new(path)).into_owned()),
None => Ok(home_dir()?),
}
}
/// Helper function to apply a directory change for an already-parsed Path ref
#[inline]
fn apply_directory_change(cx: &mut compositor::Context, dir: &Path) -> anyhow::Result<()> {
cx.editor.set_cwd(dir).map_err(|err| {
anyhow!(
"Could not change working directory to '{}': {err}",
dir.display()
)
})?;
cx.editor.set_status(format!(
"Current working directory is now {}",
helix_stdx::env::current_working_dir().display()
));
Ok(())
}
fn change_current_directory(
cx: &mut compositor::Context,
args: Args,
event: PromptEvent,
) -> anyhow::Result<()> {View on GitHub (pinned to 079a789e8c)
Solutions
- Verify the path exists and is a directory (`:sh ls <dir>` or check in a terminal).
- Use an absolute path or a leading '~'; note that arbitrary env vars like $HOME are not expanded inside the prompt.
- If the path exists but still fails, check execute permissions and mount health.
Example fix
# before :cd ~/My Docs # after — quote paths containing spaces where your shell/prompt requires, or escape: :cd "~/My Docs"
Defensive patterns
Strategy: validation
Validate before calling
let p = std::path::Path::new(target);
if !(p.is_dir() && p.canonicalize().is_ok()) {
// refuse early instead of calling :cd and surfacing the OS error
} Prevention
- Verify the target with `:sh ls <dir>` before scripting `:cd` sequences.
- Remember only a leading '~' expands; env vars do not.
When it happens
Trigger: `:cd /nonexistent`; `:cd somefile.txt`; `:cd` into a directory without execute permission; `:cd -` when the previous directory was deleted in the meantime.
Common situations: Typos and missing quotes around paths with spaces; expecting environment variables to expand (only a leading '~' is expanded); mounts that went away; permission-restricted directories.
Related errors
- Current working directory does not exist
- Current working directory does not exist
- No previous working directory
- expected a path to file, but found a directory: {file:?}. (t
- --working-dir specified does not exist or is not a directory
AI-assisted analysis of helix-editor/helix@079a789e8c (2026-08-16).
Data as JSON: /api/errors/68fba864fe29806e.
Report an issue: GitHub.