agent-tank 0.9.3 → 0.9.5

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/README.md CHANGED
@@ -2,286 +2,268 @@
2
2
 
3
3
  ![Agent Tank Web UI preview](https://raw.githubusercontent.com/integry/agent-tank/main/media/www-preview.png)
4
4
 
5
- Monitor and query usage limits for LLM CLI tools (Claude, Gemini, Codex) via a simple HTTP API.
5
+ Agent Tank is a local dashboard and HTTP API for monitoring usage limits in AI coding agent CLIs.
6
6
 
7
- > **Note:** Agent Tank is designed for **AI coding agent subscriptions** such as Claude Code Pro/Max, Google Gemini CLI (with Advanced/Max plans), and ChatGPT Codex (with Plus/Pro plans). It tracks **active session and rate limit usage**—not API key consumption or pay-per-use billing. If you're using API keys with pay-as-you-go pricing, this tool won't help you track costs; check your provider's billing dashboard instead.
7
+ It supports:
8
8
 
9
- ## Features
9
+ - Claude Code
10
+ - Gemini CLI
11
+ - OpenAI Codex
10
12
 
11
- - **Privacy-first** - Runs entirely locally with no external data transmission
12
- - **Auto-discovery** - Automatically detects installed LLM CLI tools
13
- - **HTTP API** - Query usage limits via REST endpoints
14
- - **Unified Web UI** - All-in-one dashboard showing Claude, Gemini, and Codex usage at a glance
15
- - **Instant Tab Tracking** - Pin the dashboard to your browser tab and see live usage updates via favicon and title changes
16
- - **Lightweight** - Single dependency (node-pty)
17
- - **Multi-agent** - Monitor Claude, Gemini, and Codex simultaneously
18
- - **Secure by design** - No browser cookies, web scraping, or credential access
13
+ ## How It Gets the Data
19
14
 
20
- ## Usage
15
+ This is the part that matters.
21
16
 
22
- ### Basic Usage
17
+ Agent Tank reads usage directly from the local CLI tools you already use. It launches the installed CLIs locally, runs their built-in usage commands, and parses the output into a unified web UI and JSON API.
23
18
 
24
- ```bash
25
- # Auto-discover and monitor all available LLM agents
26
- agent-tank
19
+ - Claude: runs `/usage`
20
+ - Gemini: runs `/stats`
21
+ - Codex: prefers JSON-RPC `account/rateLimits/read`, falls back to `/status`
27
22
 
28
- # Monitor specific agents only
29
- agent-tank --claude --gemini
23
+ What it does not do:
30
24
 
31
- # Use a custom port (default: 3456)
32
- agent-tank --port 8080
25
+ - It does not scrape provider websites
26
+ - It does not read browser cookies
27
+ - It does not depend on a logged-in browser session
28
+ - It does not MITM or inspect your network traffic
29
+ - It does not send your usage data to a remote service
33
30
 
34
- # Fetch usage once and exit (no HTTP server)
35
- agent-tank --once
31
+ If you have seen other tools built around log-file heuristics or browser-session scraping, Agent Tank is deliberately not that.
36
32
 
37
- # Output pure JSON for scripting/piping
38
- agent-tank --once --json
39
- ```
33
+ ## Who It Is For
40
34
 
41
- ### Command Line Options
35
+ Agent Tank is meant for subscription-based coding agent products where the CLI itself exposes session or limit information.
42
36
 
43
- ```
44
- Options:
45
- --claude Enable Claude monitoring
46
- --gemini Enable Gemini monitoring
47
- --codex Enable Codex monitoring
48
- --port <port> HTTP server port (default: 3456)
49
- --host <host> Bind address (default: 127.0.0.1)
50
- --auth-user <user> HTTP Basic Auth username
51
- --auth-pass <pass> HTTP Basic Auth password
52
- --auth-token <token> API key for Bearer token auth
53
- --fresh-process Spawn a new process per refresh (default: false)
54
- --claude-api Use direct Anthropic API for Claude usage (faster, 60s refresh)
55
- --config, -c Path to config file (JSON)
56
- --auto-discover Auto-discover available agents (default: true)
57
- --auto-refresh Enable/disable background auto-refresh (default: true)
58
- --auto-refresh-mode <mode> Refresh mode: none, interval, activity (default: activity)
59
- --auto-refresh-interval <seconds> Auto-refresh interval in seconds (default: 60)
60
- --activity-debounce <ms> Activity debounce interval in milliseconds (default: 5000)
61
- --keepalive Enable/disable session keepalive (default: true)
62
- --keepalive-interval <seconds> Session keepalive interval in seconds (default: 300)
63
- --history-retention-days <days> Days to retain usage history (default: 14)
64
- --once Fetch usage once and exit (no HTTP server)
65
- --json Output pure JSON (suppress logging, use with --once)
66
- --help, -h Show this help message
67
- ```
37
+ Examples:
68
38
 
69
- ### Environment Variables
39
+ - Claude Code Pro / Max
40
+ - Gemini CLI with supported subscription plans
41
+ - ChatGPT Codex with supported plans
70
42
 
71
- Environment variables override CLI flags and config file settings:
43
+ It is not for:
72
44
 
73
- | Variable | Description |
74
- |----------|-------------|
75
- | `AGENT_TANK_USER` | Basic auth username (overrides `--auth-user`) |
76
- | `AGENT_TANK_PASS` | Basic auth password (overrides `--auth-pass`) |
77
- | `AGENT_TANK_TOKEN` | API key (overrides `--auth-token`) |
78
- | `AGENT_TANK_HOST` | Bind address (overrides `--host`) |
79
- | `AGENT_TANK_FRESH_PROCESS` | Use fresh process per refresh (`1` or `true`) |
80
- | `AGENT_TANK_CLAUDE_API` | Use direct Anthropic API for Claude usage (`1` or `true`) |
81
- | `AGENT_TANK_AUTO_REFRESH` | Enable/disable background auto-refresh (`1`/`true` or `0`/`false`) |
82
- | `AGENT_TANK_AUTO_REFRESH_MODE` | Refresh mode: `none`, `interval`, or `activity` (default: `activity`) |
83
- | `AGENT_TANK_AUTO_REFRESH_INTERVAL` | Auto-refresh interval in seconds |
84
- | `AGENT_TANK_ACTIVITY_DEBOUNCE` | Activity debounce interval in milliseconds (default: 5000) |
85
- | `AGENT_TANK_KEEPALIVE` | Enable/disable session keepalive (`1`/`true` or `0`/`false`) |
86
- | `AGENT_TANK_KEEPALIVE_INTERVAL` | Session keepalive interval in seconds (default: 300) |
87
- | `AGENT_TANK_HISTORY_RETENTION_DAYS` | Days to retain usage history (default: 14) |
45
+ - pay-as-you-go API key billing
46
+ - cost tracking for API requests
47
+ - provider billing dashboards
88
48
 
89
- ### Configuration File
49
+ If you need API spend tracking, use the provider’s billing tools instead.
90
50
 
91
- You can use a JSON configuration file:
51
+ ## Quick Start
92
52
 
93
- ```json
94
- {
95
- "claude": true,
96
- "gemini": true,
97
- "codex": false,
98
- "port": 8080,
99
- "history": {
100
- "retentionDays": 7
101
- }
102
- }
103
- ```
53
+ ### Install
104
54
 
105
55
  ```bash
106
- agent-tank -c config.json
56
+ npm install -g agent-tank
107
57
  ```
108
58
 
109
- ## Claude API Mode
110
-
111
- By default, Claude usage data is fetched by spawning a PTY session and running the `/usage` command. With `--claude-api`, Agent Tank fetches usage directly from the Anthropic OAuth API instead, which is faster and allows a 60-second refresh interval (vs 10 minutes for PTY).
59
+ Or run it directly:
112
60
 
113
61
  ```bash
114
- agent-tank --claude --claude-api
62
+ npx agent-tank
115
63
  ```
116
64
 
117
- ### How It Works
65
+ ### First Run
118
66
 
119
- - Uses the OAuth token from `~/.claude/.credentials.json` (the same credentials Claude Code uses)
120
- - Calls the `api.anthropic.com/api/oauth/usage` endpoint with the `anthropic-beta: oauth-2025-04-20` header
121
- - Automatically refreshes expired tokens using the OAuth refresh token flow
122
- - Falls back to PTY mode if the API call fails
67
+ ```bash
68
+ # Auto-discover installed agents and start the web UI + API
69
+ agent-tank
70
+ ```
123
71
 
124
- ### Configuration
72
+ By default it starts on:
125
73
 
126
- ```json
127
- {
128
- "claude": true,
129
- "claudeApi": true
130
- }
74
+ ```text
75
+ http://127.0.0.1:3456
131
76
  ```
132
77
 
133
- Or via environment variable:
78
+ If Docker is available, Agent Tank asks Docker for the active bridge gateway addresses and binds them by default so containers on the same host can reach it without exposing it on the public interface. If Docker is unavailable, it falls back to local bridge interface detection.
79
+
80
+ Use this if you want localhost only:
134
81
 
135
82
  ```bash
136
- AGENT_TANK_CLAUDE_API=1 agent-tank --claude
83
+ agent-tank --no-docker
137
84
  ```
138
85
 
139
- ## Activity-Based Polling
86
+ ### Most Common Commands
140
87
 
141
- Agent Tank supports intelligent activity-based polling that monitors local log directories for LLM CLI activity. Instead of polling on a fixed interval (which can waste resources during idle periods), activity mode only triggers usage refreshes when you're actively using the CLI tools.
88
+ ```bash
89
+ # Monitor only specific agents
90
+ agent-tank --claude --gemini
142
91
 
143
- ### How It Works
92
+ # Use a custom port
93
+ agent-tank --port 8080
144
94
 
145
- 1. **Log Directory Monitoring**: Agent Tank watches the following directories for file changes:
146
- - Claude: `~/.config/claude/projects/`, `~/.claude/`
147
- - Codex: `~/.codex/sessions/`, `~/.codex/`
148
- - Gemini: `~/.config/gemini/`, `~/.gemini/`
95
+ # Fetch once and print JSON
96
+ agent-tank --once --json
149
97
 
150
- 2. **Debounced Detection**: When activity is detected, a configurable debounce timer starts. This prevents excessive refreshes during bursts of activity.
98
+ # Show the installed Agent Tank version
99
+ agent-tank --version
151
100
 
152
- 3. **On-Demand Refresh Cycles**: After the debounce period, a refresh cycle begins and continues at the configured interval while activity is ongoing.
101
+ # Require at least 60 seconds between refreshes for the same agent
102
+ agent-tank --refresh-cooldown 60
103
+ ```
153
104
 
154
- 4. **Idle State**: When no more activity is detected, polling stops to conserve resources.
105
+ ## What You Get
155
106
 
156
- ### Auto-Refresh Modes
107
+ ### Web UI
157
108
 
158
- Agent Tank supports three refresh modes:
109
+ - Single-page dashboard for all supported agents
110
+ - Live refresh
111
+ - Reset countdowns
112
+ - Pace indicators
113
+ - Browser-tab tracking via title and favicon updates
159
114
 
160
- | Mode | Description |
161
- |------|-------------|
162
- | `activity` | (Default) Monitors log directories and refreshes when CLI activity is detected |
163
- | `interval` | Traditional interval-based polling at fixed intervals |
164
- | `none` | No automatic refresh; manual refresh only via `POST /refresh` |
115
+ ### HTTP API
165
116
 
166
- ### Configuration
117
+ - `GET /status`
118
+ - `GET /status/:agent`
119
+ - `POST /refresh`
120
+ - `POST /refresh/:agent`
121
+ - `GET /config`
122
+ - `GET /history`
123
+ - `GET /history/:agent`
167
124
 
168
- ```bash
169
- # Use activity-based polling (default)
170
- agent-tank
125
+ ### Supported Metrics
171
126
 
172
- # Use activity mode with custom debounce (wait 10 seconds after activity)
173
- agent-tank --activity-debounce 10000
127
+ | Agent | Method | Metrics |
128
+ |---|---|---|
129
+ | Claude | PTY `/usage` or Anthropic OAuth API | Current session, weekly all-models, weekly Sonnet-only |
130
+ | Gemini | PTY `/stats` | Per-model usage and reset windows |
131
+ | Codex | JSON-RPC preferred, PTY fallback | 5-hour limits, weekly limits, model/account info |
174
132
 
175
- # Use traditional interval-based polling
176
- agent-tank --auto-refresh-mode interval
133
+ ## Basic Usage
177
134
 
178
- # Disable all auto-refresh (manual only)
179
- agent-tank --auto-refresh-mode none
135
+ ### Auto-Discover Everything
180
136
 
181
- # Via environment variables
182
- AGENT_TANK_AUTO_REFRESH_MODE=activity agent-tank
183
- AGENT_TANK_ACTIVITY_DEBOUNCE=10000 agent-tank
137
+ ```bash
138
+ agent-tank
184
139
  ```
185
140
 
186
- ### Notes
187
-
188
- - Activity mode automatically falls back to interval mode if no log directories are found
189
- - The debounce interval is specified in milliseconds (default: 5000ms = 5 seconds)
190
- - During active usage, refreshes occur at the `--auto-refresh-interval` rate (default: 60 seconds)
191
- - Activity mode is disabled in one-shot mode (`--once`)
192
-
193
- ## Session Keepalive
141
+ ### Monitor Specific Agents
194
142
 
195
- Agent Tank includes an automatic session keepalive feature that prevents LLM CLI sessions from expiring due to inactivity. This is especially useful for Claude and Codex, which have session timeouts that require periodic activity.
143
+ ```bash
144
+ agent-tank --claude --codex
145
+ ```
196
146
 
197
- ### How It Works
147
+ ### One-Shot Scripting Mode
198
148
 
199
- The keepalive manager runs in the background and periodically sends lightweight "ping" commands to each agent's PTY session. This maintains the connection without triggering API calls or affecting rate limits.
149
+ ```bash
150
+ agent-tank --once --json
151
+ ```
200
152
 
201
- ### Configuration
153
+ ### Bind to a Different Host or Port
202
154
 
203
155
  ```bash
204
- # Use default keepalive (every 5 minutes)
205
- agent-tank
206
-
207
- # Custom keepalive interval (every 10 minutes)
208
- agent-tank --keepalive-interval 600
156
+ agent-tank --host 0.0.0.0 --port 8080
157
+ ```
209
158
 
210
- # Disable keepalive
211
- agent-tank --no-keepalive
159
+ ### Disable Docker Bridge Binding
212
160
 
213
- # Via environment variable
214
- AGENT_TANK_KEEPALIVE_INTERVAL=600 agent-tank
161
+ ```bash
162
+ agent-tank --no-docker
215
163
  ```
216
164
 
217
- ### Notes
165
+ ### Disable Background Refresh
218
166
 
219
- - Keepalive is automatically disabled in fresh process mode (`--fresh-process`) since there are no persistent sessions to maintain
220
- - Keepalive is also disabled in one-shot mode (`--once`)
221
- - The feature only affects PTY-based sessions; JSON-RPC mode (used by Codex when available) doesn't require keepalive
167
+ ```bash
168
+ agent-tank --auto-refresh-mode none
169
+ ```
222
170
 
223
- ## Usage History & Pace Evaluation
171
+ ### Slow Down Agent Refreshes
224
172
 
225
- Agent Tank automatically tracks usage history and evaluates whether you're burning through your rate limits faster than expected.
173
+ By default, Agent Tank will not refresh the same agent more than once every 30 seconds, even if the refresh is triggered manually or by detected CLI activity. This reduces unnecessary polling and helps avoid CLI-side rate limiting.
226
174
 
227
- ### Features
175
+ ```bash
176
+ agent-tank --refresh-cooldown 60
177
+ ```
228
178
 
229
- - **Historical Snapshots**: Usage percentages are stored in `~/.agent-tank/history.json` with timestamps
230
- - **Automatic Pruning**: Records older than the retention period (default: 14 days) are automatically removed
231
- - **Pace Evaluation**: Each metric includes a `paceEval` object that calculates:
232
- - `expectedPercent`: What your usage should be based on linear pace
233
- - `isBurningFast`: Whether you're using faster than the 1.2x threshold
234
- - `etaSeconds`: Estimated seconds until you hit 100% (if burning fast)
235
- - `deltaPercent`: Difference between actual and expected usage
179
+ Set it to `0` to disable the cooldown entirely.
236
180
 
237
- ### Configuration
181
+ ## Command Line Options
238
182
 
239
- ```bash
240
- # Keep 7 days of history instead of default 14
241
- agent-tank --history-retention-days 7
242
-
243
- # Via environment variable
244
- AGENT_TANK_HISTORY_RETENTION_DAYS=7 agent-tank
183
+ ```text
184
+ Options:
185
+ --claude Enable Claude monitoring
186
+ --gemini Enable Gemini monitoring
187
+ --codex Enable Codex monitoring
188
+ --port <port> HTTP server port (default: 3456)
189
+ --host <host> Bind address (default: 127.0.0.1 + Docker bridge when available)
190
+ --docker Enable Docker bridge bind when --host is omitted (default: true)
191
+ --auth-user <user> HTTP Basic Auth username
192
+ --auth-pass <pass> HTTP Basic Auth password
193
+ --auth-token <token> API key for Bearer token auth
194
+ --fresh-process Spawn a new process per refresh (default: false)
195
+ --claude-api Use direct Anthropic API for Claude usage (faster, 60s refresh)
196
+ --config, -c Path to config file (JSON)
197
+ --version, -v Show version
198
+ --auto-discover Auto-discover available agents (default: true)
199
+ --auto-refresh Enable/disable background auto-refresh (default: true)
200
+ --auto-refresh-mode <mode> Refresh mode: none, interval, activity (default: activity)
201
+ --auto-refresh-interval <seconds> Auto-refresh interval in seconds (default: 60)
202
+ --refresh-cooldown <seconds> Minimum time between refreshes per agent (default: 30, 0 = disabled)
203
+ --activity-debounce <ms> Activity debounce interval in milliseconds (default: 5000)
204
+ --keepalive Enable/disable session keepalive (default: true)
205
+ --keepalive-interval <seconds> Session keepalive interval in seconds (default: 300)
206
+ --history-retention-days <days> Days to retain usage history (default: 14)
207
+ --once Fetch usage once and exit (no HTTP server)
208
+ --json Output pure JSON (suppress logging, use with --once)
209
+ --help, -h Show this help message
245
210
  ```
246
211
 
247
- ### API Endpoints
212
+ ## Configuration
248
213
 
249
- - `GET /history` - Get history statistics (total records, per-agent counts, date ranges)
250
- - `GET /history/:agent` - Get full history for a specific agent
214
+ ### Environment Variables
215
+
216
+ Environment variables override CLI flags and config file values.
251
217
 
252
- ### Example Pace Evaluation Data
218
+ | Variable | Description |
219
+ |---|---|
220
+ | `AGENT_TANK_USER` | Basic auth username |
221
+ | `AGENT_TANK_PASS` | Basic auth password |
222
+ | `AGENT_TANK_TOKEN` | Bearer token auth |
223
+ | `AGENT_TANK_HOST` | Bind address |
224
+ | `AGENT_TANK_DOCKER` | Enable/disable Docker bridge bind when `--host` is omitted |
225
+ | `AGENT_TANK_FRESH_PROCESS` | Use fresh process per refresh (`1`/`true`) |
226
+ | `AGENT_TANK_CLAUDE_API` | Use Claude API mode (`1`/`true`) |
227
+ | `AGENT_TANK_AUTO_REFRESH` | Enable/disable auto-refresh |
228
+ | `AGENT_TANK_AUTO_REFRESH_MODE` | `none`, `interval`, or `activity` |
229
+ | `AGENT_TANK_AUTO_REFRESH_INTERVAL` | Auto-refresh interval in seconds |
230
+ | `AGENT_TANK_REFRESH_COOLDOWN` | Minimum time between refreshes per agent in seconds |
231
+ | `AGENT_TANK_ACTIVITY_DEBOUNCE` | Activity debounce interval in milliseconds |
232
+ | `AGENT_TANK_KEEPALIVE` | Enable/disable keepalive |
233
+ | `AGENT_TANK_KEEPALIVE_INTERVAL` | Keepalive interval in seconds |
234
+ | `AGENT_TANK_HISTORY_RETENTION_DAYS` | History retention window |
253
235
 
254
- When an agent is burning faster than expected, the `paceEval` object is attached to each metric:
236
+ ### Config File
255
237
 
256
238
  ```json
257
239
  {
258
- "session": {
259
- "percent": 60,
260
- "resetsInSeconds": 9000,
261
- "paceEval": {
262
- "expectedPercent": 50,
263
- "isBurningFast": true,
264
- "etaSeconds": 6000,
265
- "paceRatio": 1.2,
266
- "elapsedPercent": 50,
267
- "deltaPercent": 10
268
- }
240
+ "claude": true,
241
+ "gemini": true,
242
+ "codex": false,
243
+ "port": 8080,
244
+ "dockerAccess": true,
245
+ "claudeApi": false,
246
+ "refreshCooldown": 30,
247
+ "autoRefresh": {
248
+ "mode": "activity",
249
+ "interval": 60,
250
+ "activityDebounce": 5000,
251
+ "refreshCooldown": 30
252
+ },
253
+ "keepalive": {
254
+ "enabled": true,
255
+ "interval": 300
256
+ },
257
+ "history": {
258
+ "retentionDays": 14
269
259
  }
270
260
  }
271
261
  ```
272
262
 
273
- This example shows: 50% of the 5-hour session has elapsed, but 60% of usage is consumed. At this pace (1.2x), you'll hit 100% in approximately 6000 seconds (1h 40m).
274
-
275
- ## Installation
276
-
277
- ```bash
278
- npm install -g agent-tank
279
- ```
280
-
281
- Or run directly with npx:
263
+ Run with:
282
264
 
283
265
  ```bash
284
- npx agent-tank
266
+ agent-tank -c config.json
285
267
  ```
286
268
 
287
269
  ## HTTP API
@@ -289,19 +271,17 @@ npx agent-tank
289
271
  ### Endpoints
290
272
 
291
273
  | Method | Endpoint | Description |
292
- |--------|----------|-------------|
274
+ |---|---|---|
293
275
  | GET | `/` | HTML status page |
294
276
  | GET | `/status` | JSON status for all agents |
295
- | GET | `/status/:agent` | JSON status for specific agent |
296
- | GET | `/config` | Auto-refresh and history configuration (JSON) |
297
- | GET | `/history` | Usage history statistics (JSON) |
298
- | GET | `/history/:agent` | Usage history for specific agent (JSON) |
277
+ | GET | `/status/:agent` | JSON status for one agent |
278
+ | GET | `/config` | Auto-refresh and history config |
279
+ | GET | `/history` | History summary |
280
+ | GET | `/history/:agent` | History for one agent |
299
281
  | POST | `/refresh` | Refresh all agents |
300
- | POST | `/refresh/:agent` | Refresh specific agent |
282
+ | POST | `/refresh/:agent` | Refresh one agent |
301
283
 
302
- ### Example Responses
303
-
304
- #### GET /status
284
+ ### Example `GET /status`
305
285
 
306
286
  ```json
307
287
  {
@@ -321,19 +301,9 @@ npx agent-tank
321
301
  "resetsAt": "Mar 13, 3am (Europe/London)",
322
302
  "resetsIn": "4d 5h",
323
303
  "resetsInSeconds": 364364
324
- },
325
- "weeklySonnet": {
326
- "label": "Current week (Sonnet only)",
327
- "percent": 5,
328
- "resetsAt": "Mar 13, 10am (Europe/London)",
329
- "resetsIn": "4d 12h",
330
- "resetsInSeconds": 389564
331
304
  }
332
305
  },
333
306
  "metadata": {
334
- "sessionId": "0b34aa59-...",
335
- "cwd": "/tmp",
336
- "organization": "Your Organization",
337
307
  "email": "user@example.com",
338
308
  "version": "2.1.71"
339
309
  },
@@ -341,94 +311,25 @@ npx agent-tank
341
311
  "error": null,
342
312
  "isRefreshing": false
343
313
  },
