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
累计下载
4,568
星标
3
全站排名
#2,096
全站前 42% · 「AI 智能体」前 41%
平台累计安装累计下载星标评论
ClawHub ↗1414,3173-
SkillHub ↗1644,5683—

各平台的计数口径不同,统计时间不一致。

这个技能是做什么的

该技能会读取、保存或替换本地认证文件,并可按配额余量比较账户;向 OpenClaw 传播 token 需要显式选择同步。技能卡提示凭据会被复制并写入本地快照,同步还可能把 token 传入 agent 认证文件;账户名路径校验与静默保存行为也需要关注。仅在可信设备上使用,限制凭据目录权限;同步前先预览写入并限制目标 agent,随后检查写入结果。 需要 Python 和已配置 Codex CLI。自动配额探测会暂换当前认证文件并运行 Codex,并非只读,也可能回退缓存配额;路径验证修复前仅用可信简单账号名,执行前批准探测/切换影响。

资料发布于 2026-10-27

可以用来做什么

  • 保存并列出本地账户快照
  • 切换当前使用的账户
  • 比较账户配额余量或预览 OpenClaw 同步范围

什么时候用

  • 确实需要在同一可信设备管理多个 Codex 身份时
  • 运行前已审查本地认证文件操作,同步时已预览变更并限定目标 agent 时

示例提示词

以下是根据技能文档生成的示例,不代表实际运行结果。

先只读列出将被读取或写入的认证文件和同步目标;不要切换账户或同步 token,直到我确认。

月度数据趋势

累计下载4,568
2,8753,7844,6932026-03 · 累计下载 3,0002026-05 · 累计下载 3,5732026-06 · 累计下载 3,7212026-07 · 累计下载 4,0322026-08 · 累计下载 4,1762026-09 · 累计下载 4,56826-0326-09
星标3
2332026-03 · 星标 22026-05 · 星标 32026-06 · 星标 32026-07 · 星标 32026-08 · 星标 32026-09 · 星标 326-0326-09

2026-09 起统计方法调整:同名技能按作者分别统计,并覆盖全部技能。图中虚线为调整前的月份,与之后的数据不直接比较,也不计算跨越调整的增长。

月份累计下载环比星标
2026-094,568—3
2026-084,176+3.6%3
2026-074,032+8.4%3
2026-063,721+4.1%3
2026-053,573—3
2026-033,000—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),按月更新。口径说明见数据方法。