| --- |
| title: Tools |
| description: Manage the tools an LLM can use. |
| --- |
| |
| Tools allow the LLM to perform actions in your codebase. OpenCode comes with a set of built-in tools, but you can extend it with [custom tools](/docs/custom-tools) or [MCP servers](/docs/mcp-servers). |
|
|
| By default, all tools are **enabled** and don't need permission to run. You can control tool behavior through [permissions](/docs/permissions). |
|
|
| --- |
| |
| |
|
|
| Use the `permission` field to control tool behavior. You can allow, deny, or require approval for each tool. |
|
|
| ```json title="opencode.json" |
| { |
| "$schema": "https://opencode.ai/config.json", |
| "permission": { |
| "edit": "deny", |
| "bash": "ask", |
| "webfetch": "allow" |
| } |
| } |
| ``` |
|
|
| You can also use wildcards to control multiple tools at once. For example, to require approval for all tools from an MCP server: |
|
|
| ```json title="opencode.json" |
| { |
| "$schema": "https://opencode.ai/config.json", |
| "permission": { |
| "mymcp_*": "ask" |
| } |
| } |
| ``` |
|
|
| [Learn more](/docs/permissions) about configuring permissions. |
|
|
| --- |
| |
| |
|
|
| Here are all the built-in tools available in OpenCode. |
|
|
| --- |
| |
| |
|
|
| Execute shell commands in your project environment. |
|
|
| ```json title="opencode.json" {4} |
| { |
| "$schema": "https://opencode.ai/config.json", |
| "permission": { |
| "bash": "allow" |
| } |
| } |
| ``` |
|
|
| This tool allows the LLM to run terminal commands like `npm install`, `git status`, or any other shell command. |
|
|
| --- |
| |
| |
|
|
| Modify existing files using exact string replacements. |
|
|
| ```json title="opencode.json" {4} |
| { |
| "$schema": "https://opencode.ai/config.json", |
| "permission": { |
| "edit": "allow" |
| } |
| } |
| ``` |
|
|
| This tool performs precise edits to files by replacing exact text matches. It's the primary way the LLM modifies code. |
|
|
| --- |
| |
| |
|
|
| Create new files or overwrite existing ones. |
|
|
| ```json title="opencode.json" {4} |
| { |
| "$schema": "https://opencode.ai/config.json", |
| "permission": { |
| "edit": "allow" |
| } |
| } |
| ``` |
|
|
| Use this to allow the LLM to create new files. It will overwrite existing files if they already exist. |
|
|
| :::note |
| The `write` tool is controlled by the `edit` permission, which covers all file modifications (`edit`, `write`, `apply_patch`). |
| ::: |
|
|
| --- |
| |
| |
|
|
| Read file contents from your codebase. |
|
|
| ```json title="opencode.json" {4} |
| { |
| "$schema": "https://opencode.ai/config.json", |
| "permission": { |
| "read": "allow" |
| } |
| } |
| ``` |
|
|
| This tool reads files and returns their contents. It supports reading specific line ranges for large files. |
|
|
| --- |
| |
| |
|
|
| Search file contents using regular expressions. |
|
|
| ```json title="opencode.json" {4} |
| { |
| "$schema": "https://opencode.ai/config.json", |
| "permission": { |
| "grep": "allow" |
| } |
| } |
| ``` |
|
|
| Fast content search across your codebase. Supports full regex syntax and file pattern filtering. |
|
|
| --- |
| |
| |
|
|
| Find files by pattern matching. |
|
|
| ```json title="opencode.json" {4} |
| { |
| "$schema": "https://opencode.ai/config.json", |
| "permission": { |
| "glob": "allow" |
| } |
| } |
| ``` |
|
|
| Search for files using glob patterns like `**/*.js` or `src/**/*.ts`. Returns matching file paths sorted by modification time. |
|
|
| --- |
| |
| |
|
|
| Interact with your configured LSP servers to get code intelligence features like definitions, references, hover info, and call hierarchy. |
|
|
| :::note |
| This tool is only available when `OPENCODE_EXPERIMENTAL_LSP_TOOL=true` (or `OPENCODE_EXPERIMENTAL=true`). |
| ::: |
|
|
| ```json title="opencode.json" {4} |
| { |
| "$schema": "https://opencode.ai/config.json", |
| "permission": { |
| "lsp": "allow" |
| } |
| } |
| ``` |
|
|
| Supported operations include `goToDefinition`, `findReferences`, `hover`, `documentSymbol`, `workspaceSymbol`, `goToImplementation`, `prepareCallHierarchy`, `incomingCalls`, and `outgoingCalls`. |
|
|
| To configure which LSP servers are available for your project, see [LSP Servers](/docs/lsp). |
|
|
| --- |
| |
| |
|
|
| Apply patches to files. |
|
|
| ```json title="opencode.json" {4} |
| { |
| "$schema": "https://opencode.ai/config.json", |
| "permission": { |
| "edit": "allow" |
| } |
| } |
| ``` |
|
|
| This tool applies patch files to your codebase. Useful for applying diffs and patches from various sources. |
|
|
| When handling `tool.execute.before` or `tool.execute.after` hooks, check `input.tool === "apply_patch"` (not `"patch"`). |
|
|
| `apply_patch` uses `output.args.patchText` instead of `output.args.filePath`. Paths are embedded in marker lines within `patchText` and are relative to the project root (for example: `*** Add File: src/new-file.ts`, `*** Update File: src/existing.ts`, `*** Move to: src/renamed.ts`, `*** Delete File: src/obsolete.ts`). |
|
|
| :::note |
| The `apply_patch` tool is controlled by the `edit` permission, which covers all file modifications (`edit`, `write`, `apply_patch`). |
| ::: |
|
|
| --- |
| |
| |
|
|
| Load a [skill](/docs/skills) (a `SKILL.md` file) and return its content in the conversation. |
|
|
| ```json title="opencode.json" {4} |
| { |
| "$schema": "https://opencode.ai/config.json", |
| "permission": { |
| "skill": "allow" |
| } |
| } |
| ``` |
|
|
| --- |
| |
| |
|
|
| Manage todo lists during coding sessions. |
|
|
| ```json title="opencode.json" {4} |
| { |
| "$schema": "https://opencode.ai/config.json", |
| "permission": { |
| "todowrite": "allow" |
| } |
| } |
| ``` |
|
|
| Creates and updates task lists to track progress during complex operations. The LLM uses this to organize multi-step tasks. |
|
|
| :::note |
| This tool is disabled for subagents by default, but you can enable it manually. [Learn more](/docs/agents/#permissions) |
| ::: |
|
|
| --- |
| |
| |
|
|
| Fetch web content. |
|
|
| ```json title="opencode.json" {4} |
| { |
| "$schema": "https://opencode.ai/config.json", |
| "permission": { |
| "webfetch": "allow" |
| } |
| } |
| ``` |
|
|
| Allows the LLM to fetch and read web pages. Useful for looking up documentation or researching online resources. |
|
|
| --- |
| |
| |
|
|
| Search the web for information. |
|
|
| :::note |
| This tool is only available when using the OpenCode or OpenCode Go provider, or when either the `OPENCODE_ENABLE_EXA` or `OPENCODE_ENABLE_PARALLEL` environment variable is set to any truthy value (e.g., `true` or `1`). |
|
|
| To enable when launching OpenCode: |
|
|
| ```bash |
| OPENCODE_ENABLE_EXA=1 opencode |
| |
| OPENCODE_ENABLE_PARALLEL=1 opencode |
| ``` |
|
|
| ::: |
|
|
| ```json title="opencode.json" {4} |
| { |
| "$schema": "https://opencode.ai/config.json", |
| "permission": { |
| "websearch": "allow" |
| } |
| } |
| ``` |
|
|
| Performs web searches using Exa or Parallel to find relevant information online. Useful for researching topics, finding current events, or gathering information beyond the training data cutoff. |
|
|
| No API key is required — the tool connects directly to the backend's hosted MCP service without authentication. |
|
|
| :::tip |
| Use `websearch` when you need to find information (discovery), and `webfetch` when you need to retrieve content from a specific URL (retrieval). |
| ::: |
|
|
| --- |
| |
| |
|
|
| Ask the user questions during execution. |
|
|
| ```json title="opencode.json" {4} |
| { |
| "$schema": "https://opencode.ai/config.json", |
| "permission": { |
| "question": "allow" |
| } |
| } |
| ``` |
|
|
| This tool allows the LLM to ask the user questions during a task. It's useful for: |
|
|
| - Gathering user preferences or requirements |
| - Clarifying ambiguous instructions |
| - Getting decisions on implementation choices |
| - Offering choices about what direction to take |
|
|
| Each question includes a header, the question text, and a list of options. Users can select from the provided options or type a custom answer. When there are multiple questions, users can navigate between them before submitting all answers. |
|
|
| --- |
| |
| |
|
|
| Custom tools let you define your own functions that the LLM can call. These are defined in your config file and can execute arbitrary code. |
|
|
| [Learn more](/docs/custom-tools) about creating custom tools. |
|
|
| --- |
| |
| |
|
|
| MCP (Model Context Protocol) servers allow you to integrate external tools and services. This includes database access, API integrations, and third-party services. |
|
|
| [Learn more](/docs/mcp-servers) about configuring MCP servers. |
|
|
| --- |
| |
| |
|
|
| Internally, tools like `grep` and `glob` use [ripgrep](https://github.com/BurntSushi/ripgrep) under the hood. By default, ripgrep respects `.gitignore` patterns, which means files and directories listed in your `.gitignore` will be excluded from searches and listings. |
|
|
| --- |
| |
| |
|
|
| To include files that would normally be ignored, create a `.ignore` file in your project root. This file can explicitly allow certain paths. |
|
|
| ```text title=".ignore" |
| !node_modules/ |
| !dist/ |
| !build/ |
| ``` |
|
|
| For example, this `.ignore` file allows ripgrep to search within `node_modules/`, `dist/`, and `build/` directories even if they're listed in `.gitignore`. |
|
|