344
- "gemini": {
345
- "name": "gemini",
346
- "usage": {
347
- "models": [
348
- {
349
- "model": "gemini-2.5-flash",
350
- "usageLeft": 100,
351
- "resetsIn": "24h",
352
- "percentUsed": 0,
353
- "resetsInSeconds": 86400
354
- },
355
- {
356
- "model": "gemini-2.5-pro",
357
- "usageLeft": 99.5,
358
- "resetsIn": "12h 16m",
359
- "percentUsed": 0.5,
360
- "resetsInSeconds": 44160
361
- }
362
- ]
363
- },
364
- "metadata": {
365
- "version": "0.24.5",
366
- "email": "user@example.com",
367
- "authMethod": "OAuth",
368
- "model": "auto-gemini-2.5",
369
- "os": "linux",
370
- "updateAvailable": {
371
- "current": "0.24.5",
372
- "latest": "0.32.1"
373
- }
374
- },
375
- "lastUpdated": "2026-03-08T21:47:14.138Z",
376
- "error": null,
377
- "isRefreshing": false
378
- },
379
314
  "codex": {
380
315
  "name": "codex",
381
316
  "usage": {
382
317
  "fiveHour": {
383
- "percentLeft": 100,
384
- "resetsAt": "02:44 on 9 Mar",
385
- "label": "5h limit",
386
318
  "percentUsed": 0,
319
+ "resetsAt": "02:44 on 9 Mar",
387
320
  "resetsIn": "4h 56m",
388
321
  "resetsInSeconds": 17807
389
322
  },
390
323
  "weekly": {
391
- "percentLeft": 100,
392
- "resetsAt": "21:44 on 15 Mar",
393
- "label": "Weekly limit",
394
324
  "percentUsed": 0,
325
+ "resetsAt": "21:44 on 15 Mar",
395
326
  "resetsIn": "6d 23h",
396
327
  "resetsInSeconds": 604607
397
- },
398
- "version": {
399
- "current": "0.107.0",
400
- "latest": "0.111.0"
401
- },
402
- "modelLimits": [
403
- {
404
- "name": "GPT-5.3-Codex-Spark",
405
- "fiveHour": {
406
- "percentLeft": 100,
407
- "resetsAt": "02:46 on 9 Mar",
408
- "label": "5h limit",
409
- "percentUsed": 0,
410
- "resetsIn": "4h 58m",
411
- "resetsInSeconds": 17927
412
- },
413
- "weekly": {
414
- "percentLeft": 100,
415
- "resetsAt": "21:46 on 15 Mar",
416
- "label": "Weekly limit",
417
- "percentUsed": 0,
418
- "resetsIn": "6d 23h",
419
- "resetsInSeconds": 604727
420
- }
421
- }
422
- ],
423
- "model": "gpt-5.3-codex",
424
- "account": "user@example.com"
328
+ }
425
329
  },
