{"record":{"id":"ec6d84f26163933c","repo":"BoundaryML/baml","slug":"no-optimization-runs-found-run-baml-cli-optimize-first","errorCode":null,"errorMessage":"No optimization runs found. Run 'baml-cli optimize' first.\nExpected directory: {}","messagePattern":"No optimization runs found\\. Run 'baml-cli optimize' first\\.\nExpected directory: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/baml-runtime/src/cli/optimize.rs","lineNumber":721,"sourceCode":"\n    /// Run the TUI viewer mode\n    fn run_view_mode(&self) -> Result<OptimizeRunResult> {\n        let run_dir = if let Some(ref dir) = self.run_dir {\n            // Use explicitly specified run directory\n            if !dir.exists() {\n                anyhow::bail!(\"Specified run directory does not exist: {}\", dir.display());\n            }\n            dir.clone()\n        } else {\n            // Find the most recent run in .baml_optimize/\n            let from = BamlRuntime::parse_baml_src_path(&self.from)?;\n            let optimize_base_dir = from\n                .parent()\n                .map(|p| p.join(\".baml_optimize\"))\n                .unwrap_or_else(|| PathBuf::from(\".baml_optimize\"));\n\n            if !optimize_base_dir.exists() {\n                anyhow::bail!(\n                    \"No optimization runs found. Run 'baml-cli optimize' first.\\n\\\n                     Expected directory: {}\",\n                    optimize_base_dir.display()\n                );\n            }\n\n            // Find the most recent run_* directory\n            let mut runs: Vec<_> = std::fs::read_dir(&optimize_base_dir)?\n                .filter_map(|entry| {\n                    let entry = entry.ok()?;\n                    let path = entry.path();\n                    if path.is_dir() {\n                        let name = path.file_name()?.to_string_lossy().to_string();\n                        if name.starts_with(\"run_\") {\n                            return Some(path);\n                        }\n                    }\n                    None","sourceCodeStart":703,"sourceCodeEnd":739,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/baml-runtime/src/cli/optimize.rs#L703-L739","documentation":"In run_view_mode, when no --run-dir is given, the command derives the optimize base directory (.baml_optimize next to the parsed baml_src path or ./.baml_optimize) and expects it to exist. If the base directory is missing, no optimization was ever run (or it ran elsewhere), so the viewer bails with this message including the expected path.","triggerScenarios":"Running `baml-cli optimize --view` without --run-dir when the computed .baml_optimize directory does not exist.","commonSituations":"Running --view before ever running an optimization, running the viewer from a different project/checkout, or .baml_optimize removed by clean tooling.","solutions":["Run `baml-cli optimize` once to create .baml_optimize with run data.","Verify the expected directory printed in the error; if optimizing a different project, pass matching --from.","Check you're in the correct project root (relative .baml_optimize resolution).","Pass --run-dir explicitly if your runs live in a custom location."],"exampleFix":"// before\nbaml-cli optimize --view  // no runs yet\n// after\nbaml-cli optimize --from baml_src   # creates runs\nbaml-cli optimize --view --from baml_src","handlingStrategy":"validation","validationCode":"# guard before viewing without --run-dir\n[ -d .baml_optimize ] || { echo 'run baml-cli optimize first'; exit 1; }","typeGuard":null,"tryCatchPattern":"catch (e) {\n  if (String(e.message).includes('No optimization runs found')) {\n    // trigger a fresh optimize run, then re-run view\n  }\n}","preventionTips":["Always run optimize before --view.","Keep .baml_optimize out of clean scripts or restore it via CI cache.","Run view from the same project root used for optimize."],"tags":["cli","optimize","filesystem"],"backgroundTag":"resource-not-found","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"}