AI Playbook中文

Coding agents

Quota-aware model routing across several AI coding providers

Verification

Tested on
2026-11-24
What was tested
Scope not stated
Evidence level
Dated run records or re-runnable tests
Status
Published
Version
0.2.0
Updated
2026-11-29
Source commit
a8fb8db149
Tools
an agent orchestrator or coordinator (or you, by hand), 2-3 coding agents/plans, e.g. Kimi Code, GLM Coding Plan, Qwen Code, DeepSeek API, Claude Code, Codex CLI, Grok
Models
any 2-3 providers (example setup: Claude + OpenAI Codex + Grok)
Audience
developers
Availability in mainland China
Partly available
Alternatives for mainland China
Kimi Code plan, GLM Coding Plan, Qwen Code, DeepSeek API, local models via Ollama (see local-ai recipes)

Framing: a solo developer's workflow (2026-11). Claude / Codex / Grok are one example combination; Kimi / GLM / Qwen / DeepSeek work the same way. Claude: Anthropic has not supported mainland China, Hong Kong or Macau since 2026-11-12, including use while there (checked 2026-11-23). Codex: mainland China is not on OpenAI's supported-countries list (2026-11-23, carried over from the PR #14 draft). Grok: check xAI's terms for your region.

Situation

This is step 3 (pick a pattern) of the method applied to routing: choose by role plus quota fallback, not by "which model is smartest".

Steps

  1. List the quota signals you can actually see (for Kimi / GLM plans, read each console's window rules): Claude Code /usage (5-hour and weekly windows, shared with claude.ai); Codex /status or the usage dashboard; otherwise treat errors mentioning usage limit / rate limit as "unavailable". If your orchestrator has one usage page covering several providers (we use Orca's), trust that.
  2. Rank by role. One solo developer's table (changes with quota): plan/code → Claude, then Codex only if Claude is unavailable; independent review → Codex (read-only), then a separate Claude session, then Grok; chores (research, tests, logs, docs) → Grok, then Codex, then Claude. Hard rules: writer ≠ reviewer session; payments/IAP/permission changes are not reviewed by your least-trusted model.
  3. Save quota: one workstream at a time; the coordinator dispatches and accepts but does not read code (coordinator-agent-specs); use completion notifications, not polling (hooks-not-polling-notifications).
  4. Put the table into the coordinator's instructions (template above).
  5. Log every switch with time zones for both the event and the expected reset; switch back when quota returns.
  6. Reminders and scheduled wake-ups use the same time zone as the reset time; record both local time and UTC.

Templates

AGENTS.md snippet and status line are in the code blocks above. In pipeline.yaml, routing lives in each model step's fallback; steps that must not degrade say fallback.models: [] and "wait for quota". Re-estimate tokens after any fallback (ROI input table).

Cost (order of magnitude, estimate)

Failure cases and guards

The first four items are dated records; the rest are guards.

China alternatives

Safety notes

Test notes

Verification

来源 / Sources

  • Claude Code commands (/usage): https://code.claude.com/docs/en/commands
  • Claude plan limits: https://support.claude.com/en/articles/11145838-use-claude-code-with-your-pro-max-or-ultra-plan
  • Codex developer commands (/status): https://learn.chatgpt.com/docs/developer-commands.md
  • Anthropic Supported Regions Policy (checked 2026-11-23): https://www.anthropic.com/legal/supported-regions
  • Domestic coding plans comparison: https://codingplan.org/blogs/glm-vs-kimi

Source links

Export to your agent

Path: quota-based-model-routing/SKILL.md

Preview
---
name: quota-based-model-routing
description: "Quota-aware model routing across several AI coding providers. Use when the user asks for help with this task."
metadata:
  version: "0.2.0"
  status: "published"
  source-commit: "5f7272be13826bec473d6f2e073c82a5a620f1d2"
---

# Quota-aware model routing across several AI coding providers

- Version: 0.2.0
- Status: published
- Tested on: 2026-11-24
- Evidence level: field-use-logged
- Source commit: 5f7272be13826bec473d6f2e073c82a5a620f1d2

> Reference playbook: follow it only when the user asks for this task, and ask a human before running commands or irreversible actions.

## English

> **Framing: a solo developer's workflow (2026-11).** Claude / Codex / Grok are one example combination; Kimi / GLM / Qwen / DeepSeek work the same way.
> Claude: Anthropic has not supported mainland China, Hong Kong or Macau since 2026-11-12, including use while there (checked 2026-11-23). Codex: mainland China is not on OpenAI's supported-countries list (2026-11-23, carried over from the PR #14 draft). Grok: check xAI's terms for your region.

### Situation
- **Audience:** people paying for two or three AI coding services who hit "5-hour limit reached" mid-task and watch the whole pipeline stall.
- **When to use:** a coordinator (you or an agent) dispatches work to several agents.
- **When not to use:** you have only one provider — nothing to route to; wait.

This is step 3 (pick a pattern) of the method applied to routing: choose by role plus quota fallback, not by "which model is smartest".

### Steps
1. **List the quota signals you can actually see** (for Kimi / GLM plans, read each console's window rules): Claude Code `/usage` (5-hour and weekly windows, shared with claude.ai); Codex `/status` or the usage dashboard; otherwise treat errors mentioning `usage limit` / `rate limit` as "unavailable". If your orchestrator has one usage page covering several providers (we use Orca's), trust that.
2. **Rank by role.** One solo developer's table (changes with quota): plan/code → Claude, then Codex only if Claude is unavailable; independent review → Codex (read-only), then a *separate* Claude session, then Grok; chores (research, tests, logs, docs) → Grok, then Codex, then Claude. Hard rules: writer ≠ reviewer session; payments/IAP/permission changes are not reviewed by your least-trusted model.
3. **Save quota:** one workstream at a time; the coordinator dispatches and accepts but does not read code (`coordinator-agent-specs`); use completion notifications, not polling (`hooks-not-polling-notifications`).
4. **Put the table into the coordinator's instructions** (template above).
5. **Log every switch** with time zones for both the event and the expected reset; switch back when quota returns.
6. **Reminders and scheduled wake-ups use the same time zone** as the reset time; record both local time and UTC.

### Templates
AGENTS.md snippet and status line are in the code blocks above. In pipeline.yaml, routing lives in each model step's `fallback`; steps that must not degrade say `fallback.models: []` and "wait for quota". Re-estimate tokens after any fallback (ROI input table).

### Cost (order of magnitude, estimate)
- Routing itself is nearly free; what it saves is **stalled time**. Quota windows are measured in hours; fallback turns "wait hours" into "swap a role".
- Different models tokenize and write differently: re-measure, don't reuse A's usage numbers for B.

### Failure cases and guards
The first four items are dated records; the rest are guards.
- **Date and time zone misread (nearly 24 hours late; caught in time, no actual delay):** on 2026-11-23 a waiting worker reported "6:15 AM reset" with no date or zone; the machine runs PST and the owner is on Beijing time (UTC+8). The coordinator read it as "tomorrow morning" and set a one-shot wake-up for 2026-11-24 06:20 PST, but the Codex log's `rate_limits.primary.resets_at` converts to 2026-11-23 06:15 PST — the **same day** — so it would have fired a full 24 hours late. At 02:47 PST the same day, converting with `date -d @<resets_at>` exposed it and the reminder was deleted and recreated for 2026-11-23 06:20 PST. Lesson: trust the log's epoch for reset times, and write date plus zone when converting (`date -d @<epoch>`); one-shot reminders built as cron repeat yearly, so delete them after they run. *(Record: the coordinator's own account, the automation's delete/recreate record on the machine, and the dated quota update in the dev-workflow doc.)*
- **Reading the wrong number:** on 2026-11-23 Codex's local session log showed `credits.balance = 0`, but that was separately purchased credit; the number to read is the 5-hour window `used_percent` (about 5% that evening after the reset). Local log formats are undocumented; prefer `/status` or the official dashboard.
- **Two providers near their limits at once:** one early-morning observation on 2026-11-23 had Claude's 5-hour window ≈91% and Codex ≈100%; all workers were parked at safe points and woken together after the reset.
- **Fallback to the same session** is not a review.
- **Downgrading review to avoid waiting:** for risky changes, wait. On 2026-11-24 a second review round was deliberately postponed until Codex recovered instead of swapping reviewers.
- **Time-limited allowances treated as permanent:** write the expiry date (e.g. a trial ending on a given day) into the table.
- **Reachable ≠ permitted** in unsupported regions.

### China alternatives
- `china_availability: partial`. The method is vendor-neutral: build the same table from Kimi Code / GLM Coding Plan / Qwen Code / DeepSeek API. Their window rules differ — confirm in each console (we only link a comparison article; not tested here).
- Local models (Ollama etc.) can fill the "chores" tier (see `local-ai` recipes); not tested here.
- No circumvention advice.

### Safety notes
- The coordinator only needs usage percentages, never credentials; don't paste tokens or cookies to see quota.
- When reading local session logs, extract only the quota fields; don't paste whole logs (they may contain code or secrets) into chats or repos.

### Test notes
- 2026-11-23/24: the table and switches were used in a solo developer's multi-agent setup with dated switch entries (Codex exhausted → review reassigned; recovered → defaults restored; exhausted again early 2026-11-24 → waited).
- **The templates here are cleaned-up rewrites that were not re-run verbatim**; `/usage` and `/status` behavior follows the official docs (consulted 2026-11-23). Local versions: Claude Code 2.1.330, Codex CLI 0.171.0 (2026-11-23).

### Verification
- Make the first choice unavailable on purpose; the coordinator should route to the next and log a zone-qualified switch.
- After a week: did any quota gap stall the pipeline for more than half a day?

## 来源 / Sources

- Claude Code commands (`/usage`): https://code.claude.com/docs/en/commands
- Claude plan limits: https://support.claude.com/en/articles/11145838-use-claude-code-with-your-pro-max-or-ultra-plan
- Codex developer commands (`/status`): https://learn.chatgpt.com/docs/developer-commands.md
- Anthropic Supported Regions Policy (checked 2026-11-23): https://www.anthropic.com/legal/supported-regions
- Domestic coding plans comparison: https://codingplan.org/blogs/glm-vs-kimi

## Code and templates from the Chinese section (may contain Chinese comments or text)

**Block 1 — AGENTS.md**

```markdown
## Model routing (check quota before every dispatch)
<!-- Example providers; replace with your own (e.g. Kimi / GLM / Qwen / DeepSeek). -->

Signals:
- Claude: `/usage` (5h session + weekly). Shared with claude.ai.
- Codex: `/status` or the Codex usage dashboard; look at the used-percent of the 5h window.
- Any worker error containing "usage limit" / "rate limit" => treat that model as unavailable.

Priority (skip to the next if unavailable):
- Plan & implement: Claude -> Codex
- Independent review: Codex (read-only) -> fresh Claude session (never the implementer's) -> Grok
  - Payments / IAP / auth / permissions: NOT Grok-reviewed; wait for quota instead.
- Chores (research, tests, logs, docs): Grok -> Codex -> Claude

Rules:
- One active workstream at a time while any provider is exhausted.
- Log each switch in STATE.md, always with time zones:
  `2026-11-23 22:15 UTC+8 | codex exhausted | review -> claude-2 | resets 2026-11-24 06:15 UTC+8 (= 2026-11-23 22:15 UTC)`
- Switch back to defaults when quota returns.
```

**Block 2**

```text
[quota] <provider> exhausted at <time + TZ>; <role> moved to <provider/session>; expected reset <time + TZ>; switch back: yes/no
```