OpenCode: OpenCode Built-in Tools

Last updated: 2026-08-31

--- title: OpenCode Built-in Tools description: Understand the built-in tool system including file operations, Shell execution, and search order: 11 lang: en

OpenCode's power comes from its built-in tool system—AI calls tools to execute specific operations.

1. What You Will Learn


2. Built-in Tool Overview

Tool Function Permission Level
read Read file content Read-only
write Write/create files Write
edit Edit/patch files Write
bash Execute Shell commands Execute
grep Search file content Read-only
glob Find files by pattern Read-only
list List directory contents Read-only
webfetch Fetch web content Network
task Call sub-agents Agent

3. File Operation Tools


4. Shell Execution Tool

Execute any Shell command:

TEXT 📖 Display only
Run npm test and analyze the failing tests

AI will: execute the command → analyze errors → locate problems → suggest fixes → can modify code directly.


5. Search and Analysis Tools


6. Tool Configuration

Global toggles:

JSON
{
  "tools": {
    "write": true,
    "edit": true,
    "bash": true,
    "webfetch": false
  }
}

Agent-level:

JSON
{
  "agent": {
    "review": {
      "tools": {
        "write": false,
        "edit": false
      }
    }
  }
}

Permission values: allow (auto), ask (confirm), deny (reject)


❓ FAQ

Q How to prevent AI from executing dangerous operations?
A Set bash permission to ask or deny. Use Glob patterns for fine control: allow git status, deny rm -rf.
Q AI made wrong modifications?
A Use /undo immediately. Recommend setting edit and write permissions to ask for confirmation before changes.
Q Alice allows all tools, Bob only allows read-only—who's safer?
A Bob. Read-only configuration prevents AI from making any modifications—ideal for code review. Alice's setup is more efficient but riskier.

📖 Summary


📝 Exercises

  1. Basic: Configure tool permissions in opencode.json, set edit to ask.

  2. Intermediate: Create a read-only agent with all write/execute tools disabled.

  3. Advanced: Use Glob patterns to allow git operations but deny rm and other dangerous commands.

Web-Tutorial.com

Web-Tutorial Tech Team

A team of developers maintaining programming tutorials. Each tutorial is written and reviewed by developers with expertise in that field. We work to keep our content accurate and reliable — if you spot an issue, please let us know.

100%

🙏 帮我们做得更好

我们是刚上线的编程教程站,几个人的小团队,精力有限。页面虽经检查,难免还有疏漏——链接失效、排版错乱、内容有误、语言生硬……

如果您发现了,麻烦告诉我们,我们会在收到反馈后第一时间进行修复,再次感谢您的光临 🙏