BoundaryML/baml · error

BAML project already exists

Error message

BAML project already exists

What it means

`baml-cli init` refuses to overwrite an existing project. In InitCommand::run, if <dest>/baml_src already exists, it prints an error and bails with "BAML project already exists". BAML init is intentionally non-destructive to avoid clobbering user files.

Source

Thrown at engine/baml-runtime/src/cli/init.rs:438

        // Detect project type if not explicitly provided
        let output_type = if let Some(client_type) = self.client_type {
            client_type
        } else if let Some(detected_type) = detect_project_type(&self.dest) {
            // baml_log::info!("Detected project type: {:?}", detected_type);
            detected_type
        } else {
            defaults.output_type
        };

        // If the destination directory already contains a baml_src directory, we don't want to overwrite it.
        let baml_src = self.dest.join("baml_src");
        if baml_src.exists() {
            show_error(&format!(
                "Looks like you already have a BAML project at {}",
                self.dest.display()
            ))?;
            anyhow::bail!("BAML project already exists");
        }

        // Detect editor early to customize messages
        let editor = detect_editor();

        // Add initialization steps
        ui_context.add_step("Checking project structure");
        ui_context.add_step("Creating BAML project files");
        ui_context.add_step("Generating configuration");
        ui_context.add_step("Detecting editor environment");

        // Add editor-specific steps
        match editor {
            EditorType::VSCode => {
                ui_context.add_step("Getting BAML VSCode extension");
                ui_context.add_step("Finishing VSCode setup");
            }
            EditorType::Cursor => {

View on GitHub (pinned to bd85ce9dee)

Solutions

  1. Run init from (or with a target of) a directory that has no baml_src folder.
  2. If you intended to reinitialize, move or delete the existing baml_src directory first.
  3. Use `baml dev` or other commands instead of init inside an already-initialized project.
  4. If the baml_src folder is a leftover empty stub, remove it and re-run init.

Example fix

// before
baml init ./myapp   // baml_src already exists
// after
mkdir newproj && cd newproj && baml init
// or remove the stale dir:
rm -rf myapp/baml_src && baml init ./myapp
Defensive patterns

Strategy: validation

Validate before calling

# shell guard before baml init
[ -d baml_src ] && echo 'already a BAML project' || baml init

Try / catch

catch (e) {
  if (String(e.message).includes('BAML project already exists')) {
    // no-op: project already initialized; proceed with baml dev
  }
}

Prevention

When it happens

Trigger: Running `baml init` (or `baml init <dir>`) in a directory that already contains a baml_src folder.

Common situations: Re-running init in an existing project, running init in the wrong directory, running init at a parent directory when the project lives in a subfolder.

Understand the failure class

Background: "already exists" / EEXIST / FileAlreadyExistsException: what the 'file already exists' error means and how to fix it — this error's family across 37 libraries.

Related errors


AI-assisted analysis of BoundaryML/baml@bd85ce9dee (2026-09-12). Data as JSON: /api/errors/c124ce63a5ffb15c. Report an issue: GitHub.