Skip to content

How to Enable Web Search and Code Search in OpenCode CLI

I switched from Claude Code to OpenCode CLI recently, and immediately noticed something was missing - the research capabilities. Every time I tried to search the web or search my codebase, nothing happened.

At first I thought it was a bug. Then I realized: OpenCode intentionally disables these features by default. Here’s what I learned about enabling them.

The Problem: Missing Research Tools

When I first started using OpenCode, I tried asking it to search for documentation on a library I was using. The response was underwhelming - it couldn’t access the web at all.

Then I tried searching my own codebase for a specific function pattern. Again, nothing. This was frustrating because Claude Code had these capabilities built-in and enabled by default.

Turns out, OpenCode takes a privacy-first approach. Web search sends queries to external services, and code search could potentially expose your codebase information. So both are disabled out of the box.

Finding the Configuration

I looked through the documentation and found that OpenCode uses a configuration file called opencode.json. The file can exist in two places:

  1. Global configuration: ~/.config/opencode/opencode.json
  2. Project-level configuration: opencode.json in your project root

Project-level settings override global ones, which is useful for controlling which projects can access these tools.

Enabling the Tools

The fix is straightforward. Add a tools section to your configuration:

opencode.json
{
"$schema": "https://opencode.ai/config.json",
"tools": {
"websearch": true,
"codesearch": true
}
}

I added this to my global configuration first, and the code search started working immediately.

Web Search Needs One More Thing

However, web search still didn’t work even with websearch: true. After checking the docs more carefully, I found the missing piece: you need to either use the OpenCode provider or set an environment variable.

I chose the environment variable approach:

~/.zshrc
export OPENCODE_ENABLE_EXA=1

After restarting my terminal, web search worked perfectly.

Understanding the Tools Configuration

One thing that confused me initially was the difference between tools and permission settings. They serve different purposes:

opencode.json
{
"tools": {
"websearch": true
},
"permission": {
"websearch": "allow"
}
}

The tools section enables or disables tools entirely. The permission section controls whether tools need user approval before running. These are independent - you can enable a tool but still require approval for each use.

A Complete Working Configuration

Here’s the configuration I ended up with:

~/.config/opencode/opencode.json
{
"$schema": "https://opencode.ai/config.json",
"model": "anthropic/claude-sonnet-4-5",
"tools": {
"websearch": true,
"codesearch": true
},
"permission": {
"websearch": "allow",
"grep": "allow",
"glob": "allow"
}
}

This gives me the research capabilities I was missing while maintaining sensible permissions.

Project-Level Security

For sensitive projects, I use a project-level opencode.json that disables web search:

project-root/opencode.json
{
"tools": {
"websearch": false,
"codesearch": true
}
}

This way, my global config enables everything, but specific projects can lock down what’s allowed.

OpenCode has several search-related tools worth knowing about:

ToolPurposeDefault
websearchSearch the web using Exa AIDisabled
webfetchFetch content from specific URLsEnabled
grepSearch file contents with regexEnabled
globFind files by patternEnabled

I use websearch when I need to discover information, and webfetch when I already have a URL and just need the content. The grep and glob tools are always available and work great for local code navigation.

Why This Matters

Having these tools enabled changed how I use OpenCode. Before, I had to manually look up documentation and copy-paste context. Now, OpenCode can research on its own, finding current information beyond its training data cutoff.

The privacy-first default makes sense for enterprise environments, but for individual developers who want the full experience, enabling these tools is essential.

Final Words + More Resources

My intention with this article was to help others share my knowledge and experience. If you want to contact me, you can contact by email: Email me

Here are also the most important links from this article along with some further resources that will help you in this scope:

Oh, and if you found these resources useful, don’t forget to support me by starring the repo on GitHub!

Comments