{"record":{"id":"f7781ab5fbcfa814","repo":"jdx/mise","slug":"directory-specified-with-cd-does-not-exist-p","errorCode":null,"errorMessage":"Directory specified with --cd does not exist: {}\nPlease check the path and try again.","messagePattern":"Directory specified with --cd does not exist: (.+?)\nPlease check the path and try again\\.","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cli/mod.rs","lineNumber":982,"sourceCode":"/// Check if the current working directory exists and warn if not\nfn check_working_directory() {\n    if std::env::current_dir().is_err() {\n        // Try to get the directory path from PWD env var, which might still contain the old path\n        let dir_path = std::env::var(\"PWD\")\n            .or_else(|_| std::env::var(\"OLDPWD\"))\n            .unwrap_or_else(|_| \"(unknown)\".to_string());\n        warn!(\n            \"Current directory does not exist or is not accessible: {}\",\n            dir_path\n        );\n    }\n}\n\n/// Validate the --cd path if provided and return an error if it doesn't exist\nfn validate_cd_path(cd: &Option<PathBuf>) -> Result<()> {\n    if let Some(path) = cd {\n        if !path.exists() {\n            bail!(\n                \"Directory specified with --cd does not exist: {}\\n\\\n                 Please check the path and try again.\",\n                ui::style::epath(path)\n            );\n        }\n        if !path.is_dir() {\n            bail!(\n                \"Path specified with --cd is not a directory: {}\\n\\\n                 Please provide a valid directory path.\",\n                ui::style::epath(path)\n            );\n        }\n    }\n    Ok(())\n}\n\n#[cfg(test)]\nmod tests {","sourceCodeStart":964,"sourceCodeEnd":1000,"githubUrl":"https://github.com/jdx/mise/blob/6f52dcdf99e282ef7a7db68c81301fa4618d0f79/src/cli/mod.rs#L964-L1000","documentation":"mise validates the global `--cd` flag (validate_cd_path) before running any subcommand. This error means the directory you passed with `--cd` does not exist on disk, so mise refuses up front rather than running the command against a wrong or default working directory.","triggerScenarios":"Any subcommand with a nonexistent `--cd` path: `mise --cd /home/me/old-project use node`, a deleted/renamed directory, a typo, or a relative path resolved from the current cwd that does not exist there.","commonSituations":"Renamed or moved project while shell history still holds the old path; CI checkout directory changed; path built from an unset env var; tab-completion typo.","solutions":["Fix the path or typo and re-run (`ls` the directory to confirm it exists)","Use an absolute path so it does not depend on your current cwd","If the path comes from a variable, verify it is set and expands correctly (echo \"$DIR\" before running)"],"exampleFix":"# before\nmise --cd ~/projct use node\n# after\nmise --cd ~/project use node","handlingStrategy":"validation","validationCode":"# bash: guard before invoking mise\ndir=\"${1:?usage: mise --cd <dir> ...}\"\n[ -d \"$dir\" ] || { echo \"refusing: --cd dir does not exist: $dir\" >&2; exit 1; }\nmise --cd \"$dir\" use node","typeGuard":"is_valid_cd_dir() { [ -d \"$1\" ]; }   # existence implied by -d","tryCatchPattern":null,"preventionTips":["Expand and `ls` the directory once when writing the command instead of relying on stale history","Prefer absolute paths (or $PWD-based) for --cd in scripts","Derive --cd from a verified root (e.g. `git rev-parse --show-toplevel`) rather than hardcoding"],"tags":["mise","cd","path","cli","validation"],"backgroundTag":"file-not-found","analyzedSha":"6f52dcdf99e282ef7a7db68c81301fa4618d0f79","analyzedAt":"2026-08-22T10:14:23.840Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}