426
330
  "metadata": {
427
- "directory": "/tmp",
428
- "sessionId": "019ccf68-...",
429
- "collaborationMode": "Default",
430
- "model": "gpt-5.3-codex",
431
- "email": "user@example.com"
331
+ "email": "user@example.com",
332
+ "model": "gpt-5.3-codex"
432
333
  },
433
334
  "lastUpdated": "2026-03-08T21:47:12.648Z",
434
335
  "error": null,
@@ -437,220 +338,206 @@ npx agent-tank
437
338
  }
438
339
  ```
439
340
 
440
- #### GET /status/claude
341
+ ## Claude API Mode
441
342
 
442
- ```json
443
- {
444
- "name": "claude",
445
- "usage": {
446
- "session": {
447
- "label": "Current session",
448
- "percent": 42,
449
- "resetsAt": "10pm (Europe/London)",
450
- "resetsIn": "12m",
451
- "resetsInSeconds": 764
452
- },
453
- "weeklyAll": {
454
- "label": "Current week (all models)",
455
- "percent": 31,
456
- "resetsAt": "Mar 13, 3am (Europe/London)",
457
- "resetsIn": "4d 5h",
458
- "resetsInSeconds": 364364
459
- },
460
- "weeklySonnet": {
461
- "label": "Current week (Sonnet only)",
462
- "percent": 5,
463
- "resetsAt": "Mar 13, 10am (Europe/London)",
464
- "resetsIn": "4d 12h",
465
- "resetsInSeconds": 389564
466
- }
467
- },
468
- "metadata": {
469
- "sessionId": "0b34aa59-...",
470
- "cwd": "/tmp",
471
- "organization": "Your Organization",
472
- "email": "user@example.com",
473
- "version": "2.1.71"
474
- },
475
- "lastUpdated": "2026-03-08T21:47:15.090Z",
476
- "error": null,
477
- "isRefreshing": false
478
- }
479
- ```
343
+ By default, Claude usage is collected via PTY by running `/usage`.
480
344
 
481
- ## Developer & Advanced Setup
345
+ With `--claude-api`, Agent Tank uses the Anthropic OAuth usage API instead. This is usually faster and supports a shorter refresh interval.
482
346
 
483
- ### Prerequisites
347
+ ```bash
348
+ agent-tank --claude --claude-api
349
+ ```
484
350
 
485
- #### Build Requirements
351
+ How it works:
486
352
 
487
- The `node-pty` dependency requires native compilation. You'll need:
353
+ - reads the same Claude OAuth credentials the CLI already uses
354
+ - calls `https://api.anthropic.com/api/oauth/usage`
355
+ - refreshes expired OAuth tokens when needed
356
+ - falls back to PTY mode if the API path fails
488
357
 
