astral-sh/ruff · error · anyhow::Error
Working directory does not exist
Error message
Working directory does not exist
What it means
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.
Source
Thrown at crates/ruff/src/resolve.rs:25
use ruff_workspace::configuration::Configuration;
use ruff_workspace::pyproject::{self, find_fallback_target_version};
use ruff_workspace::resolver::{
ConfigurationOrigin, ConfigurationTransformer, PyprojectConfig, PyprojectDiscoveryStrategy,
resolve_root_settings,
};
use ruff_python_ast as ast;
use crate::args::ConfigArguments;
/// Resolve the relevant settings strategy and defaults for the current
/// invocation.
pub fn resolve(
config_arguments: &ConfigArguments,
stdin_filename: Option<&Path>,
) -> Result<PyprojectConfig> {
let Ok(cwd) = std::env::current_dir() else {
bail!("Working directory does not exist")
};
// First priority: if we're running in isolated mode, use the default settings.
if config_arguments.isolated {
let config = config_arguments.transform(Configuration::default());
let settings = config.into_settings(&cwd)?;
debug!("Isolated mode, not reading any pyproject.toml");
return Ok(PyprojectConfig::new(
PyprojectDiscoveryStrategy::Fixed,
settings,
None,
));
}
// Second priority: the user specified a `pyproject.toml` file. Use that
// `pyproject.toml` for _all_ configuration, and resolve paths relative to the
// current working directory. (This matches ESLint's behavior.)
if let Some(pyproject) = config_arguments.config_file() {View on GitHub (pinned to 26f38c119c)
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 .`.
Example fix
// before: shell sits in a deleted directory ruff check . // after cd /path/to/project && ruff check .
Defensive patterns
Strategy: fallback
Validate before calling
# Shell: bail early if the CWD is gone before invoking ruff
cd . 2>/dev/null || { echo "working directory no longer exists"; exit 1; } Try / catch
// In Rust wrappers: check the CWD before spawning ruff
match std::env::current_dir() {
Ok(dir) => run_ruff(&dir),
Err(_) => eprintln!("Working directory does not exist; cd to a valid path first"),
} Prevention
- 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.
When it happens
Trigger: 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`.
Common situations: 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.
Related errors
- No files found under the given path
- Expected {}
- Unknown option: {key}
- The argument `--config={}` cannot be used with `--isolated`
- You cannot specify more than one configuration file on the c
AI-assisted analysis of astral-sh/ruff@26f38c119c (2026-09-05).
Data as JSON: /api/errors/3e48051e2e60c040.
Report an issue: GitHub.