Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

OpenCode Tools

OpenCode Tools

OpenCode's core capabilities come not only from the large model itself, but also from what it can callTools。

The essence of tools: turning LLM from being able to talk into being able to act.

Tools = OpenCode's execution capability, while permissions = the security boundary.


I. What are tools (Tools)

Tools are capability interfaces for LLM to perform operations in a project, for example:

Without tools: can only generate code

With tools: candirectly operate on the project


II. Tool permission control (most important)

By default:

Permissions must be configured in production environments!

1. Basic permission configuration


{
  "$schema": "https://opencode.ai/config.json",
  "permission": {
    "edit": "deny",
    "bash": "ask",
    "webfetch": "allow"
  }
}
Permission value Description
allow Allow direct execution
deny Completely forbidden
ask Require manual confirmation before execution

2. Wildcard control

Tools can be controlled in batches:


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

All tools from MCP require approval


III. Built-in tools in detail

OpenCode has a built-in set of engineering-grade tools:

1. bash (command execution)


{
  "permission": {
    "bash": "allow"
  }
}

Function:

**Risk:** high (recommended to set to ask)

2. edit (core tool)


{
  "permission": {
    "edit": "allow"
  }
}

Function:

**Note:** this is the core capability for AI to modify code

3. write (file creation)

Function:

Note:

write is controlled by edit permissions

4. read (read files)


{
  "permission": {
    "read": "allow"
  }
}

Function:

**Risk:** low (recommended always allow)

5. grep (content search)


{
  "permission": {
    "grep": "allow"
  }
}

Function:

6. glob (file matching)

Function:

7. list (directory browsing)

Function:

8. patch (patch application)

Function:

**Note:** controlled by edit permissions

9. lsp (experimental)

Function:

How to enable:


OPENCODE_EXPERIMENTAL_LSP_TOOL=true

10. skill (skill loading)

Function:

11. todowrite (task management)

Function:

12. webfetch (web page reading)

Function:

13. websearch (online search)

How to enable:


OPENCODE_ENABLE_EXA=1 opencode

Function:

Difference:

14. question (interactive questioning)

Function:

Suitable for:


IV. Custom tools

You can define your own tools to let AI execute custom logic.

For example:

**Essence:** let LLM call functions


V. MCP servers (advanced capability)

MCP (Model Context Protocol) allows you to connect to external systems:

Equivalent to connecting "external capabilities" to AI


VI. Underlying mechanism (important)

OpenCode uses ripgrep as its search engine:

How to override ignore rules

Create a file:


.ignore

Example:


!node_modules/
!dist/
!build/

Force include these directories


VII. Best practices (strongly recommended)

Core principles: