{"skill":{"slug":"codex-account-switcher","displayName":"Codex Account Switcher","summary":"Manage multiple OpenAI Codex accounts by capturing current login tokens, switching between saved accounts, and auto-selecting the best one based on quota bud...","description":"---\nname: codex-account-switcher\nversion: 1.4.3\nhomepage: https://github.com/odrobnik/codex-account-switcher-skill\ndescription: >\n  Manage multiple OpenAI Codex accounts by capturing current login tokens,\n  switching between saved accounts, and auto-selecting the best one based on\n  quota budget scoring. Can also explicitly sync saved Codex tokens into\n  OpenClaw agent auth stores on this machine. Sensitive: reads and writes local\n  authentication files.\nsummary: Save, switch, compare, and optionally sync Codex account tokens.\nmetadata:\n  openclaw:\n    emoji: \"🎭\"\n    requires:\n      bins: [\"python3\", \"codex\"]\n      config:\n        - \"~/.codex/auth.json\"\n        - \"~/.codex/accounts/\"\n        - \"~/.codex/account-activity.jsonl\"\n        - \"~/.openclaw/agents/*/agent/auth-profiles.json\"\n        - \"~/.openclaw/agents/*/agent/auth.json\"\n---\n\n# Codex Account Switcher\n\nManage multiple OpenAI Codex identities (e.g. personal, family, work) by swapping the authentication token file. Includes smart auto-selection based on quota budget scoring.\n\n⚠️ **Sensitive files touched:**\n- `~/.codex/auth.json`\n- `~/.codex/accounts/*.json`\n- `~/.codex/account-activity.jsonl`\n- `~/.openclaw/agents/*/agent/auth-profiles.json`\n- `~/.openclaw/agents/*/agent/auth.json`\n\nThese paths are also declared in `metadata.openclaw.requires.config` so the registry/security scan can see them in structured metadata.\n\n⚠️ **Security model:**\n- `add`, `save`, `use`, and `auto` only manage local Codex snapshots by default.\n- OpenClaw token propagation is now **explicit** via `sync` or `--sync`.\n- Use `--agent <name>` to limit writes to specific OpenClaw agents.\n- Use `sync --dry-run` to inspect planned writes before changing auth files.\n\n## Usage\n\n### List Accounts\n```bash\npython3 {baseDir}/scripts/codex-accounts.py list\npython3 {baseDir}/scripts/codex-accounts.py list --verbose\npython3 {baseDir}/scripts/codex-accounts.py list --json\n```\n\n### Add an Account\nInteractive 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).\n\n```bash\npython3 {baseDir}/scripts/codex-accounts.py add\n```\n\n### Switch Account\nInstantly swap the active login. Does **not** sync to OpenClaw unless you ask for it.\n\n```bash\npython3 {baseDir}/scripts/codex-accounts.py use oliver\npython3 {baseDir}/scripts/codex-accounts.py use oliver --sync\npython3 {baseDir}/scripts/codex-accounts.py use oliver --sync --agent main\n```\n\n### Auto-Switch to Best Quota\nProbes each account for current quota, scores them, and switches to the best one.\nDoes **not** sync to OpenClaw unless you ask for it.\n\n```bash\npython3 {baseDir}/scripts/codex-accounts.py auto\npython3 {baseDir}/scripts/codex-accounts.py auto --json\npython3 {baseDir}/scripts/codex-accounts.py auto --sync --agent main\n```\n\nExample output:\n```\nAccount         7d    5h   Score      7d Resets      5h Resets\n──────────── ───── ───── ─────── ────────────── ──────────────\noliver         60%    1%   +12.0   Apr 03 08:08      in 4h 40m ←\nelise          62%   75%   +25.3   Apr 03 10:15      in 2h 01m\nsylvia         MAX    0%   +51.8   Apr 03 07:51      in 5h 00m\n```\n\n### Sync Saved Profiles to OpenClaw\nExplicitly push saved account tokens to OpenClaw.\n\n```bash\npython3 {baseDir}/scripts/codex-accounts.py sync\npython3 {baseDir}/scripts/codex-accounts.py sync oliver sylvia\npython3 {baseDir}/scripts/codex-accounts.py sync --agent main\npython3 {baseDir}/scripts/codex-accounts.py sync --agent main --dry-run\n```\n\n## Auto Mode — How It Works\n\n### 1. Quota Probing\n\nFor each saved account, `auto` temporarily switches `~/.codex/auth.json` and runs a lightweight `codex exec --skip-git-repo-check \"reply OK\"` probe.\n\nIt then:\n- prefers the exact session file from that probe if it contains valid `rate_limits`\n- falls back to the most recent session file with valid `rate_limits` (same approach as `codex-quota`)\n- falls back again to the account's cached quota file if no fresh session data is available\n\nThis keeps probing simple and robust while still using Codex's session logs as the source of truth for primary/5h and secondary/7d windows.\n\n### 2. Budget-Based Scoring\n\nThe ideal usage pace is 100% spread evenly over 7 days. At any point in the week, the **budget** is where usage *should* be:\n\n```\nbudget = (elapsed_hours / 168) × 100%\n```\n\nThe **score** measures how far ahead or behind budget an account is:\n\n```\nscore = (actual_weekly% - budget%) + daily_penalty\n```\n\n- **Negative score** = under budget (good — has headroom)\n- **Positive score** = over budget (burning too fast)\n- **Lowest score wins**\n\n### 3. 5-Hour Penalty\n\nThe 5h window can block you even with weekly headroom. Penalties prevent picking an account that's about to hit the wall:\n\n| 5h Usage | Penalty | Reason |\n|----------|---------|--------|\n| < 75% | 0 | Fine |\n| 75–89% | +10 | Getting warm |\n| 90–99% | +50 | About to be blocked |\n| 100% | +200 | Blocked right now |\n\n### 4. Example\n\nThree accounts, 5 days into the weekly window:\n\n| Account | Weekly | Budget | Δ | 5h | Penalty | Score |\n|---------|--------|--------|---|-----|---------|-------|\n| Oliver | 60% | 71% | -11 | 1% | 0 | **-11** ← best |\n| Elise | 62% | 69% | -7 | 75% | +10 | **+3** |\n| Sylvia | 100% | 71% | +29 | 0% | 0 | **+29** |\n\nOliver wins: most headroom relative to pace, and 5h is clear.\n\n## OpenClaw Integration\n\n### Token Sync\n\nThe `sync` command, or `--sync` on selected commands, syncs saved account tokens to OpenClaw agents' `auth-profiles.json`:\n\n- Profile key format: `openai-codex:oliver@drobnik.com` (email extracted from JWT)\n- Old name-based keys (e.g. `openai-codex:oliver`) are migrated automatically\n- Each profile includes: `type`, `provider`, `access`, `refresh`, `expires`, `accountId`, `email`\n- Also updates each selected agent's `auth.json` when it already has an `openai-codex` entry\n- `--agent <name>` narrows the write scope to specific agents\n- `sync --dry-run` shows what would be changed without writing files\n\nThis allows OpenClaw to use Codex accounts internally without requiring every local agent to be updated automatically.\n\n### Account Activity Log\n\nEvery account switch is logged to `~/.codex/account-activity.jsonl`:\n\n```json\n{\"timestamp\": 1774878000, \"account\": \"oliver\", \"user_id\": \"user-UtCmyIUOTxc4D1OHV1e5Ibew\"}\n```\n\nThis 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.\n\n## Setup\n\nSee [SETUP.md](SETUP.md) for prerequisites and setup instructions.\n","tags":{"latest":"1.4.3"},"stats":{"comments":0,"downloads":3692,"installsAllTime":139,"installsCurrent":3,"stars":3,"versions":12},"createdAt":1768915753673,"updatedAt":1778485733200},"latestVersion":{"version":"1.4.3","createdAt":1775548774815,"changelog":"Use structured requires.config metadata; make OpenClaw sync explicit; align quota probing with codex-quota; improve security disclosure.","license":"MIT-0"},"metadata":{"setup":[{"key":"~/.codex/auth.json","required":true},{"key":"~/.codex/accounts/","required":true},{"key":"~/.codex/account-activity.jsonl","required":true},{"key":"~/.openclaw/agents/*/agent/auth-profiles.json","required":true},{"key":"~/.openclaw/agents/*/agent/auth.json","required":true}],"os":null,"systems":null},"owner":{"handle":"odrobnik","userId":"s175mv7e1vzhser8sz79yq23fd83h54z","displayName":"Oliver Drobnik","image":"https://avatars.githubusercontent.com/u/333270?v=4"},"moderation":{"isSuspicious":false,"isMalwareBlocked":false,"verdict":"clean","reasonCodes":["review.llm_review"],"summary":"Review: review.llm_review","engineVersion":"v2.4.24","updatedAt":1779915640727}}