aaif-goose/goose · error

Directory '{}' does not exist

Error message

Directory '{}' does not exist

What it means

When saving a recipe to a user-supplied path, goose resolves relative paths against the current working directory and requires the parent directory to exist before creating the file. A missing parent yields "Directory '{path}' does not exist"; goose does not create intermediate directories itself.

Source

Thrown at crates/goose-cli/src/session/mod.rs:2081

    fn save_recipe(
        &self,
        recipe: &goose::recipe::Recipe,
        filepath_str: &str,
    ) -> anyhow::Result<PathBuf> {
        let path_buf = PathBuf::from(filepath_str);
        let mut path = path_buf.clone();

        // Update the final path if it's relative
        if path_buf.is_relative() {
            // If the path is relative, resolve it relative to the current working directory
            let cwd = std::env::current_dir().context("Failed to get current directory")?;
            path = cwd.join(&path_buf);
        }

        // Check if parent directory exists
        if let Some(parent) = path.parent() {
            if !parent.exists() {
                return Err(anyhow::anyhow!(
                    "Directory '{}' does not exist",
                    parent.display()
                ));
            }
        }

        // Try creating the file
        let file = std::fs::File::create(path.as_path())
            .context(format!("Failed to create file '{}'", path.display()))?;

        // Write YAML
        serde_yaml::to_writer(file, recipe).context("Failed to save recipe")?;

        Ok(path)
    }

    fn push_message(&mut self, message: Message) {
        self.messages.push(message);

View on GitHub (pinned to 3810898a74)

Solutions

  1. Create the directory first: mkdir -p recipes/new
  2. Save into an existing directory
  3. Use an absolute path to make resolution independent of CWD

Example fix

# before
goose recipe save recipes/new/foo.yaml   # recipes/new missing
# after
mkdir -p recipes/new && goose recipe save recipes/new/foo.yaml
Defensive patterns

Strategy: validation

Validate before calling

let parent = path.parent().filter(|p| !p.as_os_str().is_empty());
if let Some(p) = parent {
    std::fs::create_dir_all(p)?; // goose only checks existence; it does not mkdir
}

Prevention

When it happens

Trigger: goose recipe save new/nested/dir/recipe.yaml (or any save-to-file path) where any intermediate directory does not exist, including relative paths resolved against an unexpected CWD.

Common situations: Saving into a not-yet-created folder; path typos; running from a different directory than assumed so the relative parent resolves elsewhere.

Related errors


AI-assisted analysis of aaif-goose/goose@3810898a74 (2026-08-16). Data as JSON: /api/errors/d4d5f531b5eb5728. Report an issue: GitHub.