Oliver Drobnik

Codex Account Switcher

AI 智慧體v1.4.3
作者:Oliver Drobnik更新於 2026-05-11共 12 個版本 · 最新版本釋出於 2026-04-07codex-account-switcher@clawhub_odrobnik/codex-account-switcher
任務自動化工具呼叫#Sync

據 AlphaMoat 統計,截至 2026-09,Codex Account Switcher 累計下載 4,568 次、獲 3 個星標,在全部 5,078 個 AI 技能中排名第 2,096 位,在「AI 智慧體」分類(969 個)中排名第 392 位。

累計安裝
164
累計下載
4568
星標
3
全站排名
#2,096
全站前 42% · 「AI 智慧體」前 41%
平台累計安裝累計下載星標評論
ClawHub ↗14143173-
SkillHub ↗16445683—

各平台的計數口徑不同,統計時間不一致。

這個技能是做什麼的

該技能會讀取、儲存或替換本地認證檔案,並可按配額餘量比較帳戶;向 OpenClaw 傳播 token 需要顯式選擇同步。技能卡提示憑證會被複製並寫入本地快照,同步還可能把 token 傳入 agent 認證檔案;帳戶名路徑校驗與靜默儲存行為也需要關注。僅在可信裝置上使用,限制憑證目錄權限;同步前先預覽寫入並限制目標 agent,隨後檢查寫入結果。 需要 Python 與已設定 Codex CLI。自動配額探測會暫時替換目前的認證檔案並執行 Codex,並非唯讀,也可能改用快取配額;路徑驗證修正前僅用可信且簡單的帳號名稱,執行前核准探測/切換的影響。

資料釋出於 2026-10-27

可以用來做什麼

  • 儲存並列出本地帳戶快照
  • 切換當前使用的帳戶
  • 比較帳戶配額餘量或預覽 OpenClaw 同步範圍

什麼時候用

  • 確實需要在同一可信裝置管理多個 Codex 身份時
  • 執行前已審查本地認證檔案操作,同步時已預覽變更並限定目標 agent 時

示例提示詞

以下是根據技能文件生成的示例,不代表實際執行結果。

先唯讀列出將被讀取或寫入的認證檔案和同步目標;不要切換帳戶或同步 token,直到我確認。

月度資料趨勢

累計下載4568
2875378446932026-03 · 累計下載 30002026-05 · 累計下載 35732026-06 · 累計下載 37212026-07 · 累計下載 40322026-08 · 累計下載 41762026-09 · 累計下載 456826-0326-09
星標3
2332026-03 · 星標 22026-05 · 星標 32026-06 · 星標 32026-07 · 星標 32026-08 · 星標 32026-09 · 星標 326-0326-09

2026-09 起統計方法調整:同名技能按作者分別統計,並覆蓋全部技能。圖中虛線為調整前的月份,與之後的資料不直接比較,也不計算跨越調整的增長。

月份累計下載環比星標
2026-094568—3
2026-084176+3.6%3
2026-074032+8.4%3
2026-063721+4.1%3
2026-053573—3
2026-033000—2

SKILL.md 原文

以下是作者釋出的原始檔案,按純文字顯示,本站未做修改或稽核;其中的連結不可點選,命令請核實後再執行。抓取於 2026-10-23。

6.6 KB · ClawHub v1.4.3
---
name: codex-account-switcher
version: 1.4.3
homepage: https://github.com/odrobnik/codex-account-switcher-skill
description: >
  Manage multiple OpenAI Codex accounts by capturing current login tokens,
  switching between saved accounts, and auto-selecting the best one based on
  quota budget scoring. Can also explicitly sync saved Codex tokens into
  OpenClaw agent auth stores on this machine. Sensitive: reads and writes local
  authentication files.
展開全部(共 180 行)
summary: Save, switch, compare, and optionally sync Codex account tokens.
metadata:
  openclaw:
    emoji: "🎭"
    requires:
      bins: ["python3", "codex"]
      config:
        - "~/.codex/auth.json"
        - "~/.codex/accounts/"
        - "~/.codex/account-activity.jsonl"
        - "~/.openclaw/agents/*/agent/auth-profiles.json"
        - "~/.openclaw/agents/*/agent/auth.json"
---

# Codex Account Switcher

Manage multiple OpenAI Codex identities (e.g. personal, family, work) by swapping the authentication token file. Includes smart auto-selection based on quota budget scoring.

⚠️ **Sensitive files touched:**
- `~/.codex/auth.json`
- `~/.codex/accounts/*.json`
- `~/.codex/account-activity.jsonl`
- `~/.openclaw/agents/*/agent/auth-profiles.json`
- `~/.openclaw/agents/*/agent/auth.json`

These paths are also declared in `metadata.openclaw.requires.config` so the registry/security scan can see them in structured metadata.

⚠️ **Security model:**
- `add`, `save`, `use`, and `auto` only manage local Codex snapshots by default.
- OpenClaw token propagation is now **explicit** via `sync` or `--sync`.
- Use `--agent <name>` to limit writes to specific OpenClaw agents.
- Use `sync --dry-run` to inspect planned writes before changing auth files.

## Usage

### List Accounts
```bash
python3 {baseDir}/scripts/codex-accounts.py list
python3 {baseDir}/scripts/codex-accounts.py list --verbose
python3 {baseDir}/scripts/codex-accounts.py list --json
```

