{"record":{"id":"3e48051e2e60c040","repo":"astral-sh/ruff","slug":"working-directory-does-not-exist","errorCode":null,"errorMessage":"Working directory does not exist","messagePattern":"Working directory does not exist","errorType":"console","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/ruff/src/resolve.rs","lineNumber":25,"sourceCode":"use ruff_workspace::configuration::Configuration;\nuse ruff_workspace::pyproject::{self, find_fallback_target_version};\nuse ruff_workspace::resolver::{\n    ConfigurationOrigin, ConfigurationTransformer, PyprojectConfig, PyprojectDiscoveryStrategy,\n    resolve_root_settings,\n};\n\nuse ruff_python_ast as ast;\n\nuse crate::args::ConfigArguments;\n\n/// Resolve the relevant settings strategy and defaults for the current\n/// invocation.\npub fn resolve(\n    config_arguments: &ConfigArguments,\n    stdin_filename: Option<&Path>,\n) -> Result<PyprojectConfig> {\n    let Ok(cwd) = std::env::current_dir() else {\n        bail!(\"Working directory does not exist\")\n    };\n\n    // First priority: if we're running in isolated mode, use the default settings.\n    if config_arguments.isolated {\n        let config = config_arguments.transform(Configuration::default());\n        let settings = config.into_settings(&cwd)?;\n        debug!(\"Isolated mode, not reading any pyproject.toml\");\n        return Ok(PyprojectConfig::new(\n            PyprojectDiscoveryStrategy::Fixed,\n            settings,\n            None,\n        ));\n    }\n\n    // Second priority: the user specified a `pyproject.toml` file. Use that\n    // `pyproject.toml` for _all_ configuration, and resolve paths relative to the\n    // current working directory. (This matches ESLint's behavior.)\n    if let Some(pyproject) = config_arguments.config_file() {","sourceCodeStart":7,"sourceCodeEnd":43,"githubUrl":"https://github.com/astral-sh/ruff/blob/26f38c119cac42e4d320ba08f09224fdec74af2c/crates/ruff/src/resolve.rs#L7-L43","documentation":"Ruff resolves configuration relative to the current working directory. If `std::env::current_dir()` fails — typically because the process's working directory was deleted or is inaccessible — `resolve` bails with this error since no configuration or file discovery can proceed reliably.","triggerScenarios":"Invoking ruff from a shell whose current directory has been deleted (or is unreadable), so `std::env::current_dir()` returns Err at the start of `resolve`.","commonSituations":"Running ruff in CI or containers after a build step removed the directory the shell sits in; long-lived shells whose project folder was renamed/deleted; sandboxed environments revoking access to the CWD.","solutions":["cd to an existing directory (e.g. the project root) before running ruff.","Recreate the deleted working directory or restore the project checkout.","Fix the wrapper/CI script so it runs ruff from a valid path, e.g. `cd \"$PROJECT_DIR\" && ruff check .`."],"exampleFix":"// before: shell sits in a deleted directory\nruff check .\n// after\ncd /path/to/project && ruff check .","handlingStrategy":"fallback","validationCode":"# Shell: bail early if the CWD is gone before invoking ruff\ncd . 2>/dev/null || { echo \"working directory no longer exists\"; exit 1; }","typeGuard":null,"tryCatchPattern":"// In Rust wrappers: check the CWD before spawning ruff\nmatch std::env::current_dir() {\n    Ok(dir) => run_ruff(&dir),\n    Err(_) => eprintln!(\"Working directory does not exist; cd to a valid path first\"),\n}","preventionTips":["Always launch ruff from a valid project directory.","In CI, avoid deleting the directory the shell occupies mid-job.","Use absolute paths or an explicit cd in wrapper scripts."],"tags":["cli","filesystem","configuration","ruff"],"backgroundTag":"working-directory-missing","analyzedSha":"26f38c119cac42e4d320ba08f09224fdec74af2c","analyzedAt":"2026-09-05T10:32:37.492Z","contentChangedAt":"2026-09-05T10:32:37.492Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}