489
- - **Python 3.8+** (Python 3.11 recommended)
490
- - **C++ build tools** (gcc, g++, make)
491
- - **Node.js development headers**
358
+ You can also enable it with:
492
359
 
493
- ##### Linux (Ubuntu/Debian)
494
360
  ```bash
495
- sudo apt-get install python3.11 python3.11-dev build-essential nodejs-dev
361
+ AGENT_TANK_CLAUDE_API=1 agent-tank --claude
496
362
  ```
497
363
 
498
- ##### Linux (Fedora/RHEL/CentOS)
499
- ```bash
500
- sudo dnf install python3.11 python3.11-devel gcc gcc-c++ make nodejs-devel
501
- ```
364
+ ## Auto-Refresh Modes
502
365
 
503
- ##### Linux (openSUSE)
504
- ```bash
505
- sudo zypper install python311 python311-devel gcc gcc-c++ make nodejs20-devel
506
- ```
366
+ Agent Tank supports three refresh strategies:
367
+
368
+ | Mode | Description |
369
+ |---|---|
370
+ | `activity` | Default. Watches known local agent directories and refreshes when activity is detected |
371
+ | `interval` | Refreshes on a fixed timer |
372
+ | `none` | No background refresh. Use manual refresh only |
373
+
374
+ Examples:
507
375
 
