Skip to content

Title: Improve diagnostics when stored credentials or background service environment override API keys #52891

Open

Description

@hagix9

Description

Description

In OpenCode v2.0.21 on macOS, I encountered two authentication issues while configuring a custom OpenAI-compatible provider.

An outdated API key stored in SQLite took precedence over the correct key supplied through the environment variable and configuration.

After removing the outdated credential, opencode run --standalone worked, but the normal TUI continued to fail because it reused a background service that had been started without the required environment variable.

The TUI process had the correct environment variable, but the background service did not. Restarting the service from a terminal with the correct environment resolved the issue.

Expected behavior

It would be helpful if OpenCode could:

Show which credential source is being used, without exposing the API key.

Warn when stored credentials override a configured environment variable.

Provide a diagnostic hint when the background service does not have an environment variable required by the selected provider.

Suggest restarting the service when its environment is outdated.

Actual behavior

The TUI reported an authentication error even though the correct API key was present in the terminal environment and standalone execution succeeded.

Environment

OpenCode v2.0.21

macOS

Custom OpenAI-compatible provider

Managed background service

The issue was resolved by removing the outdated stored credential and running opencode service restart with the correct environment variable.

Plugins

No response

OpenCode version

No response

Steps to reproduce

No response

Screenshot and/or share link

No response

Operating System

No response

Terminal

No response

Activity

  1. github-actions commented on Oct 3, 2026

    @github-actions
    Contributor

    This issue might be a duplicate of existing issues. Please check:

    • #10950: Stored OAuth credentials silently override explicit provider configuration, with no warning.
    • #44914: A background service does not have workspace environment variables available to the TUI; that report focuses on local MCP servers.
  2. opencodejr commented on Oct 27, 2026

    @opencodejr

    Thanks for the detailed write-up, @hagix9, and for including the fix that worked for you (removing the stale stored credential and running opencode service restart from a shell that has the variable set).

    What you're asking for is better visibility into where a provider's credential comes from. Specifically:

    • show which credential source is in use (without revealing the key)
    • warn when a stored credential overrides a configured environment variable
    • give a hint when the background service doesn't have an environment variable the selected provider needs, and suggest restarting it

    The TUI connects to the background service, and that service only sees the environment it was started with. So what you saw is how it currently works, but it's easy to get caught by and hard to diagnose. These suggestions would help.

    I've marked this as a feature request for the maintainers to consider.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions