{"record":{"id":"064044926e4b78aa","repo":"helix-editor/helix","slug":"no-previous-working-directory","errorCode":null,"errorMessage":"No previous working directory","messagePattern":"No previous working directory","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"warning","filePath":"helix-term/src/commands/typed.rs","lineNumber":1319,"sourceCode":"fn show_clipboard_provider(\n    cx: &mut compositor::Context,\n    _args: Args,\n    event: PromptEvent,\n) -> anyhow::Result<()> {\n    if event != PromptEvent::Validate {\n        return Ok(());\n    }\n\n    cx.editor\n        .set_status(cx.editor.registers.clipboard_provider_name());\n    Ok(())\n}\n\n/// Helper function to parse the first argument as a directory\n#[inline]\nfn parse_first_arg_as_dir(args: &Args, last_cwd: Option<PathBuf>) -> anyhow::Result<PathBuf> {\n    match args.first().map(AsRef::as_ref) {\n        Some(\"-\") => last_cwd.ok_or_else(|| anyhow!(\"No previous working directory\")),\n        Some(path) => Ok(helix_stdx::path::expand_tilde(Path::new(path)).into_owned()),\n        None => Ok(home_dir()?),\n    }\n}\n\n/// Helper function to apply a directory change for an already-parsed Path ref\n#[inline]\nfn apply_directory_change(cx: &mut compositor::Context, dir: &Path) -> anyhow::Result<()> {\n    cx.editor.set_cwd(dir).map_err(|err| {\n        anyhow!(\n            \"Could not change working directory to '{}': {err}\",\n            dir.display()\n        )\n    })?;\n\n    cx.editor.set_status(format!(\n        \"Current working directory is now {}\",\n        helix_stdx::env::current_working_dir().display()","sourceCodeStart":1301,"sourceCodeEnd":1337,"githubUrl":"https://github.com/helix-editor/helix/blob/079a789e8cb08ead67f19e1971a1b7438b37354b/helix-term/src/commands/typed.rs#L1301-L1337","documentation":"`: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.","triggerScenarios":"`:cd -` (or a keybinding mapped to ':cd -') as the very first directory change after starting helix.","commonSituations":"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.","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)."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// only offer ':cd -' when a previous cwd exists\nif last_cwd.is_some() {\n    // safe to run :cd -\n} else {\n    // fall back to an explicit path\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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."],"tags":["cwd","command"],"backgroundTag":null,"analyzedSha":"079a789e8cb08ead67f19e1971a1b7438b37354b","analyzedAt":"2026-08-16T09:09:59.668Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}