> ## Documentation Index
> Fetch the complete documentation index at: https://docs.zenrows.com/llms.txt
> Use this file to discover all available pages before exploring further.

# How to Integrate ZenRows with OpenCode

> Add the ZenRows MCP to OpenCode and let your AI coding agent browse the web and fetch web content reliably without anti-bot or JavaScript rendering limitations. Fetch live documentation, pull real API specs, and scrape technical references directly inside your coding session.

## What is OpenCode?

OpenCode is an open-source AI coding agent available as a terminal UI, desktop app, or IDE extension. It connects to your codebase, understands your project structure, and helps you build features, refactor code, fix bugs, and navigate unfamiliar code, all from your editor or terminal.

Like other AI coding tools, OpenCode can call external tools via MCP. Connect ZenRows and it gains reliable access to any web resource: protected documentation sites, JavaScript-rendered API references, paywalled technical content, and any page that would otherwise return a blocked or empty response.

## Why connect ZenRows to OpenCode?

* **Fetch live docs that block automated requests.** Many documentation sites (Cloudflare, AWS, Stripe, and others) return challenges or empty pages to automated clients. ZenRows bypasses that so OpenCode gets the actual content.
* **Pull real API responses, not cached snapshots.** When OpenCode needs to understand an external API, ZenRows fetches the live spec or reference page rather than relying on potentially stale training data.
* **Research technical content during a coding session.** Ask OpenCode to scrape Stack Overflow threads, GitHub issues, technical blogs, or framework changelogs and incorporate the findings directly into the task it's working on.
* **Access JavaScript-rendered pages.** Developer tools, dashboards, and interactive docs often require JavaScript to render their content. ZenRows handles that automatically.

## What you can build

* **Live documentation lookup during development.** Ask OpenCode to fetch the latest docs for a library you're integrating and use them to generate correct, up-to-date code, not code based on training data that may be months old.
* **Automated competitor or dependency research.** Have OpenCode scrape changelogs, release notes, or breaking change announcements across your key dependencies and summarize what needs updating in your project.
* **Technical reference extraction.** Describe a problem and let OpenCode scrape relevant Stack Overflow threads, GitHub issues, or RFC documents to inform its solution.
* **Live API testing context.** Before generating integration code, have OpenCode scrape the target API's reference page to confirm endpoint signatures, auth patterns, and response shapes.

## Prerequisites

* A ZenRows API key from the <a href="https://app.zenrows.com/builder" target="_blank" rel="nofollow noopener noreferrer">ZenRows dashboard</a>.

## Getting started

<Steps>
  <Step title="Install OpenCode" titleSize="h3">
    **Windows / Linux / macOS:**

    ```bash theme={null}
    npm install -g opencode-ai
    ```

    Or via the install script (Windows PowerShell / Linux):

    ```bash theme={null}
    curl -fsSL https://opencode.ai/install | bash
    ```

    Other options: Homebrew (`brew install anomalyco/tap/opencode`), Chocolatey (`choco install opencode`), Scoop (`scoop install opencode`). See the <a href="https://opencode.ai/docs/#install" target="_blank" rel="nofollow noopener noreferrer">full install guide</a> for all options.

    OpenCode runs natively on Windows via PowerShell or Command Prompt. WSL is optional.

    Verify the install:

    ```bash theme={null}
    opencode --version
    ```
  </Step>

  <Step title="Connect an LLM provider" titleSize="h3">
    OpenCode needs an LLM provider to process your prompts and call tools like ZenRows. Run the `/connect` command inside OpenCode and select your provider:

    ```text theme={null}
    /connect
    ```

    For Anthropic, select Anthropic, enter your API key, then run `/models` to pick a model like `claude-sonnet-4-6`. For other providers, see the <a href="https://opencode.ai/docs/providers/" target="_blank" rel="nofollow noopener noreferrer">OpenCode full provider guide</a>.

    Once a model is selected, you're ready to add ZenRows.
  </Step>

  <Step title="Add ZenRows MCP to OpenCode" titleSize="h3">
    ZenRows connects as a remote MCP server. You'll need to create an `opencode.json` config file and add it under the `mcp` key.

    Create the file at one of these locations depending on your preferred scope:

    * **Project-level** (`opencode.json` in your project root): ZenRows available only in this project.
    * **Global** (`~/.config/opencode/opencode.json`): ZenRows available across all projects.

    If neither file exists yet, create it. Then paste the following:

    ```json JSON theme={null}
    {
      "$schema": "https://opencode.ai/config.json",
      "mcp": {
        "zenrows": {
          "type": "remote",
          "url": "https://mcp.zenrows.com/mcp",
          "oauth": false,
          "enabled": true,
          "headers": {
            "Authorization": "Bearer YOUR_ZENROWS_API_KEY"
          }
        }
      }
    }
    ```

    <Note>`oauth: false` is required. Without it, OpenCode's automatic OAuth detection will intercept the request before the Bearer token header is sent.</Note>
  </Step>

  <Step title="Try it out" titleSize="h3">
    Start OpenCode in your project:

    ```bash theme={null}
    opencode
    ```

    Then prompt it to use ZenRows:

    ```text wrap theme={null}
    Fetch https://www.scrapingcourse.com/antibot-challenge and summarize the page.
    ```

    Or for a development-focused example:

    ```text wrap theme={null}
    Use zenrows to scrape https://github.com/vercel/next.js/issues and find open issues related to hydration errors. Summarize the most common causes and suggested fixes.
    ```

    OpenCode will call the right ZenRows tool and incorporate the response directly into its reply.
  </Step>
