{"record":{"id":"c124ce63a5ffb15c","repo":"BoundaryML/baml","slug":"baml-project-already-exists","errorCode":null,"errorMessage":"BAML project already exists","messagePattern":"BAML project already exists","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/baml-runtime/src/cli/init.rs","lineNumber":438,"sourceCode":"\n        // Detect project type if not explicitly provided\n        let output_type = if let Some(client_type) = self.client_type {\n            client_type\n        } else if let Some(detected_type) = detect_project_type(&self.dest) {\n            // baml_log::info!(\"Detected project type: {:?}\", detected_type);\n            detected_type\n        } else {\n            defaults.output_type\n        };\n\n        // If the destination directory already contains a baml_src directory, we don't want to overwrite it.\n        let baml_src = self.dest.join(\"baml_src\");\n        if baml_src.exists() {\n            show_error(&format!(\n                \"Looks like you already have a BAML project at {}\",\n                self.dest.display()\n            ))?;\n            anyhow::bail!(\"BAML project already exists\");\n        }\n\n        // Detect editor early to customize messages\n        let editor = detect_editor();\n\n        // Add initialization steps\n        ui_context.add_step(\"Checking project structure\");\n        ui_context.add_step(\"Creating BAML project files\");\n        ui_context.add_step(\"Generating configuration\");\n        ui_context.add_step(\"Detecting editor environment\");\n\n        // Add editor-specific steps\n        match editor {\n            EditorType::VSCode => {\n                ui_context.add_step(\"Getting BAML VSCode extension\");\n                ui_context.add_step(\"Finishing VSCode setup\");\n            }\n            EditorType::Cursor => {","sourceCodeStart":420,"sourceCodeEnd":456,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/baml-runtime/src/cli/init.rs#L420-L456","documentation":"`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.","triggerScenarios":"Running `baml init` (or `baml init <dir>`) in a directory that already contains a baml_src folder.","commonSituations":"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.","solutions":["Run init from (or with a target of) a directory that has no baml_src folder.","If you intended to reinitialize, move or delete the existing baml_src directory first.","Use `baml dev` or other commands instead of init inside an already-initialized project.","If the baml_src folder is a leftover empty stub, remove it and re-run init."],"exampleFix":"// before\nbaml init ./myapp   // baml_src already exists\n// after\nmkdir newproj && cd newproj && baml init\n// or remove the stale dir:\nrm -rf myapp/baml_src && baml init ./myapp","handlingStrategy":"validation","validationCode":"# shell guard before baml init\n[ -d baml_src ] && echo 'already a BAML project' || baml init","typeGuard":null,"tryCatchPattern":"catch (e) {\n  if (String(e.message).includes('BAML project already exists')) {\n    // no-op: project already initialized; proceed with baml dev\n  }\n}","preventionTips":["Only run init in fresh directories.","Script it: `test ! -d baml_src && baml init`.","Don't run init at a parent directory of an existing project."],"tags":["cli","init","filesystem"],"backgroundTag":"file-already-exists","analyzedSha":"bd85ce9dee1463ff04d27efd20531013a4ff46c1","analyzedAt":"2026-09-12T03:38:25.718Z","contentChangedAt":"2026-09-12T03:38:25.718Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}