anomalyco / anomalyco/opencode

[Bug] Unhandled crash in `Provider.list` when Cloudflare environment variables exist without `CLOUDFLARE_API_TOKEN`

Open
#42,739 6 comments 0 reactions 1 assignee View on GitHub

@jlongster is already working on this.

Since Aug 15, 2026.

Dominant language
TypeScript
Stars
209k
Forks
27.5k
PR merge metrics
PR metrics pending

Description

Description

Description

When launching OpenCode (opencode), the TUI interface fails to start and immediately crashes with the following generic error:

Error: Unexpected server error. Check server logs for details.
    at <anonymous> (/$bunfs/root/chunk-3mfps532.js:8:7615)
    at processTicksAndRejections (native:7:39)

No relevant logs are written to ~/.local/share/opencode/log/, making troubleshooting difficult in default mode.

Root Cause

Running the server directly via opencode serve --print-logs --log-level DEBUG --pure exposed the underlying unhandled exception:

Error: CLOUDFLARE_API_TOKEN (or CF_AIG_TOKEN) is required for Cloudflare AI Gateway. Set it via environment variable or run `opencode auth cloudflare-ai-gateway`.
    at <anonymous> (/$bunfs/root/chunk-dfdqwmkx.js:439:73202)
    at Provider.list (/$bunfs/root/chunk-wrjsh8a1.js:4:1338)
    at Provider.list (definition) (/$bunfs/root/chunk-dfdqwmkx.js:439:87629)
    at ProviderHttpApi.list (/$bunfs/root/chunk-wrjsh8a1.js:2:84381)
    at ProviderHttpApi.list (definition) (/$bunfs/root/chunk-wrjsh8a1.js:4:1057)
    at Server.listen (/$bunfs/root/chunk-wrjsh8a1.js:6:15456)
    at Server.listen (definition) (/$bunfs/root/chunk-wrjsh8a1.js:6:15579)
  • Trigger: OpenCode automatically parses system environment variables (e.g., CLOUDFLARE_ACCOUNT_ID in ~/.zshrc).
  • Bug: During Provider.list initialization, if a partial Cloudflare configuration is detected without a corresponding CLOUDFLARE_API_TOKEN (or CF_AIG_TOKEN), the backend throws an unhandled fatal error instead of skipping or gracefully disabling the provider. This completely breaks the local server and prevents OpenCode from starting.

Expected Behavior

  1. Graceful Fallback: If required credentials for a provider are missing, OpenCode should ignore, skip, or mark that specific provider as inactive rather than terminating the entire server process.
  2. Proper Error Logging: Fatal startup errors should be properly captured and written to the log directory so users can diagnose the failure without running internal headless debugging flags.

I believe OpenCode should not automatically read or infer system environment variables without the user's explicit consent or specification.


Issue #33780 was also caused by this problem.

Plugins

NO

OpenCode version

1.18.18

Steps to reproduce
  1. Set a partial Cloudflare environment variable in your shell profile (e.g., export CLOUDFLARE_ACCOUNT_ID="your_account_id") without setting CLOUDFLARE_API_TOKEN.
  2. Run opencode in the terminal.
  3. Observe the startup crash with Unexpected server error.
Screenshot and/or share link

NO

Operating System

macOS 26.6.1 (Darwin arm64)

Terminal

macOS Terminal

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.