BurntSushi/ripgrep · error

failed to get current working directory: {err} did your CWD

Error message

failed to get current working directory: {err}
did your CWD get deleted?

What it means

Error "failed to get current working directory: {err} did your CWD get deleted?" thrown in BurntSushi/ripgrep.

Source

Thrown at crates/core/flags/hiargs.rs:1344

}

/// Attempts to discover the current working directory.
///
/// This mostly just defers to the standard library, however, such things will
/// fail if ripgrep is in a directory that no longer exists. We attempt some
/// fallback mechanisms, such as querying the PWD environment variable, but
/// otherwise return an error.
fn current_dir() -> anyhow::Result<PathBuf> {
    let err = match std::env::current_dir() {
        Err(err) => err,
        Ok(cwd) => return Ok(cwd),
    };
    if let Some(cwd) = std::env::var_os("PWD") {
        if !cwd.is_empty() {
            return Ok(PathBuf::from(cwd));
        }
    }
    anyhow::bail!(
        "failed to get current working directory: {err}\n\
         did your CWD get deleted?",
    )
}

/// Retrieves the hostname that should be used wherever a hostname is required.
///
/// Currently, this is only used in the hyperlink format.
///
/// This works by first running the given binary program (if present and with
/// no arguments) to get the hostname after trimming leading and trailing
/// whitespace. If that fails for any reason, then it falls back to getting
/// the hostname via platform specific means (e.g., `gethostname` on Unix).
///
/// The purpose of `bin` is to make it possible for end users to override how
/// ripgrep determines the hostname.
fn hostname(bin: Option<&Path>) -> Option<String> {
    let Some(bin) = bin else { return platform_hostname() };

View on GitHub (pinned to 3fce3b5bb0)

Solutions

  1. Change to a valid existing directory before running the command
  2. Recreate the deleted working directory or start a new shell

When it happens

Trigger: Thrown at crates/core/flags/hiargs.rs:1344 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of BurntSushi/ripgrep@3fce3b5bb0 (2026-08-06). Data as JSON: /data/errors/f35c2ede3daf4de6.json. Report an issue: GitHub.