helix-editor/helix · warning · anyhow::Error
No previous working directory
Error message
No previous working directory
What it means
`:cd -` / `:chdir -` switches to the previously used working directory, tracked as last_cwd whenever helix changes directories in-session. If helix has never changed directory this session, the Option is None and parse_first_arg_as_dir fails with 'No previous working directory' before anything is touched.
Source
Thrown at helix-term/src/commands/typed.rs:1319
fn show_clipboard_provider(
cx: &mut compositor::Context,
_args: Args,
event: PromptEvent,
) -> anyhow::Result<()> {
if event != PromptEvent::Validate {
return Ok(());
}
cx.editor
.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()View on GitHub (pinned to 079a789e8c)
Solutions
- Change to an explicit path first (`:cd ~` or `:cd /path`); afterwards `:cd -` works.
- If you only want home, use `:cd` with no argument (defaults to the home directory).
Defensive patterns
Strategy: validation
Validate before calling
// only offer ':cd -' when a previous cwd exists
if last_cwd.is_some() {
// safe to run :cd -
} else {
// fall back to an explicit path
} Prevention
- Do one explicit `:cd <dir>` early in the session so '-' always has a target.
- Bind ':cd ~' or absolute paths instead of ':cd -' in fire-and-forget keymaps.
When it happens
Trigger: `:cd -` (or a keybinding mapped to ':cd -') as the very first directory change after starting helix.
Common situations: Shell `cd -` muscle memory used too early; keymaps that assume a previous directory always exists; scripts/macros replaying a :cd sequence from a fresh session.
Related errors
- Could not change working directory to '{}': {err}
- Current working directory does not exist
- Current working directory does not exist
- failed to parse arguments: {err}
- Unknown key `{}`
AI-assisted analysis of helix-editor/helix@079a789e8c (2026-08-16).
Data as JSON: /api/errors/064044926e4b78aa.
Report an issue: GitHub.