### Add an Account
Interactive wizard — starts a fresh browser login (`codex logout && codex login`) so you explicitly choose the identity to capture. Press **Enter** to accept the default name (local-part of the email).

```bash
python3 {baseDir}/scripts/codex-accounts.py add
```

### Switch Account
Instantly swap the active login. Does **not** sync to OpenClaw unless you ask for it.

```bash
python3 {baseDir}/scripts/codex-accounts.py use oliver
python3 {baseDir}/scripts/codex-accounts.py use oliver --sync
python3 {baseDir}/scripts/codex-accounts.py use oliver --sync --agent main
```

### Auto-Switch to Best Quota
Probes each account for current quota, scores them, and switches to the best one.
Does **not** sync to OpenClaw unless you ask for it.

```bash
python3 {baseDir}/scripts/codex-accounts.py auto
python3 {baseDir}/scripts/codex-accounts.py auto --json
python3 {baseDir}/scripts/codex-accounts.py auto --sync --agent main
```

Example output:
```
Account         7d    5h   Score      7d Resets      5h Resets
──────────── ───── ───── ─────── ────────────── ──────────────
oliver         60%    1%   +12.0   Apr 03 08:08      in 4h 40m ←
elise          62%   75%   +25.3   Apr 03 10:15      in 2h 01m
sylvia         MAX    0%   +51.8   Apr 03 07:51      in 5h 00m
```

### Sync Saved Profiles to OpenClaw
Explicitly push saved account tokens to OpenClaw.

```bash
python3 {baseDir}/scripts/codex-accounts.py sync
python3 {baseDir}/scripts/codex-accounts.py sync oliver sylvia
python3 {baseDir}/scripts/codex-accounts.py sync --agent main
python3 {baseDir}/scripts/codex-accounts.py sync --agent main --dry-run
```

## Auto Mode — How It Works

### 1. Quota Probing

For each saved account, `auto` temporarily switches `~/.codex/auth.json` and runs a lightweight `codex exec --skip-git-repo-check "reply OK"` probe.

It then:
- prefers the exact session file from that probe if it contains valid `rate_limits`
- falls back to the most recent session file with valid `rate_limits` (same approach as `codex-quota`)
- falls back again to the account's cached quota file if no fresh session data is available

This keeps probing simple and robust while still using Codex's session logs as the source of truth for primary/5h and secondary/7d windows.

### 2. Budget-Based Scoring

The ideal usage pace is 100% spread evenly over 7 days. At any point in the week, the **budget** is where usage *should* be:

```
budget = (elapsed_hours / 168) × 100%
```

The **score** measures how far ahead or behind budget an account is:

```
score = (actual_weekly% - budget%) + daily_penalty
```

- **Negative score** = under budget (good — has headroom)
- **Positive score** = over budget (burning too fast)
- **Lowest score wins**

### 3. 5-Hour Penalty

The 5h window can block you even with weekly headroom. Penalties prevent picking an account that's about to hit the wall:

| 5h Usage | Penalty | Reason |
|----------|---------|--------|
| < 75% | 0 | Fine |
| 75–89% | +10 | Getting warm |
| 90–99% | +50 | About to be blocked |
| 100% | +200 | Blocked right now |

### 4. Example

Three accounts, 5 days into the weekly window:

| Account | Weekly | Budget | Δ | 5h | Penalty | Score |
|---------|--------|--------|---|-----|---------|-------|
| Oliver | 60% | 71% | -11 | 1% | 0 | **-11** ← best |
| Elise | 62% | 69% | -7 | 75% | +10 | **+3** |
| Sylvia | 100% | 71% | +29 | 0% | 0 | **+29** |

Oliver wins: most headroom relative to pace, and 5h is clear.

## OpenClaw Integration

### Token Sync

The `sync` command, or `--sync` on selected commands, syncs saved account tokens to OpenClaw agents' `auth-profiles.json`:

- Profile key format: `openai-codex:[email protected]` (email extracted from JWT)
- Old name-based keys (e.g. `openai-codex:oliver`) are migrated automatically
- Each profile includes: `type`, `provider`, `access`, `refresh`, `expires`, `accountId`, `email`
- Also updates each selected agent's `auth.json` when it already has an `openai-codex` entry
- `--agent <name>` narrows the write scope to specific agents
- `sync --dry-run` shows what would be changed without writing files

This allows OpenClaw to use Codex accounts internally without requiring every local agent to be updated automatically.

### Account Activity Log

Every account switch is logged to `~/.codex/account-activity.jsonl`:

```json
{"timestamp": 1774878000, "account": "oliver", "user_id": "user-UtCmyIUOTxc4D1OHV1e5Ibew"}
```

This enables the [quota-dashboard](../quota-dashboard/) skill to attribute Codex Desktop session rate_limit data to the correct account, since session files don't record which user created them.

## Setup

See [SETUP.md](SETUP.md) for prerequisites and setup instructions.

「AI 智慧體」分類下的熱門技能

Oliver Drobnik 的其他技能

資料月份:2026-09 · 下載/星標/安裝數聚合自公開技能註冊庫(ClawHub、SkillHub),按月更新。口徑說明見資料方法。