You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# Env Var API Key Priority Over Stored Key Implementation Plan
2
+
3
+
> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking.
4
+
5
+
**Goal:** Make environment variable API keys (e.g. `OPENCODE_API_KEY`) take precedence over API keys stored via the interactive UI, so users can switch keys at launch time without touching stored configuration.
6
+
7
+
**Architecture:** In the provider loading sequence inside `provider.ts`, the `// load apikeys` section currently runs after `// load env` and overwrites whatever env var key was loaded. The fix adds a 2-line guard: before merging a stored API key into a provider, check whether that provider's env vars already provided a key. If so, skip the stored key.
8
+
9
+
**Tech Stack:** TypeScript, Effect, Bun test runner
10
+
11
+
## Global Constraints
12
+
13
+
- Run tests from `packages/opencode`, never from repo root
14
+
- Use `bun test` (not `bun run test`) to run tests
15
+
- Use `bun typecheck` (not `tsc`) for type checking
16
+
- Do not move or restructure code blocks — only add the guard inside the existing loop
17
+
18
+
---
19
+
20
+
### Task 1: Write the failing test
21
+
22
+
**Files:**
23
+
- Modify: `packages/opencode/test/provider/provider.test.ts` (append at end of file)
24
+
25
+
**Interfaces:**
26
+
- Consumes: `Auth.Service` (already imported as `import { Auth } from "@/auth"`), `set` helper (already defined at line 36), `Global` from `@opencode-ai/core/global`, `Filesystem` from `@/util/filesystem`
27
+
- Produces: test case `"env var takes precedence over stored API key"`
28
+
29
+
-[ ]**Step 1: Append the new test to the test file**
30
+
31
+
Open `packages/opencode/test/provider/provider.test.ts` and append at the very end:
32
+
33
+
```typescript
34
+
it.instance("env var takes precedence over stored API key", () =>
0 commit comments