Skip to content

Tools

Tools allow the LLM to perform actions in your codebase. OpenCode comes with built-in tools and supports extension via custom tools and MCP servers.

By default, all tools are enabled and don't require permission to run. You can control behavior through permissions.

Built-in Tools

bash

Execute shell commands in your project environment.

bash
# The LLM can run commands like:
npm install
git status
python test.py

edit

Modify existing files using exact string replacements. This is the primary way the LLM modifies code — it finds an exact text match and replaces it.

write

Create new files or overwrite existing ones. Controlled by the edit permission (which covers all file modifications: edit, write, apply_patch, multiedit).

read

Read file contents from your codebase. Supports reading specific line ranges for large files.

grep

Search file contents using regular expressions. Fast content search across your entire codebase with support for file pattern filtering.

glob

Find files by pattern matching (e.g., **/*.js, src/**/*.ts). Returns matching file paths sorted by modification time.

list

List files and directories in a given path. Accepts glob patterns to filter results.

apply_patch

Apply patches to files. Useful for applying diffs and patches. Controlled by the edit permission.

INFO

apply_patch uses output.args.patchText instead of output.args.filePath. Paths are embedded in marker lines within the patch text (e.g., *** Add File: src/new-file.ts).

lsp (experimental)

Interact with configured LSP servers for code intelligence:

  • goToDefinition — Jump to symbol definition
  • findReferences — Find all references to a symbol
  • hover — Get hover information
  • documentSymbol / workspaceSymbol — Browse symbols
  • goToImplementation — Find implementations
  • prepareCallHierarchy / incomingCalls / outgoingCalls — Call hierarchy

WARNING

Only available when OPENCODE_EXPERIMENTAL_LSP_TOOL=true (or OPENCODE_EXPERIMENTAL=true).

skill

Load a skill (SKILL.md file) and return its content in the conversation.

todowrite

Manage todo lists during coding sessions. Creates and updates task lists to track progress during complex multi-step operations.

webfetch

Fetch and read web page content. Useful for looking up documentation or online resources.

websearch

Search the web using Exa AI. No API key required.

TIP

Use websearch for discovery (finding information) and webfetch for retrieval (getting content from a known URL).

Only available when using OpenCode provider or when OPENCODE_ENABLE_EXA=1:

bash
OPENCODE_ENABLE_EXA=1 opencode

question

Ask the user questions during execution. This includes options for the user to select from, useful for gathering preferences, clarifying instructions, or getting decisions.

Tool Permissions

Control each tool's behavior via the permission config:

json
{
  "$schema": "https://opencode.ai/config.json",
  "permission": {
    "edit": "allow",
    "bash": "ask",
    "webfetch": "allow",
    "websearch": "allow"
  }
}
ValueBehavior
"allow"Tool runs without asking (default)
"ask"Requires user approval before running
"deny"Tool is disabled

Use wildcards for MCP server tools:

json
{
  "permission": {
    "mymcp_*": "ask"
  }
}

Custom Tools

Define your own tools that the LLM can call. These execute arbitrary code and are defined in your config file.

See Custom Tools Documentation for details.

MCP Servers

MCP (Model Context Protocol) servers integrate external tools and services — database access, API integrations, third-party services, and more.

Configure them in your opencode.json:

json
{
  "mcp": {
    "my-server": {
      "type": "remote",
      "url": "https://example.com/mcp",
      "enabled": true
    }
  }
}

See MCP Servers Documentation for details.

Internals

Tools like grep, glob, and list use ripgrep internally. By default, ripgrep respects .gitignore patterns.

To include files that are normally ignored, create a .ignore file in your project root:

# .ignore
!node_modules/
!dist/
!build/

Further Reading

Released under the GPLv3 License.