</Steps>

## Scoping ZenRows to a specific agent (optional)

OpenCode supports custom agents: specialized AI assistants with their own prompts, models, and tool access. You can create one using:

```bash theme={null}
opencode agent create
```

Then follow the interactive prompts to create one.

If you want ZenRows available only to a specific agent and not the default build agent, turn off the ZenRows tools globally using the `permission` key and re-enable them per agent:

```json JSON theme={null}
{
  "$schema": "https://opencode.ai/config.json",
  "mcp": {
    "zenrows": {
      "type": "remote",
      "url": "https://mcp.zenrows.com/mcp",
      "oauth": false,
      "enabled": true,
      "headers": {
        "Authorization": "Bearer YOUR_ZENROWS_API_KEY"
      }
    }
  },
  "permission": {
    "zenrows_*": "deny"
  },
  "agent": {
    "researcher": {
      "description": "Web research agent with ZenRows access",
      "mode": "subagent",
      "permission": {
        "zenrows_*": "allow"
      }
    }
  }
}
```

The `researcher` agent is now the only one that can call ZenRows tools. Invoke it by @ mentioning it in your session:

```text wrap theme={null}
@researcher scrape https://github.com/vercel/next.js/issues and find open issues related to hydration errors.
```

For more on creating and configuring agents, see the <a href="https://opencode.ai/docs/agents/" target="_blank" rel="nofollow noopener noreferrer">OpenCode agents docs</a>.

## Add a ZenRows instruction to your agent file (optional)

When you run `opencode agent create` and follow the interactive prompts, OpenCode generates a markdown agent file at `.opencode/agents/<agent-name>.md`. The file has a frontmatter block for config and a body for the system prompt.

Add the ZenRows instruction to the **Guidelines** section of the body if one exists, or anywhere in the prompt body if not. For example:

```markdown Markdown theme={null}
## Guidelines

- Use `zenrows_scrape` for fast, single-page fetches
- Use `zenrows_browser_*` tools when pages require complex navigation or user interaction
```

This tells the agent to use ZenRows when automatically fetching external content, so you don't need to specify it in every prompt.

## Troubleshooting

### Command 'opencode' not found after install

The `npm` global bin directory isn't in your PATH. Fix it by adding it.

**Linux / macOS:**

```bash theme={null}
export PATH="$(npm config get prefix)/bin:$PATH"
```

Add that line to your `~/.bashrc` or `~/.zshrc` to make it permanent, then run `source ~/.bashrc`.

**Windows CMD:**

```batch theme={null}
for /f "delims=" %i in ('npm config get prefix') do set PATH=%i;%PATH%
```

**Windows PowerShell:**

```powershell theme={null}
$env:PATH = "$(npm config get prefix)" + ";$env:PATH"
```

Alternatively, install via snap:

```bash theme={null}
sudo snap install opencode
```

### ERROR: CreateProcessCommon: execvpe(/bin/bash) failed: No such file or directory on Windows

This means WSL is installed, but no proper Linux distro is set up. The `docker-desktop` distro that ships with Docker Desktop is headless and doesn't provide a usable shell. You have two options:

Install a proper WSL distro:

```powershell theme={null}
wsl --install -d Ubuntu
```

