nikivdev/code · error
Tool '{}' exited with status: {}
Error message
Tool '{}' exited with status: {} What it means
Raised by run_tool (src/tools.rs:144) when the bun subprocess running the tool's .ts file exits with a non-zero status. The tool itself (not the runner) failed — bun launched fine but the tool script returned an error exit code.
Source
Thrown at src/tools.rs:144
let tool_file = tools_dir.join(format!("{}.ts", name));
if !tool_file.exists() {
bail!(
"Tool '{}' not found. Create it with: f tools new {}",
name,
name
);
}
let status = Command::new("bun")
.arg("run")
.arg(&tool_file)
.args(&args)
.status()
.context("failed to run bun")?;
if !status.success() {
bail!("Tool '{}' exited with status: {}", name, status);
}
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 toolView on GitHub (pinned to a747e741ae)
Solutions
- Run the tool script directly to see its real error output: `bun <tools_dir>/<name>.ts <args>`.
- Fix the bug or missing env/config in the tool's TypeScript source.
- Check the bun version (`bun --version`) and upgrade if the tool needs newer APIs.
- If the tool shells out to another program, verify that program's availability and exit code.
Example fix
// before: tool crashes on missing env
const key = process.env.API_KEY; // undefined
fetch(...)
// after
const key = process.env.API_KEY;
if (!key) { console.error("API_KEY required"); process.exit(1); } Defensive patterns
Strategy: try-catch
Validate before calling
// dry-run the tool via bun first to surface its errors
try {
execSync(`bun ${toolsDir}/${name}.ts --help`, { stdio: "inherit" });
} catch (e) {
console.error("tool itself fails under bun; fix the script first");
} Try / catch
try {
runTool(name, args);
} catch (e) {
if (String(e).includes("exited with status")) {
console.error(`tool ${name} failed; run: bun ${toolsDir}/${name}.ts for the real error`);
} else throw e;
} Prevention
- Keep bun up to date and consistent with the tool's requirements.
- Add error handling and clear process.exit codes inside each tool script.
- Verify required env vars/keys inside the tool before doing work.
- Smoke-test tools after editing them.
When it happens
Trigger: Any `f <toolname>` invocation whose tool script exits non-zero: an uncaught TypeScript exception, an explicit process.exit(1), or a failed internal command within the tool. `status` (ExitStatus) is Display-formatted into the message.
Common situations: Tool script has a bug or unhandled rejection; tool's required env vars or API keys are missing; bun runtime version incompatibility with the tool's syntax/APIs; the tool delegates to a failing external command.
Related errors
- bun run {} failed with status {}
- Lin.app is not running
- Agent exited with status: {}
- gen exited with status: {}
- {} exited with {}
AI-assisted analysis of nikivdev/code@a747e741ae (2026-09-01).
Data as JSON: /api/errors/5fa2f16387d1e4b0.
Report an issue: GitHub.