You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Write tools as TypeScript .ts files in the <workspace>/.roo/tools folder of the current project or globally in the <home>/.roo/tools/ folder. Multiple exported tools can live in one file, although one tool per file is often easier to maintain. The user must manually refresh the tools when changes are made.
4228
+
4229
+
# Custom Tools
4230
+
4231
+
Define TypeScript or JavaScript tools that Zoo can call like built-in tools—standardize team workflows instead of re-prompting the same steps every task.
4232
+
4233
+
:::warning Experimental Feature
4234
+
Custom tools is an experimental feature. Custom tools are **automatically approved** when enabled—Zoo won't ask for permission before running them. Only enable this feature if you trust your tool code.
4235
+
:::
4236
+
4237
+
---
4238
+
4239
+
## What it does
4240
+
4241
+
Custom tools let you codify project-specific actions into TypeScript/JavaScript files that Zoo calls like [`read_file()`](/basic-usage/how-tools-work) or [`execute_command()`](/basic-usage/how-tools-work). Ship tool schemas alongside your repo so teammates don't need to keep re-explaining the same workflow steps. Tools are validated with Zod and automatically transpiled from TypeScript.
4242
+
4243
+
---
4244
+
4245
+
## How to create a tool
4246
+
4247
+
Tools live in `.roo/tools/` (project-specific) or `~/.roo/tools/` (global) as `.ts` or `.js` files. Tools from later directories can override earlier ones.
4248
+
4249
+
#### Basic structure
4250
+
4251
+
```typescript
4252
+
import { parametersSchema as z, defineCustomTool } from "@roo-code/types"
- **`name`**: Tool name Zoo sees in its available tools list
4272
+
- **`description`**: Shown to the AI so it knows when to call the tool
4273
+
- **`parameters`**: Zod schema converted to JSON Schema for validation
4274
+
- **`execute`**: Async function returning a string result to Zoo
4275
+
4276
+
Tools are dynamically loaded and transpiled with esbuild. Automatic reload on file changes isn't reliable—use the **Refresh Custom Tools** command to pick up changes immediately.
4277
+
4278
+
---
4279
+
4280
+
## Enabling the feature
4281
+
4282
+
1. Open Zoo Code settings (gear icon in top right)
**Critical:** When enabled, custom tools are **auto-approved**—Zoo runs them without asking. Disable if you don't trust the tool code.
4289
+
4290
+
---
4291
+
4292
+
## Tool directories
4293
+
4294
+
- **`.roo/tools/`** in your workspace: project-specific tools shared with your team
4295
+
- **`~/.roo/tools/`** in your home folder: personal tools across all projects
4296
+
4297
+
Tools from both directories are loaded. Tools with the same name in `.roo/tools/` override those in `~/.roo/tools/`.
4298
+
4299
+
---
4300
+
4301
+
## Using npm Dependencies
4302
+
4303
+
Custom tools can use npm packages. Install dependencies in the same folder as your tool, and imports will resolve normally.
4304
+
4305
+
```bash
4306
+
# From your tool directory
4307
+
cd .roo/tools/
4308
+
npm init -y
4309
+
npm install axios lodash
4310
+
```
4311
+
4312
+
Then import in your tool:
4313
+
4314
+
```typescript
4315
+
import { parametersSchema as z, defineCustomTool } from "@roo-code/types"
4316
+
import axios from "axios"
4317
+
4318
+
export default defineCustomTool({
4319
+
name: "fetch_api",
4320
+
description: "Fetch data from an API endpoint",
4321
+
parameters: z.object({
4322
+
url: z.string().describe("API endpoint URL"),
4323
+
}),
4324
+
async execute({ url }) {
4325
+
const response = await axios.get(url)
4326
+
return JSON.stringify(response.data, null, 2)
4327
+
}
4328
+
})
4329
+
```
4330
+
4331
+
---
4332
+
4333
+
## Per-Tool Environment Variables
4334
+
4335
+
Zoo copies `.env` and `.env.*` files from your tool directory into the tool's cache folder so your tool can load them at runtime. **Zoo does not automatically inject these variables into `process.env`**—your tool must load them itself.
**Why `__dirname`?** Zoo copies your `.env` files into a cache directory alongside the transpiled tool. Using `__dirname` ensures your tool finds the `.env` in the correct location regardless of where the tool was originally defined.
4387
+
4388
+
**Security:** Ensure your `.env` file is ignored by version control to keep secrets safe.
4389
+
4390
+
---
4391
+
4392
+
## Limits
4393
+
4394
+
- **No approval prompts**: Tools are auto-approved when the feature is enabled—security trade-off for convenience
4395
+
- **String-only results**: Tools must return strings (Zoo's protocol constraint)
4396
+
- **No interactive input**: Tools can't prompt the user mid-execution
4397
+
- **Cache invalidation**: Tool updates may require reloading the window
4398
+
4399
+
**vs. MCP:** [MCP](/features/mcp/overview) is for external services (search, APIs). Custom tools are for in-repo logic you control directly. MCP is more extensible; custom tools are lighter weight for project-specific actions.
4400
+
4401
+
# MORE EXAMPLES
4402
+
4403
+
```typescript
4404
+
import { parametersSchema as z, defineCustomTool, CustomToolContext } from "@roo-code/types"
0 commit comments