Skip to content

Commit e5fccf4

Browse files
jimgqyuclaude
andcommitted
feat: CODER_* env vars, settings.json creation, --model interactive switching
- Replace ANTHROPIC_* env vars with CODER_BASE_URL/CODER_MODEL/CODER_AUTH_TOKEN - install.sh: auto-create ~/.coder/settings.json with model config prompts - entry.tsx: add --model flag for interactive model_list selection - README/docs: remove config.yaml references, update to settings.json - coder-client.ts: all ANTHROPIC_* env refs → CODER_* - engine-factory.ts: use CODER_* env vars for provider config Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent 25e00fc commit e5fccf4

12 files changed

Lines changed: 237 additions & 151 deletions

File tree

README.md

Lines changed: 32 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ Skills are stored in `~/.coder/skills/` and can be managed via:
144144
/skills search # Search community skills by keyword
145145
```
146146

147-
Configure skill auto-creation and auto-improvement in `~/.coder/config.yaml`:
147+
Configure skill auto-creation and auto-improvement in `~/.coder/settings.json`:
148148

149149
```yaml
150150
skills:
@@ -226,96 +226,62 @@ skills:
226226

227227
## Configuration
228228

229-
### API Key
229+
### Configuration
230230

231-
Coder Agent primarily uses `ANTHROPIC_API_KEY` for authentication. The legacy `ANTHROPIC_AUTH_TOKEN` is also supported as a fallback.
231+
Coder Agent uses `~/.coder/settings.json` for persistent config, with environment variable overrides.
232232

233-
Priority order for API key resolution:
234-
1. `ANTHROPIC_API_KEY` environment variable
235-
2. `ANTHROPIC_AUTH_TOKEN` environment variable
236-
3. `~/.coder/settings.json``env.ANTHROPIC_API_KEY`
237-
4. `~/.coder/settings.json``env.ANTHROPIC_AUTH_TOKEN`
233+
**Priority order:**
234+
1. CLI flags (`--model`, `--provider`)
235+
2. Environment variables (`CODER_BASE_URL`, `CODER_MODEL`, `CODER_AUTH_TOKEN`)
236+
3. `~/.coder/settings.json``model_list[]` + `env.*`
238237

239238
```bash
240-
# Recommended: set ANTHROPIC_API_KEY
241-
export ANTHROPIC_API_KEY="sk-ant-api03-..."
239+
# Set auth token (required)
240+
export CODER_AUTH_TOKEN="sk-your-key-here"
242241

243-
# Legacy: ANTHROPIC_AUTH_TOKEN also works
244-
export ANTHROPIC_AUTH_TOKEN="sk-ant-api03-..."
242+
# Optional: override model and endpoint
243+
export CODER_MODEL="deepseek-chat"
244+
export CODER_BASE_URL="https://api.deepseek.com/anthropic"
245245
```
246246

247-
For OpenAI or DeepSeek, set the `CODER_PROVIDER` environment variable:
247+
### Model Switching
248248

249+
Switch models interactively:
249250
```bash
250-
# Use OpenAI
251-
export CODER_PROVIDER=openai
252-
export OPENAI_API_KEY="sk-..."
253-
254-
# Use DeepSeek with Anthropic-compatible endpoint
255-
export CODER_PROVIDER=anthropic
256-
export ANTHROPIC_API_KEY="sk-..."
257-
export ANTHROPIC_BASE_URL="https://api.deepseek.com/anthropic"
258-
export ANTHROPIC_MODEL="deepseek-chat"
251+
coder --model # Interactive selection from model_list
252+
coder --model gpt-4o # Switch to a specific model by name
259253
```
260254

261-
### Configuration File (~/.coder/config.yaml)
262-
263-
For persistent configuration, use `~/.coder/config.yaml`:
264-
265-
```yaml
266-
provider: anthropic
267-
model: claude-sonnet-4-20250514
268-
269-
providers:
270-
anthropic:
271-
baseUrl: https://api.anthropic.com
272-
maxRetries: 3
273-
timeoutMs: 120000
274-
openai:
275-
baseUrl: https://api.openai.com/v1
276-
maxRetries: 3
277-
timeoutMs: 120000
278-
deepseek:
279-
baseUrl: https://api.deepseek.com/anthropic
280-
maxRetries: 3
281-
timeoutMs: 120000
282-
283-
permissions:
284-
mode: default # default | accept-edits | bypass
285-
allowedPaths: []
286-
deniedPaths: []
287-
288-
maxTurns: 100
289-
contextBudget: 180000
290-
```
291-
292-
You can also use `~/.coder/settings.json` (JSON format) for environment variables:
255+
### ~/.coder/settings.json
293256

