ai-acct-autopilot 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +184 -0
- package/assets/screenshot.png +0 -0
- package/bin/ai-acct-autopilot.js +1205 -0
- package/bin/claude-acct +847 -0
- package/bin/usage-stats.js +336 -0
- package/docs/how-it-works.md +169 -0
- package/install.sh +19 -0
- package/package.json +46 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Alnim (alnimra)
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
# ai-acct-autopilot
|
|
2
|
+
|
|
3
|
+
**A terminal dashboard + autopilot for multiple Claude Code and Codex accounts.**
|
|
4
|
+
Watches usage across every account, auto-switches before you hit the wall, and
|
|
5
|
+
resumes running sessions on the fresh account — so an overnight agent run never
|
|
6
|
+
dies to a rate limit while you sleep.
|
|
7
|
+
|
|
8
|
+

|
|
9
|
+
|
|
10
|
+
## Why
|
|
11
|
+
|
|
12
|
+
If you run serious agent workloads on subscription plans (Claude Max, ChatGPT
|
|
13
|
+
Pro), you know the dance: watch the usage meter, and when it gets close to the
|
|
14
|
+
5-hour or weekly limit, scramble to re-login into another account before your
|
|
15
|
+
running sessions stall. Do it at your desk and it's annoying. Have it happen at
|
|
16
|
+
3am during an overnight run and the night is lost.
|
|
17
|
+
|
|
18
|
+
`ai-acct-autopilot` automates the whole dance:
|
|
19
|
+
|
|
20
|
+
- **One dashboard** for every Claude and Codex account: 5h / weekly / opus /
|
|
21
|
+
sonnet bars, "% left", reset countdowns, usage trends — codexbar-style, in
|
|
22
|
+
your terminal.
|
|
23
|
+
- **Auto-switch at the threshold** (default <5% left on the 5h *or* weekly
|
|
24
|
+
window): the healthiest account takes over, picked by live probed usage.
|
|
25
|
+
- **Sessions keep running.** Claude sessions follow the switch automatically;
|
|
26
|
+
Codex sessions are restarted *and resumed mid-thread* by a supervisor shim.
|
|
27
|
+
- **Tokens heal themselves.** Stale account credentials are refreshed in the
|
|
28
|
+
background (atomically, with backups) so usage bars never go blind and
|
|
29
|
+
browser re-logins become rare.
|
|
30
|
+
- **Local cost panel**: today/30-day spend estimated at API rates from your
|
|
31
|
+
local session logs, per provider, all accounts combined — see what your
|
|
32
|
+
subscriptions are actually worth.
|
|
33
|
+
|
|
34
|
+
Everything is local: your tokens never leave your machine, there is no
|
|
35
|
+
telemetry, and the only network calls are to Anthropic/OpenAI's own endpoints
|
|
36
|
+
with your own credentials.
|
|
37
|
+
|
|
38
|
+
## Requirements
|
|
39
|
+
|
|
40
|
+
- **macOS** (account storage uses the macOS keychain for Claude)
|
|
41
|
+
- **Node 18+**
|
|
42
|
+
- [Claude Code](https://code.claude.com) and/or [Codex CLI](https://developers.openai.com/codex) with subscription login(s)
|
|
43
|
+
|
|
44
|
+
## Install
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
npm install -g ai-acct-autopilot
|
|
48
|
+
# or from a clone:
|
|
49
|
+
git clone https://github.com/alnimra/ai-acct-autopilot && cd ai-acct-autopilot && ./install.sh
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
This installs two commands: `ai-acct-autopilot` (the dashboard/autopilot) and
|
|
53
|
+
`claude-acct` (the Claude account manager it builds on).
|
|
54
|
+
|
|
55
|
+
## Quick start
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
# 1. Save your current Claude account, then add more (browser login each):
|
|
59
|
+
claude-acct save you@example.com
|
|
60
|
+
claude-acct add other@example.com # overwrite-login; NEVER /logout
|
|
61
|
+
|
|
62
|
+
# 2. Add codex accounts (isolated login — your current session stays alive):
|
|
63
|
+
ai-acct-autopilot codex-save # snapshot the current codex account
|
|
64
|
+
ai-acct-autopilot codex-add other@example.com
|
|
65
|
+
|
|
66
|
+
# 3. Install the codex supervisor shim (enables auto-resume of running sessions):
|
|
67
|
+
ai-acct-autopilot codex-shim install
|
|
68
|
+
|
|
69
|
+
# 4. Run it. Leave it in a terminal.
|
|
70
|
+
ai-acct-autopilot
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
That's it. When the active account drops below 5% left, the switch happens by
|
|
74
|
+
itself, a macOS notification tells you about it, and the journal at the bottom
|
|
75
|
+
of the dashboard keeps the receipts.
|
|
76
|
+
|
|
77
|
+
## How switching works (and the Claude/Codex asymmetry)
|
|
78
|
+
|
|
79
|
+
| | Claude Code | Codex |
|
|
80
|
+
|---|---|---|
|
|
81
|
+
| Credential store | macOS keychain | `~/.codex/auth.json` |
|
|
82
|
+
| Switch mechanism | keychain swap via `claude-acct use` | `auth.json` swap |
|
|
83
|
+
| **Running sessions** | **follow the switch in ~30s** (Claude re-reads the keychain) | hold auth in memory — never re-read ([openai/codex#17041](https://github.com/openai/codex/issues/17041)) |
|
|
84
|
+
| Fix for running sessions | not needed | **supervisor shim restarts + resumes them** |
|
|
85
|
+
|
|
86
|
+
The codex supervisor shim (`codex-shim install`) wraps the codex binary. Every
|
|
87
|
+
codex launch goes through it, and when the autopilot switches accounts it:
|
|
88
|
+
|
|
89
|
+
1. captures each running session's id from the rollout file the codex process
|
|
90
|
+
holds open,
|
|
91
|
+
2. terminates the process with a restart marker,
|
|
92
|
+
3. relaunches `codex … resume <session-id>` — original flags preserved — so
|
|
93
|
+
the **same conversation continues on the new account** in the same terminal.
|
|
94
|
+
|
|
95
|
+
Sessions you quit normally exit exactly like stock codex; ctrl-C still belongs
|
|
96
|
+
to codex. Fail-open: if anything in the shim breaks, codex launches normally.
|
|
97
|
+
|
|
98
|
+
### Adding codex accounts safely
|
|
99
|
+
|
|
100
|
+
`codex login` inside a shared `~/.codex` **revokes the previous account's
|
|
101
|
+
session** — that's why `codex-add` runs the login in a throwaway isolated
|
|
102
|
+
`CODEX_HOME` and imports the result. Your existing sessions stay alive. Never
|
|
103
|
+
add accounts with a plain `codex login`.
|
|
104
|
+
|
|
105
|
+
## Commands
|
|
106
|
+
|
|
107
|
+
| Command | What it does |
|
|
108
|
+
|---|---|
|
|
109
|
+
| `ai-acct-autopilot` | run the dashboard + autopilot (60s ticks) |
|
|
110
|
+
| `ai-acct-autopilot --no-switch` | monitor only — shows the switch it WOULD make |
|
|
111
|
+
| `ai-acct-autopilot --once --plain` | single tick, plain text (logging/cron) |
|
|
112
|
+
| `ai-acct-autopilot codex-add <email>` | add a codex account via isolated login |
|
|
113
|
+
| `ai-acct-autopilot codex-use <email>` | switch codex account (+ resume running sessions) |
|
|
114
|
+
| `ai-acct-autopilot codex-list` / `codex-save` | list / snapshot codex accounts |
|
|
115
|
+
| `ai-acct-autopilot codex-shim install\|status\|uninstall` | manage the supervisor shim |
|
|
116
|
+
| `ai-acct-autopilot --test-decision` | run the decision-logic self-tests |
|
|
117
|
+
| `claude-acct add\|save\|use\|list\|usage` | manage Claude accounts (by email) |
|
|
118
|
+
|
|
119
|
+
Flags: `--interval N` (seconds, default 60) · `--threshold N` (switch when
|
|
120
|
+
<N% left, default 5) · `--cooldown N` (minutes between switches, default 10).
|
|
121
|
+
|
|
122
|
+
## Safety properties
|
|
123
|
+
|
|
124
|
+
- **Never `/logout`** — logging out revokes Claude sessions server-side;
|
|
125
|
+
account capture always uses overwrite-login.
|
|
126
|
+
- **Never switch into the unknown** — a target must pass a live usage probe
|
|
127
|
+
this tick; accounts with failed probes or revoked sessions are excluded.
|
|
128
|
+
- **Atomic credential writes** with `.bak` of the previous blob; a failed
|
|
129
|
+
refresh never deletes anything.
|
|
130
|
+
- **Cooldown + all-hot hold** — no thrashing; if every account is hot, it
|
|
131
|
+
holds, notifies once, and shows the earliest reset.
|
|
132
|
+
- **Append-only journal** (`~/.claude/accounts/switch-journal.jsonl`) — every
|
|
133
|
+
switch, snapshot, and restart with timestamps and reasons.
|
|
134
|
+
- **Local-only** — no telemetry, no third-party services, tokens never leave
|
|
135
|
+
the machine.
|
|
136
|
+
|
|
137
|
+
## How usage is read
|
|
138
|
+
|
|
139
|
+
- **Claude**: Anthropic's OAuth usage/profile endpoints, per saved account
|
|
140
|
+
token (refreshed in the background when stale).
|
|
141
|
+
- **Codex**: `chatgpt.com/backend-api/wham/usage` per account token — works
|
|
142
|
+
for benched accounts with zero sessions; the **regular** account limit is
|
|
143
|
+
used (model-family buckets like the Spark research preview are ignored).
|
|
144
|
+
Rollout session logs provide the offline fallback and the trend sparkline.
|
|
145
|
+
- **Costs**: estimated at public API rates from local session logs
|
|
146
|
+
(`~/.claude/projects`, `~/.codex/sessions`), with per-model pricing mirrored
|
|
147
|
+
from [CodexBar](https://github.com/steipete/CodexBar). Estimates, not bills —
|
|
148
|
+
they exist to show what your subscription usage would cost at API rates.
|
|
149
|
+
|
|
150
|
+
See [docs/how-it-works.md](docs/how-it-works.md) for the full architecture:
|
|
151
|
+
token lifecycles, the codex single-session discovery, supervisor internals,
|
|
152
|
+
and every endpoint touched.
|
|
153
|
+
|
|
154
|
+
## FAQ
|
|
155
|
+
|
|
156
|
+
**Is this safe to run?** It only manages accounts you own, with credentials
|
|
157
|
+
already on your machine, talking to the providers' own endpoints. Treat
|
|
158
|
+
`~/.claude/accounts` and `~/.codex/accounts` like the secrets they are (the
|
|
159
|
+
tool keeps them `0600`).
|
|
160
|
+
|
|
161
|
+
**What about pinned sessions?** Claude worktree pins
|
|
162
|
+
(`claude-acct pin`) are respected — pinned sessions never follow the global
|
|
163
|
+
switch, by design.
|
|
164
|
+
|
|
165
|
+
**A codex switch happened mid-turn — did I lose work?** The thread resumes,
|
|
166
|
+
but an in-flight turn is lost (it was about to die to the rate limit anyway).
|
|
167
|
+
Re-ask and continue.
|
|
168
|
+
|
|
169
|
+
**npm upgraded codex and the shim disappeared.** That's the fail-safe
|
|
170
|
+
direction: upgrades restore stock codex. Re-run
|
|
171
|
+
`ai-acct-autopilot codex-shim install`.
|
|
172
|
+
|
|
173
|
+
**Linux/Windows?** Not yet — Claude account storage is macOS-keychain-based.
|
|
174
|
+
The codex side is mostly portable; PRs welcome.
|
|
175
|
+
|
|
176
|
+
## Credits
|
|
177
|
+
|
|
178
|
+
- [CodexBar](https://github.com/steipete/CodexBar) for the pricing tables,
|
|
179
|
+
the `wham/usage` endpoint path, and the visual inspiration.
|
|
180
|
+
- Built end-to-end with [Claude Code](https://claude.com/claude-code).
|
|
181
|
+
|
|
182
|
+
## License
|
|
183
|
+
|
|
184
|
+
[MIT](LICENSE)
|
|
Binary file
|