Skip to content

feat(opencode): accept the OpenCode Console login as a credential - #230

Open
bsmely wants to merge 1 commit into
CodeZeno:mainfrom
bsmely:opencode-console-login
Open

bsmely wants to merge 1 commit into
CodeZeno:mainfrom
bsmely:opencode-console-login

Conversation

@bsmely

@bsmely bsmely commented Nov 21, 2026

Copy link
Copy Markdown
Contributor

Why

OpenCode Go is the only provider that requires a manual credential: the README asks for a workspace ID plus the __Host-console_session cookie from an authenticated browser session, and that cookie has to be refreshed by hand whenever the session expires.

Anyone who uses OpenCode Go through the OpenCode Console CLI already has a working login on disk, and the console status endpoint accepts it. Polling it removes the manual step entirely.

What

  • Read ~/.local/share/opencode-console/credential.json ($XDG_DATA_HOME/opencode-console/credential.json, or the file named by OPENCODE_CONSOLE_CREDENTIAL_FILE), take its orgID and access fields, and send them as x-org-id and Authorization: Bearer <access> instead of a cookie.
  • Precedence stays explicit-first: OPENCODE_GO_WORKSPACE_ID + OPENCODE_GO_AUTH_COOKIE, then the saved dashboard configuration (%APPDATA%\opencode-go\config.json and the other paths), then the console login. Existing setups behave exactly as before.
  • The credential-watch signature now hashes the auth kind and watches the console login file, so a token refreshed by the CLI triggers a new poll.
  • README documents the automatic source and notes that the workspace ID is the organization ID, not the short workspace slug.

Verification

  • cargo test --locked --release --bin claude-code-usage-monitor poller::opencode: 14 passed, 0 failed. Five are new: parsing the login file (including orgID / orgId / org_id spellings and trimming), rejecting missing fields, header injection and short workspace slugs, the bearer request being sent without a Cookie header, and a 401 mapped to AuthRequired.
  • cargo fmt --check and cargo clippy --locked --release --bin claude-code-usage-monitor -- -D warnings are clean.
  • Live check against the real endpoint: GET https://opencode.ai/console/api/go/status with Authorization: Bearer taken from the console login returns 200 with access.meters.fiveHour/week/month; the same token sent as Cookie: auth=… or Cookie: __Host-console_session=… returns 401, which is why the header path is needed rather than reusing the cookie code.
  • The built widget polls OpenCode Go and writes the provider into usage-cache.json (session 9.7 %, weekly 3.9 %, monthly 1.9 %), so the tray widget and themes render real values instead of the error placeholder.

Notes

  • The token stays in the CLI's own file; the monitor only reads it and never writes or refreshes it. Any opencode-console command refreshes the login, and after opencode-console logout the poll reports the existing "sign in again" state.
  • No new dependencies, no new settings, and no change to the cookie or environment-variable paths.

The console status endpoint accepts the OAuth access token that the
opencode-console CLI already stores, so OpenCode Go usage can be polled
without asking for a browser session cookie.

Read the login from ~/.local/share/opencode-console/credential.json (also
$XDG_DATA_HOME/... or OPENCODE_CONSOLE_CREDENTIAL_FILE), take its orgID and
access fields, and send them as x-org-id and Authorization: Bearer.

Explicit environment variables and the saved dashboard configuration keep
precedence, and the legacy cookie path behaves exactly as before.
Credential-change tracking now hashes the auth kind and watches the console
login file, so a refreshed token triggers a new poll.
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.

1 participant