508
- ##### macOS
509
376
  ```bash
510
- # Install Xcode Command Line Tools if not already installed
511
- xcode-select --install
377
+ # Default mode
378
+ agent-tank
512
379
 
513
- # Install Python 3.11
514
- brew install python@3.11
380
+ # Interval polling
381
+ agent-tank --auto-refresh-mode interval
382
+
383
+ # Manual-only mode
384
+ agent-tank --auto-refresh-mode none
385
+
386
+ # Longer activity debounce
387
+ agent-tank --activity-debounce 10000
515
388
  ```
516
389
 
517
- ##### Windows
518
- - Install [Python 3.11+](https://www.python.org/downloads/)
519
- - Install [Visual Studio Build Tools](https://visualstudio.microsoft.com/downloads/#build-tools-for-visual-studio-2022)
390
+ ### Activity-Based Polling
520
391
 
521
- #### LLM CLI Tools
392
+ In activity mode, Agent Tank watches common local directories:
522
393
 
523
- You need at least one of these CLI tools installed and authenticated:
394
+ - Claude: `~/.config/claude/projects/`, `~/.claude/`
395
+ - Codex: `~/.codex/sessions/`, `~/.codex/`
396
+ - Gemini: `~/.config/gemini/`, `~/.gemini/`
524
397
 
525
- - [Claude Code](https://claude.ai/download) (`claude`) - **Version 2.0+ required** for `/usage` command support
526
- - [Gemini CLI](https://github.com/anthropics/gemini-cli) (`gemini`) - **Version 0.24.5+ required** for `/stats` command support
527
- - [OpenAI Codex](https://platform.openai.com/docs/codex) (`codex`)
398
+ If no suitable directories are found, it falls back to interval mode.
399
+
400
+ ## Session Keepalive
528
401
 
529
- **Version Requirements:**
402
+ Keepalive helps persistent PTY-backed sessions stay warm.
530
403
 
531
- **Claude Code:** Version 1.x does not support the `/usage` command.
532
404
  ```bash
533
- # Check version
534
- claude --version
405
+ # Default keepalive
406
+ agent-tank
407
+
408
+ # Every 10 minutes
409
+ agent-tank --keepalive-interval 600
535
410
 
536
- # Update to latest
537
- npm update -g @anthropic-ai/claude-code
411
+ # Disable keepalive
412
+ agent-tank --no-keepalive
538
413
  ```
539
414
 
540
- **Gemini CLI:** Version 0.24.4 and below do not support the `/stats` command properly.
541
- ```bash
542
- # Check version
543
- gemini --version
415
+ Notes:
416
+
417
+ - disabled automatically in `--fresh-process`
418
+ - disabled automatically in `--once`
419
+ - not needed for Codex JSON-RPC mode
420
+
421
+ ## Usage History and Pace
422
+
423
+ Agent Tank stores usage snapshots and calculates whether a metric is being consumed faster than the time window would suggest.
424
+
425
+ You can configure retention:
544
426
 
545
- # Update to latest
546
- npm update -g gemini
427
+ ```bash
428
+ agent-tank --history-retention-days 7
547
429
  ```
548
430
 
549
- ### Programmatic Usage
431
+ History endpoints:
550
432
 
551
- ```javascript
552
- const { AgentTank } = require('agent-tank');
433
+ - `GET /history`
434
+ - `GET /history/:agent`
553
435
 
554
- const watcher = new AgentTank({
555
- agents: ['claude', 'gemini'], // or null for auto-discover
556
- port: 3456,
557
- autoDiscover: true
558
- });
436
+ ## Installation Notes
559
437
 
560
- await watcher.start();
438
+ ### Build Requirements
561
439
 
562
- // Get status programmatically
563
- const status = watcher.getStatus();
564
- console.log(status.claude.usage);
440
+ `node-pty` requires native compilation support.
565
441
 
566
- // Refresh a specific agent
567
- await watcher.refreshAgent('claude');
442
+ You need:
568
443
 
569
- // Stop the server
570
- watcher.stop();
444
+ - Python 3.8+
445
+ - C/C++ build tools
446
+ - Node.js development headers
447
+
448
+ #### Ubuntu / Debian
449
+
450
+ ```bash
451
+ sudo apt-get install python3.11 python3.11-dev build-essential nodejs-dev
571
452
  ```
572
453
 
573
- ### How It Works: Privacy-First Local Execution
454
+ #### Fedora / RHEL / CentOS
574
455
 
575
- Agent Tank is designed with privacy and security as core principles. Understanding how it collects usage data is essential for users evaluating the tool's security posture.
456
+ ```bash
457
+ sudo dnf install python3.11 python3.11-devel gcc gcc-c++ make nodejs-devel
458
+ ```
576
459
 
577
- #### Local Execution Architecture
460
+ #### openSUSE
578
461
 
579
- The tool operates entirely on your local machine using two different approaches depending on the CLI tool's capabilities:
462
+ ```bash
463
+ sudo zypper install python311 python311-devel gcc gcc-c++ make nodejs20-devel
464
+ ```
580
465
 
581
- **JSON-RPC Mode (Codex)**
466
+ #### macOS
582
467
 
583
- For the Codex CLI, Agent Tank uses a structured JSON-RPC protocol when available:
468
+ ```bash
469
+ xcode-select --install
470
+ brew install python@3.11
471
+ ```
584
472
 
585
- 1. **Starts the app-server** - Launches `codex -s read-only -a untrusted app-server`
586
- 2. **Sends JSON-RPC requests** - Calls `account/rateLimits/read` via stdin
587
- 3. **Receives structured data** - Parses JSON responses with precise rate limit information
588
- 4. **Falls back to PTY** - Automatically uses PTY mode if JSON-RPC is unavailable (older CLI versions)
473
+ #### Windows
589
474
 
590
- This approach provides more reliable data parsing and is the preferred method for Codex.
475
+ - Install [Python 3.11+](https://www.python.org/downloads/)
476
+ - Install [Visual Studio Build Tools](https://visualstudio.microsoft.com/downloads/#build-tools-for-visual-studio-2022)
591
477
 
592
- **PTY-Based Mode (Claude, Gemini, Codex fallback)**
478
+ ## CLI Requirements
593
479
 
594
- For other CLI tools (and as a fallback for Codex), Agent Tank spawns instances within a pseudo-terminal (PTY). This approach is functionally equivalent to you opening a terminal window and typing commands yourself:
480
+ You need at least one supported CLI installed and authenticated.
595
481
 
596
- 1. **Spawns a local PTY** - Creates a pseudo-terminal session on your machine
597
- 2. **Launches the CLI tool** - Starts the authenticated CLI (e.g., `claude`, `gemini`, or `codex`)
598
- 3. **Sends usage commands** - Types the appropriate command (`/usage`, `/stats`, or `/status`)
599
- 4. **Parses the output** - Reads and structures the text response from the terminal
600
- 5. **Exposes via local HTTP** - Makes the parsed data available through a localhost API
482
+ - [Claude Code](https://claude.ai/download) as `claude`
483
+ - Version 2.0+ required for `/usage`
484
+ - Gemini CLI as `gemini`
485
+ - Version 0.24.5+ required for `/stats`
486
+ - OpenAI Codex as `codex`
601
487
 
602
- #### What Agent Tank Does NOT Do
488
+ Useful checks:
603
489
 
604
- To be explicit about what this tool avoids:
490
+ ```bash
491
+ claude --version
492
+ gemini --version
493
+ codex --version
494
+ ```
605
495
 
606
- - **No browser cookie access** - Agent Tank never reads, parses, or transmits browser cookies
607
- - **No web scraping** - The tool does not access web interfaces or scrape HTML pages
608
- - **No credential extraction** - Your API keys, tokens, or passwords are never accessed or stored
609
- - **No network interception** - There is no proxy, MITM, or traffic inspection involved
610
- - **No external data transmission** - Usage data stays on your machine; nothing is sent to external servers
496
+ ## Programmatic Usage
611
497
 
612
- #### Why This Approach?
498
+ ```javascript
499
+ const { AgentTank } = require('agent-tank');
613
500
 
614
- LLM usage data is sensitive—it can reveal work patterns, subscription tiers, and usage intensity. By operating through local CLI tools that you've already authenticated, Agent Tank inherits the security model you've already established with each provider. The tool acts as a local automation layer, not a data collection service.
501
+ const watcher = new AgentTank({
502
+ agents: ['claude', 'gemini'],
503
+ port: 3456,
504
+ autoDiscover: true
505
+ });
615
506
 
616
- #### Supported Commands
507
+ await watcher.start();
617
508
 
618
- | Agent | Method | Command/RPC | Output |
619
- |-------|--------|-------------|--------|
620
- | Claude | PTY | `/usage` | Session %, Weekly % |
621
- | Gemini | PTY | `/stats` | Model-specific usage % |
622
- | Codex | JSON-RPC | `account/rateLimits/read` | 5h limit %, Weekly % |
623
- | Codex | PTY (fallback) | `/status` | 5h limit %, Weekly % |
509
+ const status = watcher.getStatus();
510
+ console.log(status);
624
511
 
625
- ## Troubleshooting
512
+ await watcher.refreshAgent('claude');
626
513
 
627
- ### Installation fails with "gyp ERR!"
514
+ watcher.stop();
515
+ ```
628
516
 
629
- This indicates missing build dependencies. Make sure you have:
517
+ ## Troubleshooting
630
518
 
631
- 1. **Python 3.8+**: Check with `python3 --version`. If you have multiple Python versions, set the PYTHON environment variable:
632
- ```bash
633
- PYTHON=/usr/bin/python3.11 npm install
634
- ```
519
+ ### `gyp ERR!` during install
635
520
 
636
- 2. **Build tools**: Install gcc, g++, and make for your platform (see Prerequisites above)
521
+ This usually means your system is missing Python, compiler tools, or Node headers.
637
522
 
638
- 3. **Node.js headers**: Install the nodejs-devel or nodejs-dev package for your distribution
523
+ Try:
639
524
 
640
- If you still have issues, try rebuilding:
641
525
  ```bash
526
+ PYTHON=/usr/bin/python3.11 npm install
642
527
  npm run rebuild
643
528
  ```
644
529
 
645
- ### Agent shows "Timeout waiting for usage data"
530
+ ### `Timeout waiting for usage data`
646
531
 
647
- - Ensure the CLI tool is properly authenticated
648
- - Try running the CLI tool manually to verify it works
649
- - Check if there are any prompts requiring user input
532
+ - make sure the CLI works on its own
533
+ - make sure the CLI is authenticated
534
+ - check for trust prompts, auth prompts, or update prompts
535
+ - try `--fresh-process`
536
+ - try disabling keepalive or background refresh while debugging
650
537
 
651
- ### Codex fails with cursor position error
538
+ ### No agents found
652
539
 
653
- This is handled automatically. If you still see issues, ensure your terminal supports standard escape sequences.
540
+ Make sure at least one supported CLI is installed and on your `PATH`.
654
541
 
655
542
  ### Port already in use
656
543
 
@@ -672,4 +559,4 @@ MIT
672
559
 
673
560
  ## Contributing
674
561
 
675
- Contributions are welcome! Please feel free to submit a Pull Request.
562
+ Pull requests are welcome.