Skip to content

Tools

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 or MCP servers.

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


Configure

Use the permission field to control tool behavior. You can allow, deny, or require approval for each tool.

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:

opencode.json
{
"$schema": "https://opencode.ai/config.json",
"permission": {
"mymcp_*": "ask"
}
}

Learn more about configuring permissions.


Built-in

Here are all the built-in tools available in OpenCode.


bash

Execute shell commands in your project environment.

opencode.json
{
"$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.


edit

Modify existing files using exact string replacements.

opencode.json
{
"$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.


write

Create new files or overwrite existing ones.

opencode.json
{
"$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.


read

Read file contents from your codebase.

opencode.json
{
"$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.


grep

Search file contents using regular expressions.

opencode.json
{
"$schema": "https://opencode.ai/config.json",
"permission": {
"grep": "allow"
}
}

Fast content search across your codebase. Supports full regex syntax and file pattern filtering.


glob

Find files by pattern matching.

opencode.json
{
"$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.


lsp (experimental)

Interact with your configured LSP servers to get code intelligence features like definitions, references, hover info, and call hierarchy.

opencode.json
{
"$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.


apply_patch

Apply patches to files.

opencode.json
{
"$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).


skill

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

opencode.json
{
"$schema":