nikivdev/code · error

localcode not found. Install it with: cd <opencode-repo> &

Error message

localcode not found. Install it with:
  cd <opencode-repo> && flow link

What it means

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.

Source

Thrown at src/tools.rs:165

    Ok(())
}

/// Create a new tool.
fn new_tool(name: &str, description: Option<&str>, use_ai: bool) -> Result<()> {
    let tools_dir = get_tools_dir()?;
    fs::create_dir_all(&tools_dir).context("failed to create tools directory")?;

    let tool_file = tools_dir.join(format!("{}.ts", name));

    if tool_file.exists() {
        bail!("Tool '{}' already exists", name);
    }

    if use_ai {
        // Use localcode to generate the tool
        let localcode = find_localcode();
        if localcode.is_none() {
            bail!(
                "localcode not found. Install it with:\n  \
                 cd <opencode-repo> && flow link"
            );
        }

        let desc = description.unwrap_or(name);
        let prompt = format!(
            "Create a TypeScript tool for Bun called '{}' that: {}\n\n\
             Requirements:\n\
             - Use Bun APIs (Bun.$, Bun.file, etc.)\n\
             - Add a description comment at the top\n\
             - Handle CLI args via Bun.argv\n\
             - Save to: {}",
            name,
            desc,
            tool_file.display()
        );

View on GitHub (pinned to a747e741ae)

Solutions

  1. Install localcode as the message says: `cd <opencode-repo> && flow link`.
  2. Verify it is on PATH afterwards with `which localcode` / `localcode --version`.
  3. If AI generation is not needed, omit the --ai flag to scaffold a template tool without localcode.
  4. If the link is stale after an update, re-run `flow link` to refresh the binary.

Example fix

// before
f tools new report --ai   # fails: localcode not found
// after
cd ~/src/opencode && flow link
export PATH="$HOME/.local/bin:$PATH"
f tools new report --ai
Defensive patterns

Strategy: fallback

Validate before calling

const { execSync } = require("child_process");
let hasLocalcode = true;
try { execSync("which localcode", { stdio: "ignore" }); }
catch { hasLocalcode = false; console.error("install localcode: cd <opencode-repo> && flow link"); }

Try / catch

try {
  newToolAi(name);
} catch (e) {
  if (String(e).includes("localcode not found")) {
    console.error("falling back to template scaffold without AI");
    newTool(name); // non-AI path
  } else throw e;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: "environment variable is not set" and "Missing keys in environment" errors: what missing required env var messages mean and how to fix them — this error's family across 28 libraries.

Related errors


AI-assisted analysis of nikivdev/code@a747e741ae (2026-09-01). Data as JSON: /api/errors/d5fe99b02b07dcf5. Report an issue: GitHub.