Or skip WSL entirely. OpenCode runs natively on Windows via PowerShell without needing WSL.

### ZenRows tools not appearing in OpenCode

* Confirm `enabled: true` is set in the ZenRows MCP block.
* Check that `ZENROWS_API_KEY` is correct.
* Restart OpenCode after saving the config.
* Run `opencode mcp list` to see all registered MCP servers and their status.

### Authentication error when calling ZenRows tools

Verify your API key is active in the <a href="https://app.zenrows.com" target="_blank" rel="nofollow noopener noreferrer">ZenRows dashboard</a>. Also confirm `oauth: false` is in your config. Without it, OpenCode's OAuth auto-detection will intercept the connection before the Bearer token is applied.

### OpenCode not using ZenRows even when available

Be explicit in your prompt: `use zenrows to fetch https://www.scrapingcourse.com/antibot-challenge`. Alternatively, add an instruction in your `<agent-file.md>` to set ZenRows as the default tool for external web fetches.

### Context limit warnings after adding ZenRows

ZenRows adds its full tool list to the context on every request. If you're hitting context limits, restrict OpenCode to only the tools you need using glob patterns in the `tools` config:

```json JSON theme={null}
"tools": {
  "zenrows_browser_*": false
}
```

This turns off all browser automation tools and keeps only `zenrows_scrape` active. Or switch to a model with a larger context window.

## FAQ (Frequently asked questions)

<Accordion title="Should I add ZenRows to the project config or the global config?">
  Use project config to make ZenRows available only when working in a specific codebase. Use global config if you want it available across all your OpenCode sessions. The project config takes precedence over the global config when both are present.
</Accordion>

<Accordion title="Can I use the local stdio version of ZenRows MCP instead?">
  Yes. Replace the remote config with the local stdio format:

  ```json JSON theme={null}
  {
      "$schema": "https://opencode.ai/config.json",
      "mcp": {
          "zenrows": {
              "type": "local",
              "command": ["npx", "-y", "@zenrows/mcp"],
              "enabled": true,
              "environment": {
                  "ZENROWS_API_KEY": "YOUR_ZENROWS_API_KEY"
              }
          }
      }
  }
  ```

  Both options expose the same tools. The remote approach requires no local installation.
</Accordion>

<Accordion title="Can I connect multiple MCP servers alongside ZenRows?">
  Yes. Add each server as a named block under `mcp`:

  ```json JSON theme={null}
  {
      "$schema": "https://opencode.ai/config.json",
      "mcp": {
          "zenrows": {
              "type": "remote",
              "url": "https://mcp.zenrows.com/mcp",
              "oauth": false,
              "enabled": true,
              "headers": {
                  "Authorization": "Bearer YOUR_ZENROWS_API_KEY"
              }
          },
          "sentry": {
              "type": "remote",
              "url": "https://mcp.sentry.dev/mcp",
              "oauth": {}
          }
      }
  }
  ```
</Accordion>

<Accordion title="Does ZenRows work with all LLM providers in OpenCode?">
  Yes. ZenRows MCP works regardless of which provider you connect via `/connect`. The MCP layer is independent of the model.
</Accordion>

<Accordion title="Can I temporarily turn off ZenRows without removing it from the config?">
  Yes. Set `enabled: false` in the ZenRows block:

  ```json JSON theme={null}
  {
      "mcp": {
          "zenrows": {
              "type": "remote",
              "url": "https://mcp.zenrows.com/mcp",
              "oauth": false,
              "enabled": false,
              "headers": {
                  "Authorization": "Bearer YOUR_ZENROWS_API_KEY"
              }
          }
      }
  }
  ```

  Restart OpenCode, and the server won't load. Flip it back to `true` when you need it again.
</Accordion>

<Accordion title="Does ZenRows work in OpenCode's Plan mode?">
  Plan mode restricts file edits and bash commands but doesn't restrict MCP tool calls by default. ZenRows scraping tools remain available in Plan mode unless you explicitly deny them via the `permission` config.
</Accordion>

<Accordion title="Can I use ZenRows with OpenCode's built-in webfetch tool simultaneously?">
  Yes, they coexist. `webfetch` is OpenCode's native HTTP fetch tool, useful for simple, unprotected pages. ZenRows is better for pages behind bot protection, JavaScript rendering, or geo-restrictions. OpenCode will reach for whichever tool you specify, or make its own judgment if you don't specify one.
</Accordion>
