jdx/mise · error

Cannot use :task syntax without a current working directory

Error message

Cannot use :task syntax without a current working directory

What it means

Companion guard to 968: when expanding a colon pattern, mise needs the current working directory to compute the monorepo scope; if dirs::CWD is None (process has no resolvable cwd), it cannot expand ':' patterns and bails. Bare names are returned as-is for global matching.

Source

Thrown at src/task/task_load_context.rs:254

        if let Some(scope) = monorepo_scope(&monorepo_root, scope_dir) {
            // For bare task names, only expand if we're actually in the monorepo
            // For colon patterns, always expand (and error if outside monorepo)

            if is_colon_pattern {
                Ok(format!("{scope}{task}"))
            } else {
                Ok(format!("{scope}:{task}"))
            }
        } else {
            if is_colon_pattern {
                bail!("Cannot use :task syntax outside of monorepo root directory");
            }
            // Bare name outside monorepo - return as-is for global matching
            Ok(task.to_string())
        }
    } else {
        if is_colon_pattern {
            bail!("Cannot use :task syntax without a current working directory");
        }
        Ok(task.to_string())
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_monorepo_scope() {
        let root = Path::new("repo");
        assert_eq!(monorepo_scope(root, root), Some("//".to_string()));
        assert_eq!(
            monorepo_scope(root, &root.join("apps").join("api")),
            Some("//apps/api".to_string())
        );
        assert_eq!(monorepo_scope(root, Path::new("other")), None);

View on GitHub (pinned to 9dcfcaa0dc)

Solutions

  1. cd to an existing directory (`cd ~/repo`) to refresh the process cwd, then retry.
  2. Reopen the terminal / restart the container if the shell's cwd is gone.
  3. Use absolute task syntax `mise //pkg:build`, which skips cwd-based expansion entirely.
  4. Avoid deleting the directory your shell is currently in.

Example fix

# before (cwd was deleted)
$ mise :build
error: Cannot use :task syntax without a current working directory

# after
$ cd ~/repo && mise :build
Defensive patterns

Strategy: fallback

Validate before calling

# verify cwd exists before colon-pattern tasks
[ -d "$(pwd -P 2>/dev/null)" ] || { echo 'cwd invalid; cd somewhere' >&2; exit 1; }
mise :build

Prevention

When it happens

Trigger: mise runs in a process whose cwd has been deleted or is inaccessible (cwd unlinked while the shell/process still runs), or a host environment that fails to report a working directory. Only fires for ':'-prefixed task arguments.

Common situations: Deleting the directory a long-running shell sits in and then running mise; container/sandbox runtimes with broken cwd; exotic init systems spawning mise without a valid cwd.

Related errors


AI-assisted analysis of jdx/mise@9dcfcaa0dc (2026-08-17). Data as JSON: /api/errors/41e0edc8618ed706. Report an issue: GitHub.