Skip to content

feat(core): add Claude Agent as a web search provider - #65704

Merged
Tarquinen merged 2 commits into
anomalyco:devfrom
levtechs:feat/claude-agent-websearch
Nov 23, 2026
Merged

Tarquinen merged 2 commits into
anomalyco:devfrom
levtechs:feat/claude-agent-websearch

Conversation

@levtechs

@levtechs levtechs commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Issue for this PR

Related: #64996, #10704, #63487, #63784

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Adds an opt-in websearch provider, claude-agent, served by the Claude Agent plugin while it's connected. It runs Claude Code's WebSearch, which Claude plans include, so any model can use opencode's websearch tool without a search API key or Console credit. It's never the default: you select it with "websearch": { "provider": "claude-agent" }.

#64996 asked for this and was closed because handing Claude its own WebSearch would break session continuity when you switch to a non-Claude model. This PR avoids that problem: Claude Code's built-in tools stay off for chats. The search runs behind opencode's own websearch tool, so results are stored as ordinary tool output that every model can read.

How it works:

  • Each search is a one-off Haiku run with only WebSearch allowed, no transcript and thinking off. It's closed as soon as the results arrive and times out after a minute. A model has to run the search because WebSearch returns page contents encrypted. Haiku is the cheapest.
  • Searches use the provider's connection settings (baseURL, headers and so on) and the account folder the chats used last (configDir).
  • Copies of one page (/de/... locale folders, hl/authuser variants, .md.txt mirrors) are listed once, under the shortest URL. Claude's summary rides on the first result.

This was reviewed and merged first in the beta repo, Tarquinen/opencode-claude-agent#9. This PR ports that code into core, with the tests adapted to core's plugin test harness. Docs are in websearch.mdx, claude-agent.mdx and the spec.

How did you verify your code works?

  • bun test test/plugin/provider/claude-agent test/plugin/websearch.test.ts test/websearch.test.ts test/tool-websearch.test.ts test/config/websearch.test.ts: 160 pass, 0 fail. The new tests cover de-duplication, offering the provider only while connected, searching with only WebSearch and no session persistence through the configured base URL, and following the last-used account folder.
  • bun run typecheck: clean.
  • Ran it day to day with the beta plugin. With websearch.provider: "claude-agent", the websearch tool returned correct results for openai/gpt-6.2-sol, claude-agent/sonnet and opencode/big-pickle.
  • Model swaps: I searched on GPT and continued the same session on Claude Agent Haiku, then did the reverse with Sonnet and GPT. In both directions, the second model quoted the earlier tool output's URLs and summary, and they matched what was stored.

Screenshots / recordings

Not a UI change.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

Added by the opencode bot (AI-generated).

Related: #64996, #10704

Public API: adds the claude-agent value for websearch.provider, offered while Claude Agent is connected (opt-in, backwards compatible)

While Claude Agent is connected, it adds a websearch provider, claude-agent,
that runs Claude Code's WebSearch. Searches count toward the user's Claude plan,
so every model can search the web without a search API key. It is never the
default; users pick it with "websearch": { "provider": "claude-agent" }.

Each search is a one-off Haiku run with only WebSearch, no transcript and
thinking off, closed as soon as the results arrive and timed out after a
minute. It uses the provider's connection settings and the account folder
chats used last. Copies of one page are listed once, and Claude's summary
rides on the first result.

Because results come back through opencode's own websearch tool, they are
stored as ordinary tool output and survive switching between Claude Agent
and other models.

Ported from Tarquinen/opencode-claude-agent#9.

Co-authored-by: Dan Smolsky <dannysmo@gmail.com>
Copilot AI balanced review requested due to automatic review settings November 23, 2026 04:19

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I couldn't verify a real search here: it needs a logged-in Claude Code and network access. In packages/core the claude-agent and websearch tests pass (159 pass, 0 fail) and tsc --noEmit on the source is clean. The new tests use the recorded fake-Claude setup and check the right things (offered only while connected, a WebSearch-only claude run, the forwarded base URL and the last-used account folder).

Public API: one addition, the new provider ID claude-agent for websearch.provider (opt-in, backwards compatible). No other config, event, SDK or server changes.

Concerns:

  • Needs maintainer sign-off. In #64996 the maintainer gave two reasons for declining. This PR answers the first: results are saved as ordinary websearch tool output, so they still work after switching to a non-Claude model. It doesn't answer the second: opencode only matches Claude features it offers itself. A maintainer should confirm they want this before it goes further.
  • Duplicate-link check can drop real results (inline).
  • Haiku is hard-coded (inline). Users whose baseURL points at a gateway that doesn't serve Haiku may see every search fail.

Related: #64996, #10704

@Tarquinen Tarquinen changed the title feat(core): serve opencode's web search with Claude Agent's WebSearch feat(core): add Claude Agent as a web search provider Nov 23, 2026

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new commit fixes the duplicate-link problem from my last review: the de-duplication that could merge unrelated pages (such as /it/foo and /foo) is gone, and results are listed as Claude Code returns them. The spec is updated to match, and the site docs never described it. The claude-agent and websearch tests still pass (158 pass, 0 fail) and tsc --noEmit on packages/core is clean. I still couldn't run a real search here, since that needs a logged-in Claude Code and network access.

Public API: unchanged since the last review. The only addition is still the opt-in claude-agent value for websearch.provider, which is backwards compatible.

The earlier point still stands: given #64996, a maintainer needs to agree to this feature.

@Tarquinen
Tarquinen merged commit 8bae58e into anomalyco:dev Nov 23, 2026
11 checks passed
@Tarquinen

Copy link
Copy Markdown
Member

nice!

@levtechs
levtechs deleted the feat/claude-agent-websearch branch November 23, 2026 13:04
@amrkmn amrkmn mentioned this pull request Nov 23, 2026
1 task
deinspanjer added a commit to deinspanjer/opencode that referenced this pull request Nov 23, 2026
Makes account switching work for Claude Agent as it does for providers whose token opencode holds: `auth switch`, `/connect` and plugins that activate a credential now change the Claude login for every model, with no model aliases.

- Use the active account's folder for the login check, the model list and chats when no `settings.configDir` is set
- Read the folder on each request instead of projecting it into provider settings, so the retry that follows an account switch cannot run on the old account before a provider reload lands
- Claude Agent web search (anomalyco#65704) uses the same folder, so a search runs on the chats' account
- A configured `settings.configDir` still wins, so the per-model and rotation setups keep working
- Document the setup and the precedence
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants