
Brewtools:Provider Switch
- 6 installs
- 29 repo stars
- Updated August 5, 2026
- kochetkov-ma/claude-brewcode
Helps with ai & agent building tasks.
About
brewtools:provider-switch is a Claude Code skill for ai & agent building. It helps solo builders move faster with AI-assisted development.
- brewtools:provider-switch
- AI & Agent Building
- AI-coding skill
Brewtools:Provider Switch by the numbers
- 6 all-time installs (skills.sh)
- +1 installs in the week ending Aug 2, 2026 (Skillselion tracking)
- Ranked #12,824 of 16,544 AI & Agent Building skills by installs in the Skillselion catalog
- Data as of Aug 6, 2026 (Skillselion catalog sync)
npx skills add https://github.com/kochetkov-ma/claude-brewcode --skill brewtoolsprovider-switchAdd your badge
Show developers this skill is listed on Skillselion. Paste this into your README.
| Installs | 6 |
|---|---|
| repo stars | ★ 29 |
| Last updated | August 5, 2026 |
| Repository | kochetkov-ma/claude-brewcode ↗ |
What it does
Helps with ai & agent building tasks.
Files
[DICT: P=Phase, PRV=provider, EXEC=EXECUTE using Bash tool, AUQ=AskUserQuestion, REF=references, ALIAS=shell alias, CFG=configured, BASE=ANTHROPIC_BASE_URL, MOD=ANTHROPIC_DEFAULT_OPUS_MODEL]
Provider Switch
Configure + switch between Claude Code alt API providers — DeepSeek (priority), Z.ai/GLM, Qwen/DashScope, MiniMax, OpenRouter. Creates isolated ALIAS in ~/.zshrc.
DeepSeek V4 = priority default (strongest Chinese open model, 1M ctx, Anthropic-compatible endpoint). Recommend first.
<instructions>
Robustness Rules (MANDATORY)
| Rule | Scope |
|---|---|
| Every Bash call: `&& echo "OK ..." \ | \ |
| On FAILED: stop phase, report error, !=retry blindly | ALL |
| Max 3 AUQ per phase | ALL |
| !=write secrets anywhere except ~/.zshrc | ALL |
| !=commit ~/.zshrc changes | ALL |
| ~/.zshrc comments: ENGLISH only | ALL writes |
Error format on ANY failure:
SCRIPT_ERROR: <name>
PHASE: <current>
ACTION: <attempted>
SUGGESTION: <fix>---
P0: Language Selection
AUQ: "Select language / Выберите язык" | options: "English (Recommended)", "Russian / Русский" Default if skipped: English. Remember for session.
---
Compatibility Flags (REQ per PRV)
| PRV | Required Flags | Why |
|---|---|---|
| DeepSeek | none | silently ignores beta/ver headers; native Anthropic endpoint |
| Z.ai (GLM) | CLAUDE_ENABLE_BYTE_WATCHDOG=0 + CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS=1 | rejects beta headers (err 1210); SSE triggers byte watchdog |
| MiniMax | CLAUDE_ENABLE_BYTE_WATCHDOG=0 + CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS=1 | same as Z.ai |
| Qwen/DashScope | CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS=1 | beta headers may be rejected |
| OpenRouter | none | aggregator, good compat |
When constructing ALIAS (P4 Step 6): ALWAYS include compat flags from PRV REF file.
---
P1: Mode Detection
EXEC:
bash "${CLAUDE_SKILL_DIR}/scripts/detect-mode.sh" "$ARGUMENTS" && echo "OK detect" || echo "FAILED detect"STOP if FAILED — parse $ARGUMENTS manually (keyword match) as fallback.
Output: ARGS: [...] MODE: [...]
| Keyword | MODE |
|---|---|
| status, check | status |
| setup, configure | setup |
| help, how | help |
| deepseek, ds, dpsk | provider-deepseek |
| glm, zai, z.ai | provider-glm |
| qwen, dashscope | provider-qwen |
| minimax, mini | provider-minimax |
| openrouter, router | provider-openrouter |
| verify, test, token | verify |
| model-check, identify | model-check |
| typos (model-cehck, cehck, hlpe, setuo) | fuzzy-match to correct |
| (empty) | status |
---
P2: Status Check (ALL modes)
EXEC:
bash "${CLAUDE_SKILL_DIR}/scripts/check-status.sh" && echo "OK status" || echo "FAILED status"STOP if FAILED — check ~/.zshrc manually with grep.
Parse key=value output. Status per PRV:
configured= ALIAS + KEY both truepartial= ALIAS true, KEY falsenot configured= ALIAS falseactive= ACTIVE_PROVIDER matches
Render status table:
# Provider Switch — [MODE]
## Current Status
| PRV | Alias | API Key | Model | Status |
|-----|-------|---------|-------|--------|
| DeepSeek (priority) | claudeds | DEEPSEEK_API_KEY | deepseek-v4-pro | ... |
| Z.ai / GLM | claudeglm | ZAI_API_KEY | glm-5.1 | ... |
| Qwen | claudeqwen | DASHSCOPE_API_KEY | qwen3.6-plus[1m] | ... |
| MiniMax | claudeminimax | MINIMAX_API_KEY | minimax-m2.7 | ... |
| OpenRouter | claudeor | OPENROUTER_API_KEY | (user-selected) | ... |
## How to Use
Run `claudeds` — sets env vars + launches Claude (recommended default).
Return to Anthropic: new terminal → `claude`.Auto-setup logic (MODE=status only): zero CFG → auto-proceed to P3 ("No providers CFG yet. Starting setup..."). >=1 CFG → STOP here.
If MODE=help → GOTO P6.
---
P3: PRV Selection
If MODE=setup (no specific PRV): AUQ options:
- "DeepSeek V4 (deepseek-v4-pro, 1M ctx, priority - Recommended)"
- "Z.ai / GLM (glm-5.1, free models available)"
- "Qwen / DashScope (qwen3.6-plus, 1M ctx)"
- "MiniMax (minimax-m2.7, cheapest)"
- "OpenRouter (aggregator, any model)"
- "All providers"
If MODE=provider-\<name\> → skip to P4 for that PRV only.
---
P4: PRV Configuration
For each selected PRV:
Step 1: Load REF
Read PRV REF file: DeepSeek=REF/deepseek.md | Z.ai/GLM=REF/zai-glm.md | Qwen=REF/qwen-dashscope.md | MiniMax=REF/minimax.md | OpenRouter=REF/openrouter.md Also read REF/common.md for shared ALIAS structure (first time only).
Step 2: Init Section
EXEC:
bash "${CLAUDE_SKILL_DIR}/scripts/write-alias.sh" init && echo "OK init" || echo "FAILED init"STOP if FAILED — cannot write ~/.zshrc.
Step 3: API Key
Check if key set (from P2: KEY_ZAI, KEY_DASHSCOPE, KEY_MINIMAX, KEY_OPENROUTER). If missing — AUQ: "Enter your <PRV> API key (from <dashboard-url>):"
Qwen-specific: read REF/qwen-dashscope.md ## How to Get API Key before asking. Show step-by-step. Warn: key MUST be from Singapore region — other regions return 403. Valid fmt: sk-... (~40 chars). If starts with sk-ws- or >100 chars → warn wrong region, ask regenerate.
EXEC:
bash "${CLAUDE_SKILL_DIR}/scripts/write-alias.sh" set-key "KEY_VAR_NAME" "KEY_VALUE" && echo "OK set-key" || echo "FAILED set-key"KEY_VAR_NAME: DEEPSEEK_API_KEY | ZAI_API_KEY | DASHSCOPE_API_KEY | MINIMAX_API_KEY | OPENROUTER_API_KEY
STOP if FAILED.
Step 4: Model Selection (OpenRouter only)
Read REF/openrouter-models.md. AUQ options:
- "qwen/qwen3.6-plus[1m] — 1M ctx, top coding (Recommended)"
- "z-ai/glm-5.1 — #1 SWE-bench Pro, 200K"
- "qwen/qwen3-coder:free — free, 262K, code-focused"
- "Custom (specify model ID)"
Selected model = OPUS + SONNET + HAIKU simultaneously. If Custom: validate via script from REF/openrouter-models.md ## Model Validation. If NOT_FOUND → fuzzy suggestions + re-ask. Max 2 retries then fall back to default.
Step 5: ALIAS Name
AUQ: "Alias name for <PRV>:" | options: "<default> (Recommended)", "Custom" If Custom: validate — must start with claude, no spaces, lowercase alphanumeric only.
| PRV | Default |
|---|---|
| DeepSeek | claudeds |
| Z.ai/GLM | claudeglm |
| Qwen | claudeqwen |
| MiniMax | claudeminimax |
| OpenRouter | claudeor |
Step 6: Write ALIAS
Construct body from REF file: semicolon-separated exports + claude at end. EXEC:
bash "${CLAUDE_SKILL_DIR}/scripts/write-alias.sh" set-alias "ALIAS_NAME" "ALIAS_BODY" && echo "OK set-alias" || echo "FAILED set-alias"STOP if FAILED — !=continue to next PRV.
Step 7: Verify
EXEC:
source ~/.zshrc 2>/dev/null && type ALIAS_NAME 2>/dev/null && echo "OK verify" || echo "FAILED verify"STOP if FAILED — ALIAS not written correctly.
---
P5: Verification + Final Status
EXEC:
bash "${CLAUDE_SKILL_DIR}/scripts/check-status.sh" && echo "OK final-status" || echo "FAILED final-status"Render updated status table (same fmt as P2).
Token verification for each just-CFG PRV: EXEC:
bash "${CLAUDE_SKILL_DIR}/scripts/verify-providers.sh" all && echo "OK verify" || echo "FAILED verify"Add verification column to table:
| PRV | Status | Token Test |
|---|---|---|
| Z.ai/GLM | CFG | pass/fail |
If any fail → warn, suggest check API key or endpoint.
Activation instructions:
## Activation
Run ALIAS (e.g. `claudeglm`) — sets env vars + launches Claude.
Return to Anthropic: new terminal → `claude`. Env vars persist current shell only.---
P6: Help Mode
Read REF/common.md. Explain:
| Topic | Detail |
|---|---|
| How ALIAS works | Sets env vars + launches claude — isolated, one PRV at a time |
| How to switch | Run ALIAS (e.g. claudeglm) — sets vars + starts Claude |
| How to return | New terminal → claude — env vars current shell only |
| Context [1m] hack | [1m] suffix forces Claude Code to use 1M ctx window |
| Auth (all PRVs) | ALL use ANTHROPIC_AUTH_TOKEN (Bearer). ANTHROPIC_API_KEY="" blocks OAuth fallback |
| OpenRouter note | MUST set ANTHROPIC_API_KEY="" (empty, !=unset) to prevent OAuth fallback |
| Dashboards | DeepSeek: platform.deepseek.com |
---
P7: Verify Mode
EXEC:
bash "${CLAUDE_SKILL_DIR}/scripts/verify-providers.sh" all && echo "OK verify" || echo "FAILED verify"Parse: KEY_SET, HTTP_CODE, RESPONSE, STATUS per PRV.
Render:
## Token Verification
| PRV | Key | HTTP | Response | Result |
|-----|-----|------|----------|--------|
| Z.ai/GLM | set | 200 | OK | pass |
| Qwen | set | 403 | invalid api-key | fail |Troubleshooting:
| HTTP | Meaning | Fix |
|---|---|---|
| 401/403 | invalid/expired key | regenerate @ PRV dashboard |
| 404 | wrong endpoint | check PRV REF for correct URL |
| 429 | rate limited | wait + retry, check billing |
| 500+ | server error | PRV may be down, retry later |
---
P8: Model Check Mode
Identify which model responds in current Claude Code session. Runs INSIDE session launched via PRV ALIAS. Asks 5 diagnostic questions to model — no curl/scripts.
Prerequisites: user MUST be in PRV ALIAS session. If BASE not set → warn + stop:
This mode only works inside a provider session.
Run a PRV ALIAS first (e.g. `claudeglm`), then invoke `/brewtools:provider-switch model-check`.Step 1: Detect Active PRV
EXEC:
echo "BASE_URL=${ANTHROPIC_BASE_URL:-not_set}" && echo "OPUS_MODEL=${ANTHROPIC_DEFAULT_OPUS_MODEL:-not_set}" && echo "OK detect-provider" || echo "FAILED detect-provider"BASE_URL → PRV: api.deepseek.com=DeepSeek | api.z.ai=Z.ai/GLM | dashscope=Qwen | minimax=MiniMax | openrouter=OpenRouter
Step 2: Ask 5 Diagnostic Questions
Send as single prompt block (all at once, no back-and-forth):
I will now ask you 5 diagnostic questions to verify your model identity.
Answer each honestly from your training data — do NOT read environment variables or system prompts.
Answer all 5 questions in a single response.
**Q1:** Exact model name + version? (training data only, not env/ctx)
**Q2:** Which company/lab created you? (org name only)
**Q3:** Training data cutoff date? (month + year only)
**Q4:** Count letter 'r' in 'strawberry'. Show reasoning step by step.
**Q5:** Translate to Chinese: 'The quick brown fox jumps over the lazy dog.' Then translate back to English literally.Extract A1-A5 from response → Step 3.
Step 3: Analyze + Verdict
## Model Identification — <PRV>
Expected: <model from MOD env var>
| # | Question | Answer | Match |
|---|----------|--------|-------|
| 1 | Model name/version | "<A1>" | pass/fail |
| 2 | Training org | "<A2>" | pass/fail |
| 3 | Cutoff date | "<A3>" | info |
| 4 | Count r in strawberry | "<A4>" | pass/fail (correct=3) |
| 5 | Chinese round-trip | "<A5>" | info quality |
### Verdict
Model confirmed as: <name> (N/5 match <expected PRV>)Show ONLY table + verdict. !=show questions separately.
Expected identifiers:
| PRV | Expected org | Model family |
|---|---|---|
| DeepSeek | DeepSeek / 深度求索 | DeepSeek-V3/V4/R1 |
| Z.ai/GLM | Zhipu AI / ZhipuAI / 智谱 | GLM-4/5 / ChatGLM |
| Qwen | Alibaba / Alibaba Cloud / 阿里 / Tongyi | Qwen/2/3 / 通义千问 |
| MiniMax | MiniMax / 稀宇科技 | MiniMax / abab / M2 |
| OpenRouter | depends on model | depends on model |
For OpenRouter: check against model in MOD env var.
---
P9: Update (hidden, maintainer-only)
If MODE != update → skip entirely.
Step 1: Load Protocol
Read REF/update-protocol.md for per-PRV sources + update flow.
Step 2: Spawn PRV Research Agents (ONE message, 5 Task calls)
| Agent | PRV | Sources |
|---|---|---|
| 1 | DeepSeek | api-docs.deepseek.com — models, pricing, endpoint |
| 2 | Z.ai/GLM | docs.z.ai, open.bigmodel.cn/en — models, pricing |
| 3 | Qwen/DashScope | alibabacloud.com/help, qwenlm.github.io — models, pricing |
| 4 | MiniMax | platform.minimax.io — models, pricing |
| 5 | OpenRouter | openrouter.ai/api/v1/models — top coding/free models |
Each agent: WebFetch/WebSearch sources from protocol, extract current model list + pricing + endpoint changes.
Step 3: Aggregate + Diff
Per PRV: model IDs changed? pricing changed? new models? endpoint URL changed? ctx windows changed?
Step 4: Present Changes
## Update Results
| PRV | Field | Current | Fetched | Action |
|-----|-------|---------|---------|--------|
| Z.ai | opus model | glm-5.1 | glm-6.0 | UPDATE |
| Qwen | pricing | ~$0.50 | $0.40 | UPDATE |
| MiniMax | (no changes) | — | — | SKIP |Step 5: Apply Updates
Edit REF files per field-to-line mapping in REF/update-protocol.md. Also update:
- ALIAS bodies if model IDs changed
openrouter-models.mdif recommended models changedcommon.mdif env var patterns changed (rare)
Step 6: Live Test (optional, if API keys in env)
EXEC:
curl -s -o /dev/null -w "%{http_code}" -X POST "https://api.z.ai/api/anthropic/v1/messages" -H "x-api-key: ${ZAI_API_KEY:-missing}" -H "content-type: application/json" -H "anthropic-version: 2023-06-01" -d '{"model":"glm-5.1","max_tokens":5,"messages":[{"role":"user","content":"ping"}]}' && echo " OK" || echo " FAILED"Step 7: Report
## PRV Update Complete
| PRV | Changes | Status |
|-----|---------|--------|
| Z.ai/GLM | models updated | applied |
| Qwen | no changes | current |
| MiniMax | pricing updated | applied |
| OpenRouter | 3 new free models | applied |
Files modified: [list]---
Output Format
# Provider Switch — [MODE]
## Current Status
| PRV | Alias | API Key | Model | Status |
|-----|-------|---------|-------|--------|
| DeepSeek (priority) | claudeds | DEEPSEEK_API_KEY | deepseek-v4-pro | CFG |
| Z.ai / GLM | claudeglm | ZAI_API_KEY | glm-5.1 | CFG |
| Qwen | claudeqwen | DASHSCOPE_API_KEY | — | not CFG |
| MiniMax | claudeminimax | MINIMAX_API_KEY | — | not CFG |
| OpenRouter | claudeor | OPENROUTER_API_KEY | — | not CFG |
## How to Use
Run `claudeds` — sets env vars + launches Claude (recommended default).
Return to Anthropic: new terminal → `claude`.</instructions>
Provider Switch
Switch Claude Code from Anthropic Max to a pay-per-token API provider — DeepSeek V4 (priority), Z.ai/GLM, Qwen/DashScope, MiniMax, or OpenRouter — without touching any config files manually. The skill creates isolated shell aliases in ~/.zshrc, backs up existing content before any write, and guides key entry interactively.
DeepSeek V4 is the recommended default — strongest Chinese open model (1.6T MoE, 1M context), native Anthropic endpoint, no compatibility flags required.
Quick Start
# Check which providers are configured
/brewtools:provider-switch
# Set up DeepSeek V4 interactively (priority default)
/brewtools:provider-switch deepseek
# Set up Z.ai/GLM interactively
/brewtools:provider-switch glm
# Set up all providers in one run
/brewtools:provider-switch setup
# See how switching works
/brewtools:provider-switch help
# Verify all tokens work
/brewtools:provider-switch verify
# Identify which model is responding (run inside claudeglm session)
/brewtools:provider-switch model-checkAfter setup, run claudeglm — it sets env vars and starts Claude in one command. To return to Anthropic, open a new terminal.
Features
- Interactive language selection (English / Russian) at session start
- Reads current
~/.zshrcstate before any write — shows what is already configured - Auto-starts setup when no provider is configured yet
- OpenRouter: pick one model for all roles, with validated custom ID input
- All writes go into a clearly marked section in
~/.zshrc; backup created before first write - Error reporting with
SCRIPT_ERROR / PHASE / ACTION / SUGGESTIONblock on any failure
Providers
| Provider | Alias | Model (all roles) | Auth pattern | Notes |
|---|---|---|---|---|
| DeepSeek V4 (priority) | claudeds | deepseek-v4-pro | ANTHROPIC_AUTH_TOKEN + API_KEY="" | 1.6T MoE, 1M context, thinking modes, released 2026-04-24 |
| Z.ai / GLM | claudeglm | glm-5.1 | ANTHROPIC_AUTH_TOKEN + API_KEY="" | #1 SWE-bench Pro, $1.40/$4.40 per 1M |
| Qwen / DashScope | claudeqwen | qwen3.6-plus[1m] | ANTHROPIC_AUTH_TOKEN + API_KEY="" | 1M context, ~$0.50/$2.00 per 1M. Singapore region keys only |
| MiniMax | claudeminimax | minimax-m2.7 | ANTHROPIC_AUTH_TOKEN + API_KEY="" | Cheapest: $0.30/$1.20 per 1M |
| OpenRouter | claudeor | user-selected | ANTHROPIC_AUTH_TOKEN + API_KEY="" | Default: qwen/qwen3.6-plus[1m]. Custom IDs validated via API |
Usage Modes
| Argument | Mode | What it does |
|---|---|---|
| (none) | status | Shows provider table; auto-starts setup if nothing is configured |
setup | setup | Interactive selection of one or more providers to configure |
deepseek / ds / dpsk | provider-deepseek | Configure DeepSeek V4 only (priority default) |
glm / zai / z.ai | provider-glm | Configure Z.ai/GLM only |
qwen / dashscope | provider-qwen | Configure Qwen/DashScope only |
minimax / mini | provider-minimax | Configure MiniMax only |
openrouter / router | provider-openrouter | Configure OpenRouter + model selection |
help / how | help | Explains how aliases work, env vars, and dashboards |
verify / test | verify | Tests all configured tokens by sending a minimal API request to each endpoint |
model-check / identify | model-check | Asks 5 diagnostic questions to identify the model (run inside a provider session) |
How Switching Works
Each alias sets six environment variables and launches claude — one command, no separate steps. Env vars only persist in the current shell session. To return to Anthropic, open a new terminal and run claude normally.
| Variable | Purpose |
|---|---|
ANTHROPIC_BASE_URL | Points to the provider's API endpoint |
ANTHROPIC_API_KEY | Set to "" (empty string) for all providers — blocks OAuth fallback |
ANTHROPIC_AUTH_TOKEN | Bearer token with provider API key (all providers) |
ANTHROPIC_DEFAULT_OPUS_MODEL | Model ID for opus-class tasks |
ANTHROPIC_DEFAULT_SONNET_MODEL | Model ID for sonnet-class tasks |
ANTHROPIC_DEFAULT_HAIKU_MODEL | Model ID for haiku-class tasks |
Qwen: Singapore Region Required
The Anthropic-compatible endpoint (dashscope-intl.aliyuncs.com) works ONLY with API keys created in the Singapore region.
1. Open Model Studio → Singapore → API Key 2. Verify region is Singapore (ap-southeast-1) in top-right corner 3. Click Create API Key → select Owner Account → OK 4. Copy the key immediately (shown only once)
Valid key format: sk-... (~36 chars). If you see sk-ws- or a 200+ char key — wrong region (likely Frankfurt).
Files
brewtools/skills/provider-switch/
├── SKILL.md # Skill definition and phases
├── scripts/
│ ├── detect-mode.sh # Parses $ARGUMENTS → MODE
│ ├── check-status.sh # Reads ~/.zshrc, outputs key=value status
│ ├── write-alias.sh # init / set-key / set-alias subcommands
│ └── verify-providers.sh # Tests provider tokens (curl health check)
└── references/
├── common.md # Env var reference, ~/.zshrc structure
├── deepseek.md # DeepSeek V4 alias body and dashboard URL (priority)
├── zai-glm.md # Z.ai alias body and dashboard URL
├── qwen-dashscope.md # Qwen alias body and dashboard URL
├── minimax.md # MiniMax alias body and dashboard URL
├── openrouter.md # OpenRouter alias body and dashboard URL
└── openrouter-models.md # Model presets for OpenRouter pickerProvider Dashboards
| Provider | Dashboard |
|---|---|
| DeepSeek (priority) | https://platform.deepseek.com |
| Z.ai / GLM | https://z.ai/subscribe |
| Qwen / DashScope | https://modelstudio.console.alibabacloud.com/ap-southeast-1?tab=dashboard#/api-key |
| MiniMax | https://platform.minimax.io |
| OpenRouter | https://openrouter.ai |
Documentation
Full docs: provider-switch
---
Author: Maksim Kochetkov | License: MIT
Common — Provider Switch
Environment Variables
Claude Code uses these env vars to connect to alternative providers:
| Variable | Purpose |
|---|---|
ANTHROPIC_BASE_URL | API endpoint (replaces api.anthropic.com) |
ANTHROPIC_API_KEY | API key sent as x-api-key header |
ANTHROPIC_AUTH_TOKEN | Bearer token (alternative to API key) |
ANTHROPIC_DEFAULT_OPUS_MODEL | Model ID for opus role |
ANTHROPIC_DEFAULT_SONNET_MODEL | Model ID for sonnet role |
ANTHROPIC_DEFAULT_HAIKU_MODEL | Model ID for haiku role |
Unified Alias Template
ALL provider aliases MUST follow this exact pattern — no exceptions:
alias claude<name>='export ANTHROPIC_BASE_URL=<endpoint>; export ANTHROPIC_AUTH_TOKEN=$<KEY_VAR>; export ANTHROPIC_API_KEY=""; export ANTHROPIC_DEFAULT_OPUS_MODEL=<model>; export ANTHROPIC_DEFAULT_SONNET_MODEL=<model>; export ANTHROPIC_DEFAULT_HAIKU_MODEL=<model>; claude'| Part | Value | Why |
|---|---|---|
ANTHROPIC_AUTH_TOKEN | $KEY_VAR | Bearer auth — works with ALL providers |
ANTHROPIC_API_KEY | "" (empty string) | Prevents OAuth fallback. NOT unset — empty string is deterministic |
| Model vars | Same model for all 3 | One model per provider, no role splitting |
Returning to Anthropic Subscription
No special alias needed. Env vars set by provider aliases only persist in the current shell session. To return to Anthropic:
Open a new terminal and run `claude` normally — it will use your Max subscription via OAuth.
.zshrc Structure
All provider config goes in a clearly marked section:
# ========== Claude Code Provider Aliases ==========
# Managed by brewtools:provider-switch — do not edit manually
# API Keys
export DEEPSEEK_API_KEY="sk-..."
export ZAI_API_KEY="..."
export DASHSCOPE_API_KEY="..."
export MINIMAX_API_KEY="..."
export OPENROUTER_API_KEY="sk-or-v1-..."
# Provider Aliases (unified: AUTH_TOKEN + API_KEY="" + 3 model vars + claude)
alias claudeds='export ANTHROPIC_BASE_URL=https://api.deepseek.com/anthropic; export ANTHROPIC_AUTH_TOKEN=$DEEPSEEK_API_KEY; export ANTHROPIC_API_KEY=""; export ANTHROPIC_DEFAULT_OPUS_MODEL=deepseek-v4-pro; export ANTHROPIC_DEFAULT_SONNET_MODEL=deepseek-v4-pro; export ANTHROPIC_DEFAULT_HAIKU_MODEL=deepseek-v4-pro; claude'
alias claudeglm='export ANTHROPIC_BASE_URL=https://api.z.ai/api/anthropic; export ANTHROPIC_AUTH_TOKEN=$ZAI_API_KEY; export ANTHROPIC_API_KEY=""; export ANTHROPIC_DEFAULT_OPUS_MODEL=glm-5.1; export ANTHROPIC_DEFAULT_SONNET_MODEL=glm-5.1; export ANTHROPIC_DEFAULT_HAIKU_MODEL=glm-5.1; claude'
alias claudeqwen='export ANTHROPIC_BASE_URL=https://dashscope-intl.aliyuncs.com/apps/anthropic; export ANTHROPIC_AUTH_TOKEN=$DASHSCOPE_API_KEY; export ANTHROPIC_API_KEY=""; export ANTHROPIC_DEFAULT_OPUS_MODEL="qwen3.6-plus[1m]"; export ANTHROPIC_DEFAULT_SONNET_MODEL="qwen3.6-plus[1m]"; export ANTHROPIC_DEFAULT_HAIKU_MODEL="qwen3.6-plus[1m]"; claude'
# ... etc (same pattern for all providers)
# ========== End Claude Code Provider Aliases ==========Usage Pattern
1. Run provider alias: claudeglm — sets env vars and launches Claude in one command 2. When done, close the terminal 3. Next time: run claude normally = Anthropic subscription, or run alias = provider
DeepSeek (V4)
Priority provider — DeepSeek V4 is the strongest Chinese open model (1.6T MoE, 1M context) with a native Anthropic-compatible endpoint. Recommended default for this skill.
Connection
| Field | Value |
|---|---|
| Endpoint | https://api.deepseek.com/anthropic |
| Auth env var | ANTHROPIC_AUTH_TOKEN (Bearer) — x-api-key also supported |
| Key source env | DEEPSEEK_API_KEY |
| Pay model | Pay-per-token |
Auth Note
DeepSeek accepts both x-api-key and Authorization: Bearer. Uses ANTHROPIC_AUTH_TOKEN (unified with other providers). Must set ANTHROPIC_API_KEY="" to prevent OAuth fallback.
Model
| Field | Value |
|---|---|
| Model ID (top) | deepseek-v4-pro |
| Fallback | deepseek-v4-flash (auto-mapped on unknown model IDs) |
| Context | 1M tokens |
| Modes | non-thinking, thinking, thinking_max |
| Released | 2026-04-24 |
Same top model for all three Claude Code roles (opus/sonnet/haiku).
Compatibility Flags
None required. DeepSeek ignores anthropic-beta, anthropic-version, top_k, container, mcp_servers silently — no Claude Code workaround needed. Multimodal input (images/documents) is NOT supported.
Alias
alias claudeds='export ANTHROPIC_BASE_URL=https://api.deepseek.com/anthropic; export ANTHROPIC_AUTH_TOKEN=$DEEPSEEK_API_KEY; export ANTHROPIC_API_KEY=""; export ANTHROPIC_DEFAULT_OPUS_MODEL=deepseek-v4-pro; export ANTHROPIC_DEFAULT_SONNET_MODEL=deepseek-v4-pro; export ANTHROPIC_DEFAULT_HAIKU_MODEL=deepseek-v4-pro; claude'Dashboard
https://platform.deepseek.com (API keys, billing, usage)
MiniMax
Connection
| Field | Value |
|---|---|
| Endpoint | https://api.minimax.io/anthropic |
| Auth env var | ANTHROPIC_AUTH_TOKEN |
| Key source env | MINIMAX_API_KEY |
| Pay model | Pay-per-token |
Auth Note
Uses ANTHROPIC_AUTH_TOKEN. Must set ANTHROPIC_API_KEY="" (empty string, NOT unset) to prevent OAuth fallback.
Models
| Role | Model ID | Context | Input $/1M | Output $/1M |
|---|---|---|---|---|
| opus | minimax-m2.7 | 200K | $0.30 | $1.20 |
| sonnet | minimax-m2.7 | 200K | $0.30 | $1.20 |
| haiku | minimax-m2.7 | 200K | $0.30 | $1.20 |
Note: MiniMax currently has only one model (M2.7), used for all three roles.
Compatibility Flags (REQUIRED)
CLAUDE_ENABLE_BYTE_WATCHDOG=0— disables byte-level streaming watchdogCLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS=1— strips beta headers that MiniMax rejects
Prompt Caching (Verified)
MiniMax fully supports Anthropic-style prompt caching on the Anthropic-compatible endpoint. Docs: https://platform.minimax.io/docs/api-reference/anthropic-api-compatible-cache
| Type | Price / 1M tokens | Multiplier |
|---|---|---|
| Standard input | $0.30 | baseline |
| Cache write | $0.375 | 1.25x input |
| Cache read | $0.06 | 0.1x input |
- TTL: 5 minutes, auto-refreshed on hit
- Max breakpoints: 4 per request
- Min tokens: 512
- Response fields:
cache_creation_input_tokens,cache_read_input_tokens - Supported models: M2.7, M2.7-highspeed, M2.5, M2.1, M2
Alias
alias claudeminimax='export ANTHROPIC_BASE_URL=https://api.minimax.io/anthropic; export ANTHROPIC_AUTH_TOKEN=$MINIMAX_API_KEY; export ANTHROPIC_API_KEY=""; export ANTHROPIC_DEFAULT_OPUS_MODEL=minimax-m2.7; export ANTHROPIC_DEFAULT_SONNET_MODEL=minimax-m2.7; export ANTHROPIC_DEFAULT_HAIKU_MODEL=minimax-m2.7; export CLAUDE_ENABLE_BYTE_WATCHDOG=0; export CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS=1; claude'Dashboard
https://platform.minimax.io/ (account, billing, API keys)
OpenRouter — Model Selection
How It Works
OpenRouter aggregates 200+ models. The alias sets ONE model for all three Claude Code roles (opus/sonnet/haiku). User picks a single model during setup — it is used everywhere.
Recommended Models by Category
Coding (best for Claude Code)
| Model ID | Context | Price (in/out $/1M) | Notes |
|---|---|---|---|
| qwen/qwen3.6-plus[1m] | 1M | ~$0.33/$1.95 | Top coding, 1M context (Recommended) |
| z-ai/glm-5.1 | 200K | $1.40/$4.40 | #1 SWE-bench Pro |
| qwen/qwen3-coder-plus | 1M | $0.65/$3.25 | Code-focused, 1M context |
| deepseek/deepseek-r1 | 128K | $0.55/$2.19 | Strong reasoning |
Budget / Free
| Model ID | Context | Price | Notes |
|---|---|---|---|
| qwen/qwen3-coder:free | 262K | FREE | Code-focused, rate-limited |
| qwen/qwen3-next-80b-a3b-instruct:free | 262K | FREE | General, rate-limited |
| minimax/minimax-m2.5:free | 196K | FREE | Rate-limited |
| google/gemma-4-26b-a4b-it:free | 262K | FREE | Lightweight |
General Purpose
| Model ID | Context | Price (in/out $/1M) | Notes |
|---|---|---|---|
| google/gemini-2.5-pro | 1M | $1.25/$10.00 | Strong all-round |
| minimax/minimax-m2.7 | 200K | $0.30/$1.20 | Cheapest decent |
| qwen/qwen3.5-flash-02-23 | 1M | $0.065/$0.26 | Ultra-cheap, fast |
Model Validation
When user enters a custom model ID, verify it exists on OpenRouter:
EXECUTE using Bash tool:
curl -s "https://openrouter.ai/api/v1/models" -H "Authorization: Bearer $OPENROUTER_API_KEY" | python3 -c "
import json, sys
data = json.load(sys.stdin)
target = 'USER_MODEL_ID'
matches = [m for m in data.get('data', []) if m['id'] == target]
if matches:
m = matches[0]
p = m.get('pricing', {})
print(f'FOUND: {m[\"id\"]} ctx={m.get(\"context_length\",\"?\")} prompt=\${p.get(\"prompt\",\"?\")} completion=\${p.get(\"completion\",\"?\")}')
else:
# Fuzzy search
fuzzy = [m for m in data.get('data', []) if target.lower() in m['id'].lower()][:5]
print(f'NOT_FOUND: {target}')
if fuzzy:
print('Did you mean:')
for m in fuzzy:
print(f' {m[\"id\"]}')
" && echo "OK validate" || echo "FAILED validate"Replace USER_MODEL_ID with the user's input. If NOT_FOUND — show suggestions and re-ask.
Selection Flow (AskUserQuestion)
Ask user to pick ONE model (used for all roles): 1. "Which model to use?" with top 4 options from coding category 2. Allow "Other" for custom model ID input
The selected model is set as OPUS, SONNET, and HAIKU simultaneously.
Context Window Note
Add [1m] suffix to model ID if the model supports >200K context. Without it, Claude Code caps autocompact at 200K.
OpenRouter (Aggregator)
Connection
| Field | Value |
|---|---|
| Endpoint | https://openrouter.ai/api |
| Auth env var | ANTHROPIC_AUTH_TOKEN |
| Key source env | OPENROUTER_API_KEY |
| Extra required | ANTHROPIC_API_KEY="" (empty string, prevents OAuth fallback) |
| Pay model | Pay-per-token, varies by model |
Auth Note
Uses ANTHROPIC_AUTH_TOKEN. Must set ANTHROPIC_API_KEY="" (empty string, NOT unset) to prevent OAuth fallback. URL: https://openrouter.ai/api — no /v1 suffix.
Model Format
Models use provider/model-name format, e.g.: qwen/qwen3.6-plus, z-ai/glm-5.1, qwen/qwen3-coder:free. Claude Code has 3 internal roles: opus, sonnet, haiku. Each overridden via env var.
Default Model (customizable)
One model for all three roles. User selects during setup.
| Field | Default |
|---|---|
| Model | qwen/qwen3.6-plus[1m] |
| Applied to | OPUS + SONNET + HAIKU (all same) |
Alias Template
alias claudeor='export ANTHROPIC_BASE_URL=https://openrouter.ai/api; export ANTHROPIC_AUTH_TOKEN=$OPENROUTER_API_KEY; export ANTHROPIC_API_KEY=""; export ANTHROPIC_DEFAULT_OPUS_MODEL="MODEL"; export ANTHROPIC_DEFAULT_SONNET_MODEL="MODEL"; export ANTHROPIC_DEFAULT_HAIKU_MODEL="MODEL"; claude'Replace MODEL with user's chosen model ID (same value for all three vars).
Dashboard
https://openrouter.ai/settings/keys (API keys, billing, usage)
Qwen / Alibaba DashScope
Connection
| Field | Value |
|---|---|
| Endpoint | https://dashscope-intl.aliyuncs.com/apps/anthropic |
| Auth env var | ANTHROPIC_AUTH_TOKEN |
| Key source env | DASHSCOPE_API_KEY |
| Pay model | Pay-per-token |
Auth Note
Uses ANTHROPIC_AUTH_TOKEN (bearer-style). Must set ANTHROPIC_API_KEY="" (empty string, NOT unset) to prevent Anthropic OAuth fallback.
Region Requirement
CRITICAL: The Anthropic-compatible endpoint (dashscope-intl.aliyuncs.com/apps/anthropic) works ONLY with API keys created in the Singapore region. Keys from Frankfurt (eu-central-1), US Virginia, or other regions return 403. When asking user for API key, warn: select Singapore region in Model Studio console first. Standard key format: sk-... (~40 chars). If key starts with sk-ws- or is >100 chars — likely wrong region.
Model
| Field | Value |
|---|---|
| Model ID | qwen3.6-plus[1m] |
| Context | 1M |
| Input $/1M | ~$0.50 |
| Output $/1M | ~$2.00 |
| SWE-bench Pro | 56.6% |
Same model for all three Claude Code roles (opus/sonnet/haiku).
Note: [1m] suffix is REQUIRED — Claude Code defaults to 200K context otherwise (GitHub issue #40753).
Compatibility Flags
CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS=1— strips beta headers that DashScope may reject
Alias
alias claudeqwen='export ANTHROPIC_BASE_URL=https://dashscope-intl.aliyuncs.com/apps/anthropic; export ANTHROPIC_AUTH_TOKEN=$DASHSCOPE_API_KEY; export ANTHROPIC_API_KEY=""; export ANTHROPIC_DEFAULT_OPUS_MODEL="qwen3.6-plus[1m]"; export ANTHROPIC_DEFAULT_SONNET_MODEL="qwen3.6-plus[1m]"; export ANTHROPIC_DEFAULT_HAIKU_MODEL="qwen3.6-plus[1m]"; export CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS=1; claude'How to Get API Key
1. Open https://modelstudio.console.alibabacloud.com/ap-southeast-1?tab=dashboard#/api-key (direct link to Singapore region) 2. Verify region is Singapore (ap-southeast-1) in top-right corner — other regions (Frankfurt, Virginia) do NOT support the Anthropic endpoint 3. Click Create API Key → select Owner Account → OK 4. Copy the key immediately (shown only once)
Valid key: starts with sk-, ~36 characters (e.g., sk-1e88...80df). If you see sk-ws- or a 200+ char key — wrong region.
Dashboard
https://modelstudio.console.alibabacloud.com/ap-southeast-1?tab=dashboard#/api-key (Singapore region — API keys, billing)
Update Protocol (maintainer-only, hidden mode)
Purpose
Verify and refresh provider reference data: models, pricing, endpoints, context windows. Run periodically or when provider announces changes.
Per-Provider Sources
Z.ai / GLM
| Check | Source | Method |
|---|---|---|
| Models | https://docs.z.ai/guides/overview/pricing | WebFetch |
| Models | https://open.bigmodel.cn/en/dev/api/normal-model/glm-5 | WebFetch |
| Pricing | Same as above | WebFetch |
| Endpoint | https://api.z.ai/api/anthropic/v1/messages (test call) | Bash curl |
| Live test | curl -s -X POST https://api.z.ai/api/anthropic/v1/messages -H "x-api-key: $ZAI_API_KEY" -H "content-type: application/json" -H "anthropic-version: 2023-06-01" -d '{"model":"glm-5.1","max_tokens":10,"messages":[{"role":"user","content":"ping"}]}' | Bash |
Qwen / DashScope
| Check | Source | Method |
|---|---|---|
| Models | https://www.alibabacloud.com/help/en/model-studio/claude-code | WebFetch |
| Models | https://help.aliyun.com/zh/model-studio/getting-started/models | WebFetch |
| Pricing | Same pages | WebFetch |
| New releases | WebSearch: Qwen latest model release site:alibabacloud.com OR site:qwenlm.github.io | WebSearch |
MiniMax
| Check | Source | Method |
|---|---|---|
| Models | https://platform.minimax.io/docs/guides/text-ai-coding-tools | WebFetch |
| Pricing | https://platform.minimax.io/docs/guides/models-intro | WebFetch |
| New releases | WebSearch: MiniMax new model 2026 site:platform.minimax.io | WebSearch |
OpenRouter
| Check | Source | Method |
|---|---|---|
| Models | https://openrouter.ai/api/v1/models (JSON API) | WebFetch |
| Top coding models | WebSearch: best coding models OpenRouter 2026 | WebSearch |
| Free models | Filter JSON response: pricing.prompt == "0" | Parse |
| Pricing changes | Compare fetched data vs current reference | Diff |
Update Flow
1. Spawn 4 Explore agents in parallel (one per provider) 2. Each agent: WebFetch sources, extract model list + pricing + endpoint status 3. Aggregate results 4. For each provider where data changed:
- Show diff to maintainer (current vs fetched)
- Update reference file via Edit tool
5. If OpenRouter model recommendations changed — update openrouter-models.md 6. Update SKILL.md status table default models if needed 7. Run check-status.sh to verify no breakage
What to Update in References
| Field | File | Line pattern |
|---|---|---|
| Model IDs | {provider}.md | ` |
| Pricing | {provider}.md | ` |
| Endpoint URL | {provider}.md | ` |
| Context window | {provider}.md | Context column |
| Alias body | {provider}.md | `bash block |
| Free models | openrouter-models.md | Budget table |
| Recommended models | openrouter-models.md | Coding/General tables |
What NOT to Update
- SKILL.md phases/logic (only status table defaults)
- Scripts (detect-mode.sh, check-status.sh, write-alias.sh)
- common.md structure (env var names are stable)
- User's ~/.zshrc (never touch during update)
Live Test Template
For each provider, verify endpoint still responds:
curl -s -o /dev/null -w "%{http_code}" -X POST "${ENDPOINT}/v1/messages" \
-H "x-api-key: ${API_KEY}" \
-H "content-type: application/json" \
-H "anthropic-version: 2023-06-01" \
-d '{"model":"MODEL_ID","max_tokens":5,"messages":[{"role":"user","content":"hi"}]}' \
&& echo " OK" || echo " FAILED"Adjust headers per provider (x-api-key for Z.ai, Authorization: Bearer for others).
Z.ai / ZhipuAI (GLM)
Connection
| Field | Value |
|---|---|
| Endpoint | https://api.z.ai/api/anthropic |
| Auth env var | ANTHROPIC_AUTH_TOKEN |
| Key source env | ZAI_API_KEY |
| Pay model | Pay-per-token, no subscription needed |
Auth Note
Z.ai supports both x-api-key and Bearer token auth. Uses ANTHROPIC_AUTH_TOKEN (unified with other providers). Must set ANTHROPIC_API_KEY="" to prevent OAuth fallback.
Model
| Field | Value |
|---|---|
| Model ID | glm-5.1 |
| Context | 200K |
| Input $/1M | $1.40 |
| Output $/1M | $4.40 |
| SWE-bench Pro | 58.4% (#1) |
Same model for all three Claude Code roles (opus/sonnet/haiku).
Compatibility Flags (REQUIRED)
CLAUDE_ENABLE_BYTE_WATCHDOG=0— disables byte-level streaming watchdogCLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS=1— strips beta headers that Z.ai rejects with error 1210
Alias
alias claudeglm='export ANTHROPIC_BASE_URL=https://api.z.ai/api/anthropic; export ANTHROPIC_AUTH_TOKEN=$ZAI_API_KEY; export ANTHROPIC_API_KEY=""; export ANTHROPIC_DEFAULT_OPUS_MODEL=glm-5.1; export ANTHROPIC_DEFAULT_SONNET_MODEL=glm-5.1; export ANTHROPIC_DEFAULT_HAIKU_MODEL=glm-5.1; export CLAUDE_ENABLE_BYTE_WATCHDOG=0; export CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS=1; claude'Dashboard
https://z.ai/subscribe (English console, API keys, billing)
#!/bin/bash
set -euo pipefail
# check-status.sh — Check current provider configuration state
# Usage: check-status.sh
ZSHRC="$HOME/.zshrc"
SECTION_MARKER="# ========== Claude Code Provider Aliases =========="
# Check if ~/.zshrc exists
if [[ -f "$ZSHRC" ]]; then
echo "ZSHRC_EXISTS=true"
else
echo "ZSHRC_EXISTS=false"
echo "SECTION_EXISTS=false"
echo "ALIAS_DEEPSEEK=false"
echo "ALIAS_GLM=false"
echo "ALIAS_QWEN=false"
echo "ALIAS_MINIMAX=false"
echo "ALIAS_OPENROUTER=false"
echo "KEY_DEEPSEEK=false"
echo "KEY_ZAI=false"
echo "KEY_DASHSCOPE=false"
echo "KEY_MINIMAX=false"
echo "KEY_OPENROUTER=false"
echo "ACTIVE_PROVIDER=anthropic"
echo "ACTIVE_BASE_URL="
echo "ACTIVE_OPUS_MODEL="
echo "ACTIVE_SONNET_MODEL="
echo "ACTIVE_HAIKU_MODEL="
echo "OK check-status"
exit 0
fi
# Check section exists
if grep -q "$SECTION_MARKER" "$ZSHRC" 2>/dev/null; then
echo "SECTION_EXISTS=true"
else
echo "SECTION_EXISTS=false"
fi
# Check aliases (support both new claudeX and old claude-X formats)
check_alias() {
local name="$1"
if grep -qE "^alias claude${name}=|^alias claude-${name}=" "$ZSHRC" 2>/dev/null; then
echo "true"
else
echo "false"
fi
}
echo "ALIAS_DEEPSEEK=$(check_alias deepseek)"
echo "ALIAS_GLM=$(check_alias glm)"
echo "ALIAS_QWEN=$(check_alias qwen)"
echo "ALIAS_MINIMAX=$(check_alias minimax)"
echo "ALIAS_OPENROUTER=$(check_alias openrouter)"
# Also detect custom alias names containing provider keyword
echo "ALIAS_OR=$(check_alias or)"
echo "ALIAS_DS=$(check_alias ds)"
# Check API key exports (non-empty values)
check_key() {
local var="$1"
if grep -qE "^export ${var}=.+" "$ZSHRC" 2>/dev/null; then
echo "true"
else
echo "false"
fi
}
echo "KEY_DEEPSEEK=$(check_key DEEPSEEK_API_KEY)"
echo "KEY_ZAI=$(check_key ZAI_API_KEY)"
echo "KEY_DASHSCOPE=$(check_key DASHSCOPE_API_KEY)"
echo "KEY_MINIMAX=$(check_key MINIMAX_API_KEY)"
echo "KEY_OPENROUTER=$(check_key OPENROUTER_API_KEY)"
# Determine active provider from environment
BASE_URL="${ANTHROPIC_BASE_URL:-}"
PROVIDER="anthropic"
if [[ -n "$BASE_URL" ]]; then
if [[ "$BASE_URL" == *"deepseek.com"* ]]; then
PROVIDER="deepseek"
elif [[ "$BASE_URL" == *"z.ai"* ]]; then
PROVIDER="glm"
elif [[ "$BASE_URL" == *"dashscope"* ]]; then
PROVIDER="qwen"
elif [[ "$BASE_URL" == *"minimax"* ]]; then
PROVIDER="minimax"
elif [[ "$BASE_URL" == *"openrouter"* ]]; then
PROVIDER="openrouter"
else
PROVIDER="unknown"
fi
fi
echo "ACTIVE_PROVIDER=$PROVIDER"
echo "ACTIVE_BASE_URL=$BASE_URL"
echo "ACTIVE_OPUS_MODEL=${ANTHROPIC_DEFAULT_OPUS_MODEL:-}"
echo "ACTIVE_SONNET_MODEL=${ANTHROPIC_DEFAULT_SONNET_MODEL:-}"
echo "ACTIVE_HAIKU_MODEL=${ANTHROPIC_DEFAULT_HAIKU_MODEL:-}"
echo "OK check-status"
exit 0
#!/bin/bash
set -euo pipefail
# detect-mode.sh — Parse skill arguments and output detected mode
# Usage: detect-mode.sh "$ARGUMENTS"
ARGS="${1:-}"
ARGS_LOWER=$(echo "$ARGS" | tr '[:upper:]' '[:lower:]')
echo "ARGS: [$ARGS]"
MODE=""
if [[ -z "$ARGS_LOWER" ]]; then
MODE="status"
elif [[ "$ARGS_LOWER" =~ (status|check|текущий) ]]; then
MODE="status"
elif [[ "$ARGS_LOWER" =~ (setup|configure|настрой|добавь) ]]; then
MODE="setup"
elif [[ "$ARGS_LOWER" =~ (help|how|как|помощь) ]]; then
MODE="help"
elif [[ "$ARGS_LOWER" =~ (deepseek|deep-seek|dpsk|дипсик|(^| )ds( |$)) ]]; then
MODE="provider-deepseek"
elif [[ "$ARGS_LOWER" =~ (glm|zai|z\.ai|zhipu) ]]; then
MODE="provider-glm"
elif [[ "$ARGS_LOWER" =~ (qwen|dashscope|alibaba) ]]; then
MODE="provider-qwen"
elif [[ "$ARGS_LOWER" =~ (minimax|mini) ]]; then
MODE="provider-minimax"
elif [[ "$ARGS_LOWER" =~ (openrouter|router|open-router) ]]; then
MODE="provider-openrouter"
elif [[ "$ARGS_LOWER" =~ (verify|test|проверь|тест|токен) ]]; then
MODE="verify"
elif [[ "$ARGS_LOWER" =~ (model-check|model.check|модель|identify|идентиф) ]]; then
MODE="model-check"
elif [[ "$ARGS_LOWER" =~ (update|refresh|обнови|sync) ]]; then
MODE="update"
else
# Fuzzy matching for typos before final fallback
if [[ "$ARGS_LOWER" =~ (model.*check|check.*model|cehck|identif|модель|verif|провер) ]]; then
MODE="model-check"
elif [[ "$ARGS_LOWER" =~ (status|statu|stat|чек|текущ) ]]; then
MODE="status"
elif [[ "$ARGS_LOWER" =~ (setup|set.*up|setuo|config|настрой|добавь) ]]; then
MODE="setup"
elif [[ "$ARGS_LOWER" =~ (help|hlpe|how|помощь|хелп) ]]; then
MODE="help"
elif [[ "$ARGS_LOWER" =~ (deepseek|deep-seek|dpsk|дипсик|(^| )ds( |$)) ]]; then
MODE="provider-deepseek"
elif [[ "$ARGS_LOWER" =~ (glm|zai|z\.ai|zhipu) ]]; then
MODE="provider-glm"
elif [[ "$ARGS_LOWER" =~ (qwen|dash|alibaba) ]]; then
MODE="provider-qwen"
elif [[ "$ARGS_LOWER" =~ (minimax|mini) ]]; then
MODE="provider-minimax"
elif [[ "$ARGS_LOWER" =~ (openrouter|open\.router|router) ]]; then
MODE="provider-openrouter"
elif [[ "$ARGS_LOWER" =~ (verify|test|тест|токен|token) ]]; then
MODE="verify"
elif [[ "$ARGS_LOWER" =~ (update|updtae|refresh|sync) ]]; then
MODE="update"
else
MODE="status"
fi
fi
echo "MODE: $MODE"
exit 0
#!/bin/bash
set -uo pipefail
# Usage: verify-providers.sh [deepseek|glm|qwen|minimax|openrouter|all]
# Tests provider tokens by sending a minimal Anthropic API request.
# Load API keys from ~/.zshrc without executing zsh-only syntax: grep exports
if [[ -f "$HOME/.zshrc" ]]; then
while IFS= read -r line; do
# Strip "export " prefix and eval to set variable in this shell
eval "$line" 2>/dev/null || true
done < <(grep -E '^export (DEEPSEEK_API_KEY|ZAI_API_KEY|DASHSCOPE_API_KEY|MINIMAX_API_KEY|OPENROUTER_API_KEY)=' "$HOME/.zshrc" 2>/dev/null || true)
fi
TARGET="${1:-all}"
TARGET_LOWER="$(echo "$TARGET" | tr '[:upper:]' '[:lower:]')"
verify_provider() {
local name="$1"
local endpoint="$2"
local key_var="$3"
local model="$4"
local key="${!key_var:-}"
echo "PROVIDER=$name"
if [[ -z "$key" ]]; then
echo "KEY_SET=false"
echo "HTTP_CODE=-"
echo "RESPONSE=-"
echo "STATUS=skip"
echo ""
return
fi
echo "KEY_SET=true"
set +e
RAW=$(curl -s -w "\n%{http_code}" -m 15 -X POST "$endpoint" \
-H "Authorization: Bearer $key" \
-H "content-type: application/json" \
-H "anthropic-version: 2023-06-01" \
-d "{\"model\":\"$model\",\"max_tokens\":20,\"messages\":[{\"role\":\"user\",\"content\":\"Reply with exactly: OK\"}]}")
CURL_EC=$?
set -e
if [[ $CURL_EC -ne 0 ]]; then
echo "HTTP_CODE=curl_error_$CURL_EC"
echo "RESPONSE=curl failed"
echo "STATUS=fail"
echo ""
return
fi
HTTP_CODE="$(echo "$RAW" | tail -n1)"
BODY="$(echo "$RAW" | sed '$d')"
echo "HTTP_CODE=$HTTP_CODE"
if echo "$BODY" | grep -q '"text"' && echo "$BODY" | grep -qiw 'OK'; then
echo "RESPONSE=OK"
echo "STATUS=pass"
else
ERROR_MSG="$(echo "$BODY" | python3 -c "import sys,json;d=json.load(sys.stdin);print(d.get('error',{}).get('message',d.get('error','unknown')))" 2>/dev/null || echo "$BODY" | head -c 200)"
echo "RESPONSE=$ERROR_MSG"
if [[ "$HTTP_CODE" == "200" ]]; then
echo "STATUS=pass"
else
echo "STATUS=fail"
fi
fi
echo ""
}
run_deepseek() {
verify_provider "deepseek" \
"https://api.deepseek.com/anthropic/v1/messages" \
"DEEPSEEK_API_KEY" \
"deepseek-v4-pro"
}
run_glm() {
verify_provider "glm" \
"https://api.z.ai/api/anthropic/v1/messages" \
"ZAI_API_KEY" \
"glm-5.1"
}
run_qwen() {
verify_provider "qwen" \
"https://dashscope-intl.aliyuncs.com/apps/anthropic/v1/messages" \
"DASHSCOPE_API_KEY" \
"qwen3.6-plus"
}
run_minimax() {
verify_provider "minimax" \
"https://api.minimax.io/anthropic/v1/messages" \
"MINIMAX_API_KEY" \
"minimax-m2.7"
}
run_openrouter() {
local model="qwen/qwen3.6-plus"
local alias_file="${XDG_CONFIG_HOME:-$HOME/.config}/claude/provider-aliases.json"
if [[ -f "$alias_file" ]]; then
local alias_model
alias_model="$(python3 -c "import json;d=json.load(open('$alias_file'));print(d.get('openrouter',{}).get('model',''))" 2>/dev/null || true)"
[[ -n "$alias_model" ]] && model="$alias_model"
fi
verify_provider "openrouter" \
"https://openrouter.ai/api/v1/messages" \
"OPENROUTER_API_KEY" \
"$model"
}
case "$TARGET_LOWER" in
deepseek|ds) run_deepseek ;;
glm) run_glm ;;
qwen) run_qwen ;;
minimax) run_minimax ;;
openrouter) run_openrouter ;;
all)
run_deepseek
run_glm
run_qwen
run_minimax
run_openrouter
;;
*)
echo "Usage: verify-providers.sh [deepseek|glm|qwen|minimax|openrouter|all]"
exit 1
;;
esac
exit 0
#!/bin/bash
set -euo pipefail
# write-alias.sh — Safely write provider configuration to ~/.zshrc
# Usage: write-alias.sh <action> [args...]
# Actions: init, set-key, set-alias, remove-key, remove-alias
ZSHRC="$HOME/.zshrc"
SECTION_START="# ========== Claude Code Provider Aliases =========="
SECTION_COMMENT="# Managed by brewtools:provider-switch — do not edit manually"
SECTION_END="# ========== End Claude Code Provider Aliases =========="
ACTION="${1:-}"
[[ -z "$ACTION" ]] && { echo "FAILED $ACTION — no action specified"; exit 1; }
shift
# Backup before any modification
backup_zshrc() {
if [[ -f "$ZSHRC" ]]; then
cp "$ZSHRC" "$ZSHRC.bak"
fi
}
# Check if section exists
section_exists() {
[[ -f "$ZSHRC" ]] && grep -q "$SECTION_START" "$ZSHRC" 2>/dev/null
}
case "$ACTION" in
init)
if section_exists; then
echo "OK init"
exit 0
fi
backup_zshrc
# Create file if missing
[[ -f "$ZSHRC" ]] || touch "$ZSHRC"
# Append section at end
printf '\n%s\n%s\n%s\n' "$SECTION_START" "$SECTION_COMMENT" "$SECTION_END" >> "$ZSHRC"
echo "OK init"
;;
set-key)
VAR="${1:-}"
VALUE="${2:-}"
[[ -z "$VAR" ]] && { echo "FAILED set-key — no variable name"; exit 1; }
[[ -z "$VALUE" ]] && { echo "FAILED set-key — no value"; exit 1; }
if ! section_exists; then
echo "FAILED set-key — section not found, run init first"
exit 1
fi
backup_zshrc
EXPORT_LINE="export ${VAR}=\"${VALUE}\""
# Check if key already exists in section
if grep -q "^export ${VAR}=" "$ZSHRC" 2>/dev/null; then
# Remove old key line, then re-add
sed -i '' "/^export ${VAR}=/d" "$ZSHRC"
fi
# Add before end marker using awk (safer than sed for values with special chars)
TMPFILE=$(mktemp)
awk -v line="$EXPORT_LINE" -v marker="$SECTION_END" '{
if ($0 == marker) print line;
print;
}' "$ZSHRC" > "$TMPFILE" && mv "$TMPFILE" "$ZSHRC"
echo "OK set-key"
;;
set-alias)
NAME="${1:-}"
BODY="${2:-}"
[[ -z "$NAME" ]] && { echo "FAILED set-alias — no alias name"; exit 1; }
[[ -z "$BODY" ]] && { echo "FAILED set-alias — no alias body"; exit 1; }
if ! section_exists; then
echo "FAILED set-alias — section not found, run init first"
exit 1
fi
backup_zshrc
# Build alias line — write via temp file to avoid sed escaping issues
ALIAS_LINE="alias ${NAME}='${BODY}'"
# Check if alias already exists
if grep -q "^alias ${NAME}=" "$ZSHRC" 2>/dev/null; then
# Remove old alias line, then add new one before end marker
sed -i '' "/^alias ${NAME}=/d" "$ZSHRC"
fi
# Add before end marker using awk (safer than sed for complex strings)
TMPFILE=$(mktemp)
awk -v line="$ALIAS_LINE" -v marker="$SECTION_END" '{
if ($0 == marker) print line;
print;
}' "$ZSHRC" > "$TMPFILE" && mv "$TMPFILE" "$ZSHRC"
echo "OK set-alias"
;;
remove-key)
VAR="${1:-}"
[[ -z "$VAR" ]] && { echo "FAILED remove-key — no variable name"; exit 1; }
if ! section_exists; then
echo "OK remove-key"
exit 0
fi
backup_zshrc
# Remove matching export line
sed -i '' "/^export ${VAR}=/d" "$ZSHRC"
echo "OK remove-key"
;;
remove-alias)
NAME="${1:-}"
[[ -z "$NAME" ]] && { echo "FAILED remove-alias — no alias name"; exit 1; }
if ! section_exists; then
echo "OK remove-alias"
exit 0
fi
backup_zshrc
# Remove matching alias line
sed -i '' "/^alias ${NAME}=/d" "$ZSHRC"
echo "OK remove-alias"
;;
*)
echo "FAILED $ACTION — unknown action"
exit 1
;;
esac
exit 0