{"record":{"id":"d5fe99b02b07dcf5","repo":"nikivdev/code","slug":"localcode-not-found-install-it-with-cd-openco","errorCode":null,"errorMessage":"localcode not found. Install it with:\n  cd <opencode-repo> && flow link","messagePattern":"localcode not found\\. Install it with:\n  cd <opencode-repo> && flow link","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/tools.rs","lineNumber":165,"sourceCode":"    Ok(())\n}\n\n/// Create a new tool.\nfn new_tool(name: &str, description: Option<&str>, use_ai: bool) -> Result<()> {\n    let tools_dir = get_tools_dir()?;\n    fs::create_dir_all(&tools_dir).context(\"failed to create tools directory\")?;\n\n    let tool_file = tools_dir.join(format!(\"{}.ts\", name));\n\n    if tool_file.exists() {\n        bail!(\"Tool '{}' already exists\", name);\n    }\n\n    if use_ai {\n        // Use localcode to generate the tool\n        let localcode = find_localcode();\n        if localcode.is_none() {\n            bail!(\n                \"localcode not found. Install it with:\\n  \\\n                 cd <opencode-repo> && flow link\"\n            );\n        }\n\n        let desc = description.unwrap_or(name);\n        let prompt = format!(\n            \"Create a TypeScript tool for Bun called '{}' that: {}\\n\\n\\\n             Requirements:\\n\\\n             - Use Bun APIs (Bun.$, Bun.file, etc.)\\n\\\n             - Add a description comment at the top\\n\\\n             - Handle CLI args via Bun.argv\\n\\\n             - Save to: {}\",\n            name,\n            desc,\n            tool_file.display()\n        );\n","sourceCodeStart":147,"sourceCodeEnd":183,"githubUrl":"https://github.com/nikivdev/code/blob/a747e741ae92c09071d0ae946ab48488adcff1ce/src/tools.rs#L147-L183","documentation":"Raised by new_tool (src/tools.rs:165) when AI-assisted tool scaffolding is requested (use_ai) but the `find_localcode()` helper cannot locate the localcode binary. Generating a tool with AI requires the localcode CLI (installed by linking the opencode repo with `flow link`), so the scaffold aborts with installation instructions.","triggerScenarios":"Running `f tools new <name> --ai` (or equivalent flag) on a machine where localcode was never installed, was installed outside PATH, or the opencode repo link was removed/broken.","commonSituations":"Fresh machine or CI container without the opencode dev setup; localcode built but not linked into PATH; PATH changes in a new shell; upgrading opencode invalidated the previous link.","solutions":["Install localcode as the message says: `cd <opencode-repo> && flow link`.","Verify it is on PATH afterwards with `which localcode` / `localcode --version`.","If AI generation is not needed, omit the --ai flag to scaffold a template tool without localcode.","If the link is stale after an update, re-run `flow link` to refresh the binary."],"exampleFix":"// before\nf tools new report --ai   # fails: localcode not found\n// after\ncd ~/src/opencode && flow link\nexport PATH=\"$HOME/.local/bin:$PATH\"\nf tools new report --ai","handlingStrategy":"fallback","validationCode":"const { execSync } = require(\"child_process\");\nlet hasLocalcode = true;\ntry { execSync(\"which localcode\", { stdio: \"ignore\" }); }\ncatch { hasLocalcode = false; console.error(\"install localcode: cd <opencode-repo> && flow link\"); }","typeGuard":null,"tryCatchPattern":"try {\n  newToolAi(name);\n} catch (e) {\n  if (String(e).includes(\"localcode not found\")) {\n    console.error(\"falling back to template scaffold without AI\");\n    newTool(name); // non-AI path\n  } else throw e;\n}","preventionTips":["Run `flow link` after cloning/updating the opencode repo and verify with `which localcode`.","Ensure the linked binary's directory is on PATH in every shell (login scripts).","Only pass the --ai flag on machines known to have the dev toolchain; otherwise use the template scaffold."],"tags":["missing-binary","tooling","dependency"],"backgroundTag":"missing-env-var","analyzedSha":"a747e741ae92c09071d0ae946ab48488adcff1ce","analyzedAt":"2026-09-01T22:43:55.719Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}