294257
```json
295258
{
296259
"theme": "dark",
297260
"model_list": [
261+
{
262+
"name": "deepseek-v4",
263+
"model": "deepseek-chat",
264+
"base_url": "https://api.deepseek.com/anthropic",
265+
"auth_token_env": "CODER_AUTH_TOKEN",
266+
"provider": "deepseek"
267+
},
298268
{
299269
"name": "claude-sonnet-4-6",
300270
"model": "claude-sonnet-4-6",
301271
"base_url": "https://api.anthropic.com/v1",
302-
"auth_token_env": "ANTHROPIC_API_KEY",
272+
"auth_token_env": "CODER_AUTH_TOKEN",
303273
"provider": "anthropic"
304-
},
305-
{
306-
"name": "deepseek/deepseek-v4-pro",
307-
"model": "deepseek-chat",
308-
"base_url": "https://api.deepseek.com/anthropic",
309-
"auth_token_env": "DEEPSEEK_API_KEY",
310-
"provider": "deepseek"
311274
}
312275
],
313-
"default_model": "claude-sonnet-4-6"
276+
"default_model": "deepseek-v4",
277+
"env": {
278+
"CODER_MODEL": "deepseek-chat",
279+
"CODER_BASE_URL": "https://api.deepseek.com/anthropic",
280+
"CODER_AUTH_TOKEN": ""
281+
}
314282
}
315283
```
316284

317-
> **Note:** `ANTHROPIC_BASE_URL` can also be configured per-provider in `~/.coder/config.yaml` under the `providers` section, rather than as a global environment variable.
318-
319285
### Hook Configuration
320286

321287
Place hook definitions in `~/.coder/hooks/*.json`:
@@ -406,7 +372,7 @@ pnpm ci
406372
## Documentation
407373

408374
- [Getting Started Guide](./docs/getting-started.md) — installation, basic usage, TUI shortcuts, session management
409-
- [Configuration Reference](./docs/configuration.md) — full config.yaml schema, env vars, permission modes, sandbox setup
375+
- [Configuration Reference](./docs/configuration.md) — full settings.json schema, env vars, permission modes, sandbox setup
410376

411377
---
412378

config.example.toml

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
# Coder Agent Configuration
2-
# Copy this file to ~/.coder/config.toml and customize your settings.
1+
# Coder Agent Configuration (DEPRECATED FORMAT)
2+
# This file is kept for reference only. Modern config uses ~/.coder/settings.json.
3+
# Copy this file to ~/.coder/config.toml to use the legacy TOML format.
34

45
[env]
5-
# Anthropic API Configuration
6+
# Coder API Configuration
67
# Priority: environment variables > this file > defaults
7-
# For API key: ANTHROPIC_API_KEY > ANTHROPIC_AUTH_TOKEN
8-
ANTHROPIC_BASE_URL = "https://api.deepseek.com/v1"
9-
ANTHROPIC_AUTH_TOKEN = "sk-ant-xxxxx"
10-
ANTHROPIC_MODEL = "deepseek-v4-pro"
8+
# For API key: CODER_API_KEY > CODER_AUTH_TOKEN
9+
CODER_BASE_URL = "https://api.deepseek.com/v1"
10+
CODER_AUTH_TOKEN = "sk-ant-xxxxx"
11+
CODER_MODEL = "deepseek-v4-pro"
1112

1213
# Appearance
1314
theme = "dark"

configs/test-setup.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ const CREDENTIAL_SUFFIXES = [
3535
];
3636

