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:
- Read code
- Modifying files
- Execute the command
- Search code
- Access the network
Without tools: can only generate code
With tools: candirectly operate on the project
II. Tool permission control (most important)
By default:
- All tools are enabled
- and can be executed without confirmation
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:
- Execute shell commands
- such as npm install, git status
**Risk:** high (recommended to set to ask)
2. edit (core tool)
{
"permission": {
"edit": "allow"
}
}
Function:
- Modify existing files
- Based on precise text replacement
**Note:** this is the core capability for AI to modify code
3. write (file creation)
Function:
- Create a new file
- Overwrite existing files
Note:
write is controlled by edit permissions
4. read (read files)
{
"permission": {
"read": "allow"
}
}
Function:
- Read code files
- Supports reading by line
**Risk:** low (recommended always allow)
5. grep (content search)
{
"permission": {
"grep": "allow"
}
}
Function:
- Regex search code
6. glob (file matching)
Function:
- Find file paths (such as src/**/*.ts)
7. list (directory browsing)
Function:
- List directory structure
8. patch (patch application)
Function:
- Apply diff patches
**Note:** controlled by edit permissions
9. lsp (experimental)
Function:
- Code intelligence analysis (go to definition, find references)
How to enable:
OPENCODE_EXPERIMENTAL_LSP_TOOL=true
10. skill (skill loading)
Function:
- Load SKILL.md
- Enhance AI behavior
11. todowrite (task management)
Function:
- Maintain task lists
- Track complex workflows
12. webfetch (web page reading)
Function:
- Fetch content of a specified URL
13. websearch (online search)
How to enable:
OPENCODE_ENABLE_EXA=1 opencode
Function:
- Search the internet for information
Difference:
- websearch: find information (discovery)
- webfetch: read content (retrieval)
14. question (interactive questioning)
Function:
- Ask the user questions
- Gather requirements
Suitable for:
- Requirements are unclear
- Need user decisions
IV. Custom tools
You can define your own tools to let AI execute custom logic.
For example:
- Call internal APIs
- Operate databases
- Execute business logic
**Essence:** let LLM call functions
V. MCP servers (advanced capability)
MCP (Model Context Protocol) allows you to connect to external systems:
- Database
- Third-party APIs
- Internal services
Equivalent to connecting "external capabilities" to AI
VI. Underlying mechanism (important)
OpenCode uses ripgrep as its search engine:
- Respects .gitignore
- Ignores directories like node_modules by default
How to override ignore rules
Create a file:
.ignore
Example:
!node_modules/
!dist/
!build/
Force include these directories
VII. Best practices (strongly recommended)
- read / grep / glob → allow
- edit -> ask (development phase)
- bash -> ask (production environment)
- webfetch → allow
Core principles:
- Reading can be open
- Modifications must be controlled
- Executing commands must be cautious