GeezerVison is showing github.com — browser: add an API operation to close tabs · Issue #59787 · anomalyco/opencode
browser: add an API operation to close tabs #59787DescriptionSummary
The browser API can open tabs, but it does not appear to expose a way to close one. Please add a tab-closing operation to the browser API so an agent can clean up tabs it opened when it is done with them.
Why this is useful
Agents can create tabs for research, documentation, or testing and inspect the open tabs with browser.tabs.list(). Without a corresponding close operation, those tabs remain open in the GUI after the task finishes. This makes it harder for users to keep their browser tidy and for agents to manage temporary tabs across multi-step workflows.
Proposed behavior
- Add an operation such as
browser.tabs.close({ tabID }), following the existing tab-ID convention used by browser operations.
- Close only the explicitly identified tab; do not implicitly close the focused tab or the whole browser window.
- Define predictable behavior for an unknown or already-closed tab (ideally an actionable error or an idempotent success).
- Handle closing the focused tab and the last remaining tab consistently with the GUI's existing behavior.
- Return enough information for the caller to know the close succeeded and, if applicable, which tab is now focused.
Use case
An agent opens a few pages to compare information, extracts what it needs, then closes those temporary tabs while leaving the user's other tabs untouched.
Acceptance criteria
- The browser API exposes a close-tab operation that accepts an explicit tab ID.
- The operation closes the requested tab in the GUI and reports success or a clear failure.
- Closing one tab does not close unrelated tabs or the browser window.
- Behavior for the focused tab, last tab, and invalid/stale tab IDs is documented and covered by tests.
Automatically submitted on behalf of the user by an AI agent. Activitymynameistito commented on Oct 28, 2026 ContributorAuthor More actions I checked the current dev branch after filing this. The requested operation is already implemented: packages/plugin-browser/src/rpc.ts defines tabs.close with an explicit tabID, documents that it closes only that tab and aborts its work, and returns the updated browser State. packages/plugin-browser/src/tools.ts registers every operation in Browser.Operations as a browser tool, so this operation is exposed as browser.tabs.close without a separate registration change.
I’m closing this issue as already implemented in the current code. If the API you’re using does not show browser.tabs.close, it may be running an older or incompatible OpenCode/browser-plugin build; the missing operation would then be a version/distribution discrepancy rather than an unimplemented feature on dev. opencodejr commented on Oct 28, 2026 Thanks for the suggestion! The browser API should already have this: browser.tabs.close({ tabID }) has been part of the browser operations since v2.0.0. It closes only the tab you name and returns the session's remaining tabs and the focused tab, the same result browser.tabs.list() gives.
If your agent couldn't find it or call it, that may be a bug, so could you tell us, briefly and in your own words:
- Your OpenCode version (
opencode --version) and whether you're using the desktop app
- What happened when the agent tried to close a tab, or how it decided that no close operation existed (the exact error, if there was one)
You can reply here or edit the issue. If you edit it, please also leave a comment saying you've updated it so we know you're done.
Related issues, most relevant first:
mynameistito commented on Oct 28, 2026 ContributorAuthor More actions Thanks for clarifying. I’m on OpenCode Desktop 2.2.0.
I wasn’t trying to call browser.tabs.close from an agent turn. I’m building a GUI plugin that opens Reels automatically on session.execution.started and needs to close that exact tab from the GUI lifecycle handler when the run succeeds, fails, or is interrupted. In the installed @opencode/plugin 2.2.0 types, @opencode/plugin/gui/browser exposes attached, canOpen, open, and openFile; open returns void, and the contract has no tab ID or close method. So I can confirm the agent browser operation exists, but I can’t reach it from this GUI plugin API or retain the tab ID through Browser.open.
Is there a supported way for a GUI plugin to call the desktop browser tab operations (or receive the opened tab ID and close it later)? If those operations are intentionally agent-only, that API boundary is what blocked this use case. mynameistito commented on Oct 28, 2026 ContributorAuthor More actions One more clarification from the GUI plugin side: this is not a failure of an agent calling browser.tabs.close; the GUI lifecycle callback needs to open the page on run start and close it even after interruption. The public GUI Browser.open(session, url) contract returns no tab ID and has no matching close operation, so the plugin cannot use the agent Code Mode operation to clean up its tab. Please consider exposing an equivalent tab-scoped browser API to GUI plugins, or documenting a supported bridge for lifecycle cleanup. opencodejr commented on Oct 31, 2026 Closing this for now, since we haven't heard back. As mentioned above, the browser API already has browser.tabs.close({ tabID }) (since v2.0.0). It closes only the tab you name and returns the remaining tabs and the focused tab. We waited to hear whether your agent couldn't see or call it, which could be a bug.
If it's missing or fails for you, please comment with your OpenCode version (opencode --version) and what happened (the exact error, if there was one), and we can reopen this. Thanks!
MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|