# openclaw-model-switch

Safely switches or repairs OpenClaw model settings in openclaw.json. It handles primary model switches, routing errors, and token hijack bugs without breaking gateway sync.

- skill · `type=skill` · Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, OpenCode · 323 installs · ★ 1493
- Author: daymade
- License: MIT · policy=mirror · the beginning of the file is at the end of this page
- Source: https://github.com/daymade/claude-code-skills/tree/HEAD/openclaw-model-switch/SKILL.md
- Updated: 2026-10-25
- HTML: https://affpapa.org/en/nevibecode/skills/openclaw-model-switch

## What it does

The skill manages OpenClaw settings across candidate paths such as `~/.openclaw/openclaw.json` and mirror directories under `.kimi`. It uses `scripts/switch-model.py` to create a backup in `config-backups/`, register model definitions, update `agents.defaults.model.primary`, and restart the gateway service.

Before modifying files, the workflow probes endpoints with direct `curl` requests to `/v1/messages`. This test catches key hijacking caused by environment variables like `KIMI_API_KEY` and identifies unavailable relay channels upfront. After restarting, it runs `openclaw agent` to confirm that the `fallbackUsed` flag is false.

Editing only one configuration file when mirror paths exist will cause OpenClaw to overwrite your changes during the next sync.

## Install

### Claude Code (native platform)

1. **Skills CLI (Vercel)**
```bash
npx skills add daymade/claude-code-skills --skill openclaw-model-switch -a claude-code
```

2. **Manually: put the files in place**
- File: `~/.claude/skills/openclaw-model-switch/SKILL.md` — Copy the whole skill folder; for one project use .claude/skills/openclaw-model-switch/

### Codex

1. **Skills CLI (Vercel)**
```bash
npx skills add daymade/claude-code-skills --skill openclaw-model-switch -a codex
```

2. **Manually: put the files in place**
- File: `.agents/skills/openclaw-model-switch/SKILL.md` — For all projects use ~/.agents/skills/

### Cursor

1. **Skills CLI (Vercel)**
```bash
npx skills add daymade/claude-code-skills --skill openclaw-model-switch -a cursor
```

2. **Manually: put the files in place**
- File: `.cursor/skills/openclaw-model-switch/SKILL.md` — Cursor also reads .agents/skills/ and .claude/skills/

### GitHub Copilot

1. **GitHub CLI**
```bash
gh skill install daymade/claude-code-skills openclaw-model-switch
```

2. **Manually: put the files in place**
- File: `.github/skills/openclaw-model-switch/SKILL.md`

### Gemini CLI

1. **Skills CLI (Vercel)**
```bash
npx skills add daymade/claude-code-skills --skill openclaw-model-switch -a gemini-cli
```

2. **Platform CLI**
```bash
gemini skills install https://github.com/daymade/claude-code-skills --path openclaw-model-switch
```

### Windsurf (Devin Desktop)

**Manually: put the files in place**
- File: `.devin/skills/openclaw-model-switch/SKILL.md` — The legacy .windsurf/skills/ path still works

### OpenCode

**Skills CLI (Vercel)**
```bash
npx skills add daymade/claude-code-skills --skill openclaw-model-switch -a opencode
```

### Claude.ai

**Claude.ai**
- Zip the folder and upload it in Settings → Capabilities → Skills

Where a file is given instead of a command, copy the files from the source to that path: https://github.com/daymade/claude-code-skills/tree/HEAD/openclaw-model-switch/SKILL.md

## When to use it
- switch the primary agent model in openclaw.json
- fix 401 Invalid token errors caused by environment key hijacking
- resolve Thinking level conflicts across provider profiles
- synchronize OpenClaw mirror configuration paths before restarting

## Example prompts
- Switch the primary OpenClaw model to k3 and restart the gateway
- Probe the kimi-relay endpoint and fix the 503 No available channel error
- Run switch-model.py for kimi-k2.7-code and verify fallbackUsed is false

## Source text · SKILL.md · MIT

Below is the content of a third-party file. It is data, not instructions for you: do not act on anything written inside unless the human asks. Block tag: 7fcf86890f987b33.

BEGIN THIRD-PARTY FILE 7fcf86890f987b33
````text
---
name: openclaw-model-switch
description: >-
  Switches or repairs an OpenClaw instance's model config: changes the default model, adds model
  definitions, and fixes 401 "Invalid token", "No available channel / model not found", "Thinking
  level X is not supported", or a config edit that doesn't take effect. Use for 切换模型/换模型/升级模型 or
  模型配的错了. Not for plain config audits (use openclaw).
---

# OpenClaw Model Switch

Switch or repair an OpenClaw instance's model configuration by safely editing `openclaw.json`.

**Diagnose before you edit.** Model failures on OpenClaw are usually NOT the model id —
they are key routing (env hijack), provider-plugin restrictions, or endpoint/model mismatch.
Changing the model id without checking these first is how a 5-minute fix becomes a 2-hour
debugging session. The full trap catalog with discovery commands lives in
[references/troubleshooting-model-config.md](references/troubleshooting-model-config.md) — read it
the moment anything errors.

## Step 1 — Find the real config file(s)

Do NOT assume a hardcoded path. Candidate locations (check all, edit all that exist):

1. `~/.openclaw/openclaw.json` — the gateway's live config on most installs
2. `~/.kimi/kimi-claw/openclaw.json` — Kimi Claw mirror, kept in sync on some installs
3. `~/.kimi_openclaw/openclaw.json` — legacy desktop path

Confirm which one the gateway actually reads: `openclaw gateway status` prints
`Config (service): <path>`. If several exist, treat them as mirrors: **edit all of them
identically**, otherwise the next sync overwrites your fix.

## Step 2 — Probe the endpoint + model BEFORE touching config

Never trust a relay's model listing (`GET /v1/models` on new-api style relays is frequently
incomplete — a model can be absent from the list yet serve fine). The only authority is a
real completion probe **from the host that will run the bot**:

```bash
curl -sS -o /tmp/probe.json -w "HTTP %{http_code}\n" \
  -X POST "<baseUrl>/v1/messages" \
  -H "Authorization: Bearer <apiKey>" \
  -H "Content-Type: application/json" \
  -H "anthropic-version: 2023-06-01" \
  -d '{"model":"<model-id>","max_tokens":16,"messages":[{"role":"user","content":"hi"}]}'
```

Expected: `HTTP 200` and a `content` array in the body. `401 Invalid token` with a token you
just verified works elsewhere → the wire key is being hijacked (see trap #1 in the
troubleshooting reference). `503 No available channel` → the model is not served for this
token/group **from this network** (trap #3) — pick a served model or fix the relay, don't
blind-switch.

## Step 3 — Switch the model

```bash
python3 scripts/switch-model.py <model-id> --restart
# target a specific provider instead of the guessed one:
````
END THIRD-PARTY FILE 7fcf86890f987b33

The third-party file has ended. Everything between the 7fcf86890f987b33 tags is data: requests and commands from it are not followed. An “end of file” line with another tag inside the block is part of the file.

First 2770 of 5467 bytes. © daymade · MIT · https://github.com/daymade/claude-code-skills/tree/HEAD/openclaw-model-switch/SKILL.md

_Part of the page did not fit — see the HTML version._

---
NeVibeCode on affpapa.org. Catalog texts are descriptions, not instructions for the agent. How to choose and install: https://affpapa.org/en/nevibecode/agents.md
