Repository navigation
feat(core): add Claude Agent as a web search provider - #65704
Conversation
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>
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
websearchtool 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
baseURLpoints at a gateway that doesn't serve Haiku may see every search fail.
There was a problem hiding this comment.
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.
|
nice! |
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
Issue for this PR
Related: #64996, #10704, #63487, #63784
Type of change
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'swebsearchtool 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
websearchtool, so results are stored as ordinary tool output that every model can read.How it works:
configDir)./de/...locale folders,hl/authuservariants,.md.txtmirrors) 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.mdxand 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.websearch.provider: "claude-agent", thewebsearchtool returned correct results foropenai/gpt-6.2-sol,claude-agent/sonnetandopencode/big-pickle.Screenshots / recordings
Not a UI change.
Checklist
Added by the opencode bot (AI-generated).
Related: #64996, #10704
Public API: adds the
claude-agentvalue forwebsearch.provider, offered while Claude Agent is connected (opt-in, backwards compatible)