3737
const CREDENTIAL_NAMES = new Set([
38-
'ANTHROPIC_API_KEY',
39-
'ANTHROPIC_TOKEN',
38+
'CODER_API_KEY',
39+
'CODER_TOKEN',
4040
'OPENAI_API_KEY',
4141
'OPENROUTER_API_KEY',
4242
'GEMINI_API_KEY',

docs/configuration.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
# Configuration Reference
22

3-
Coder Agent is configured through a combination of `~/.coder/config.yaml`,
3+
Coder Agent is configured through a combination of `~/.coder/settings.json`,
44
environment variables, and CLI flags.
55

66
## Config File
77

8-
The primary configuration file lives at `~/.coder/config.yaml`. It is created
8+
The primary configuration file lives at `~/.coder/settings.json`. It is created
99
automatically on first run if it doesn't exist.
1010

1111
### Full Schema
@@ -73,7 +73,7 @@ Environment variables take precedence over the config file.
7373
7474
| Variable | Description | Default |
7575
|----------|-------------|---------|
76-
| `ANTHROPIC_API_KEY` | Anthropic API key | — |
76+
| `CODER_API_KEY` | Coder API key | — |
7777
| `DEEPSEEK_API_KEY` | DeepSeek API key | — |
7878
| `OPENAI_API_KEY` | OpenAI API key | — |
7979
| `CODER_PROVIDER` | LLM provider name | `anthropic` |
@@ -99,7 +99,7 @@ Environment variables take precedence over the config file.
9999
### Anthropic (Default)
100100

101101
```bash
102-
export ANTHROPIC_API_KEY=sk-ant-api03-...
102+
export CODER_API_KEY=sk-ant-api03-...
103103
```
104104

105105
Supported models:
@@ -303,6 +303,6 @@ compactThreshold: 0.7 # Start compacting at 126K tokens
303303

304304
### Multiple Projects
305305

306-
Configuration is global (`~/.coder/config.yaml`), but project-specific
306+
Configuration is global (`~/.coder/settings.json`), but project-specific
307307
instructions go in `CLAUDE.md` at the project root. The agent reads this
308308
file at the start of every session.

docs/getting-started.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ Coder Agent supports multiple LLM providers. Set at least one:
5151

5252
```bash
5353
# Anthropic (default)
54-
export ANTHROPIC_API_KEY=sk-ant-...
54+
export CODER_API_KEY=sk-ant-...
5555

5656
# DeepSeek
5757
export DEEPSEEK_API_KEY=sk-...
@@ -65,7 +65,7 @@ across terminal sessions.
6565

6666
### Provider Selection
6767

68-
Set the provider and model in `~/.coder/config.yaml`:
68+
Set the provider and model in `~/.coder/settings.json`:
6969

7070
```yaml
7171
provider: deepseek

install.sh

Lines changed: 79 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -172,54 +172,91 @@ mkdir -p "${CODER_DIR}/scratchpad"
172172
echo -e "${GREEN}✅ Configuration directory created at ${CODER_DIR}${NC}"
173173

174174
# ---------------------------------------------------------------------------
175-
# 6. API Key setup
175+
# 6. Model Configuration (settings.json)
176176
# ---------------------------------------------------------------------------
177+
SETTINGS_FILE="${CODER_DIR}/settings.json"
178+
177179
echo ""
178180
echo -e "${YELLOW}╔══════════════════════════════════════════════════╗${NC}"
179-
echo -e "${YELLOW}API Key Configuration ║${NC}"
181+
echo -e "${YELLOW}Model Configuration ${NC}"
180182
echo -e "${YELLOW}╚══════════════════════════════════════════════════╝${NC}"
181183
echo ""
182-
echo "Coder Agent supports multiple LLM providers:"
183-
echo " - DeepSeek (default): DEEPSEEK_API_KEY"
184-
echo " - Anthropic: ANTHROPIC_API_KEY"
185-
echo " - OpenAI: OPENAI_API_KEY"
184+
echo "Configure your default LLM provider and model."
186185
echo ""
187186

188-
# Check if API keys are already set
189-
if [ -n "${DEEPSEEK_API_KEY:-}" ]; then
190-
echo -e "${GREEN}✅ DEEPSEEK_API_KEY is already set${NC}"
191-
else
192-
echo -e "${YELLOW}⚠️ DEEPSEEK_API_KEY is not set${NC}"
193-
echo ""
194-
echo "To set it now, enter your DeepSeek API key (or press Enter to skip):"
195-
read -r -p "API Key: " api_key
196-
197-
if [ -n "$api_key" ]; then
198-
# Detect shell config file
199-
SHELL_CONFIG=""
200-
if [ -f "${HOME}/.zshrc" ]; then
201-
SHELL_CONFIG="${HOME}/.zshrc"
202-
elif [ -f "${HOME}/.bashrc" ]; then
203-
SHELL_CONFIG="${HOME}/.bashrc"
204-
elif [ -f "${HOME}/.bash_profile" ]; then
205-
SHELL_CONFIG="${HOME}/.bash_profile"
206-
fi
207-
208-
if [ -n "$SHELL_CONFIG" ]; then
209-
echo "" >> "$SHELL_CONFIG"
210-
echo "# Coder Agent — API Key" >> "$SHELL_CONFIG"
211-
echo "export DEEPSEEK_API_KEY=${api_key}" >> "$SHELL_CONFIG"
212-
echo -e "${GREEN}✅ API key added to ${SHELL_CONFIG}${NC}"
213-
echo ""
214-
echo -e "${YELLOW}Run 'source ${SHELL_CONFIG}' or restart your terminal to apply.${NC}"
215-
else
216-
echo -e "${YELLOW}Could not detect shell config file. Add this to your shell profile:${NC}"
217-
echo " export DEEPSEEK_API_KEY=${api_key}"
218-
fi
219-
else
220-
echo "Skipped. You can set it later:"
221-
echo " export DEEPSEEK_API_KEY=your-key-here"
222-
fi
187+
# -- CODER_BASE_URL --
188+
echo -e "${CYAN}API Base URL${NC} (e.g. https://api.deepseek.com/anthropic)"
189+
echo "Press Enter to skip:"
190+
read -r -p "> " coder_base_url
191+
192+
# -- CODER_MODEL --
193+
echo ""
194+
echo -e "${CYAN}Model ID${NC} (e.g. deepseek-chat, claude-sonnet-4-6)"
195+
echo "Press Enter for default (deepseek-chat):"
196+
read -r -p "> " coder_model
197+
coder_model="${coder_model:-deepseek-chat}"
198+
199+
# -- CODER_AUTH_TOKEN --
200+
echo ""
201+
echo -e "${CYAN}API Key / Auth Token${NC}"
202+
echo "Press Enter to skip (you can set CODER_AUTH_TOKEN env var later):"
203+
read -r -p "> " coder_auth_token
204+
205+
# Build settings.json
206+
SETTINGS_JSON=$(cat <<SETEOF
207+
{
208+
"theme": "dark",
209+
"default_model": "${coder_model}",
210+
"model_list": [
211+
{
212+
"name": "${coder_model}",
213+
"model": "${coder_model}",
214+
"base_url": "${coder_base_url}",
215+
"auth_token_env": "CODER_AUTH_TOKEN",
216+
"provider": "deepseek"
217+
}
218+
],
219+
"env": {
220+
"CODER_MODEL": "${coder_model}",
221+
"CODER_BASE_URL": "${coder_base_url}",
222+
"CODER_AUTH_TOKEN": "${coder_auth_token}"
223+
}
224+
}
225+
SETEOF
226+
)
227+
228+
# Write settings.json
229+
echo "$SETTINGS_JSON" > "$SETTINGS_FILE"
230+
echo -e "${GREEN}✅ Created ${SETTINGS_FILE}${NC}"
231+
232+
# Export env vars for immediate use
233+
if [ -n "$coder_base_url" ]; then
234+
export CODER_BASE_URL="$coder_base_url"
235+
fi
236+
if [ -n "$coder_auth_token" ]; then
237+
export CODER_AUTH_TOKEN="$coder_auth_token"
238+
fi
239+
export CODER_MODEL="$coder_model"
240+
241+
# Add to shell config for persistence
242+
SHELL_CONFIG=""
243+
if [ -f "${HOME}/.zshrc" ]; then
244+
SHELL_CONFIG="${HOME}/.zshrc"
245+
elif [ -f "${HOME}/.bashrc" ]; then
246+
SHELL_CONFIG="${HOME}/.bashrc"
247+
elif [ -f "${HOME}/.bash_profile" ]; then
248+
SHELL_CONFIG="${HOME}/.bash_profile"
249+
fi
250+
251+
if [ -n "$SHELL_CONFIG" ]; then
252+
{
253+
echo ""
254+
echo "# Coder Agent — Model Configuration"
255+
echo "export CODER_MODEL=${coder_model}"
256+
[ -n "$coder_base_url" ] && echo "export CODER_BASE_URL=${coder_base_url}"
257+
[ -n "$coder_auth_token" ] && echo "export CODER_AUTH_TOKEN=${coder_auth_token}"
258+
} >> "$SHELL_CONFIG"
259+
echo -e "${GREEN}✅ Env vars added to ${SHELL_CONFIG}${NC}"
223260
fi
224261

225262
# ---------------------------------------------------------------------------
@@ -244,6 +281,7 @@ echo ""
244281
echo -e "${CYAN}Configuration:${NC}"
245282
echo " ~/.coder/ — Configuration directory"
246283
echo " ~/.coder/settings.json — Provider & model settings"
284+
echo " export CODER_AUTH_TOKEN — Set your API key if skipped during install"
247285
echo " CODER.md — Project-specific instructions"
248286
echo ""
249287
echo -e "${YELLOW}Documentation: https://github.com/AgenticMatrix/Coder-Agent${NC}"

packages/cli/src/config/env.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export const STARTUP_QUERY = (process.env.CODER_TUI_QUERY ?? '').trim()
2929
export const STARTUP_IMAGE = (process.env.CODER_TUI_IMAGE ?? '').trim()
3030

3131
// Mouse tracking mode resolution at startup. Per-mode selection (off|wheel|
32-
// buttons|all) lives in display.mouse_tracking in config.yaml — these env
32+
// buttons|all) lives in display.mouse_tracking in settings.json — these env
3333
// vars only set the boot-time default before that config is applied.
3434
//
3535
// Precedence (highest first):

0 commit comments

Comments
 (0)