agentcap-cli 0.1.3__tar.gz → 0.2.0__tar.gz

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.
Files changed (77) hide show
  1. agentcap_cli-0.2.0/PKG-INFO +665 -0
  2. agentcap_cli-0.2.0/README.md +635 -0
  3. {agentcap_cli-0.1.3 → agentcap_cli-0.2.0}/pyproject.toml +5 -2
  4. {agentcap_cli-0.1.3 → agentcap_cli-0.2.0}/src/agentcap/__init__.py +1 -1
  5. {agentcap_cli-0.1.3 → agentcap_cli-0.2.0}/src/agentcap/adapters.py +101 -0
  6. {agentcap_cli-0.1.3 → agentcap_cli-0.2.0}/src/agentcap/alerts.py +78 -6
  7. agentcap_cli-0.2.0/src/agentcap/analytics.py +355 -0
  8. agentcap_cli-0.2.0/src/agentcap/budget.py +124 -0
  9. {agentcap_cli-0.1.3 → agentcap_cli-0.2.0}/src/agentcap/clamp.py +32 -1
  10. {agentcap_cli-0.1.3 → agentcap_cli-0.2.0}/src/agentcap/cli.py +328 -16
  11. agentcap_cli-0.2.0/src/agentcap/cli_history.py +218 -0
  12. {agentcap_cli-0.1.3 → agentcap_cli-0.2.0}/src/agentcap/data/pricing.json +162 -2
  13. {agentcap_cli-0.1.3 → agentcap_cli-0.2.0}/src/agentcap/devtools/fake_upstream.py +159 -0
  14. {agentcap_cli-0.1.3 → agentcap_cli-0.2.0}/src/agentcap/estimate.py +22 -3
  15. agentcap_cli-0.2.0/src/agentcap/eta.py +66 -0
  16. agentcap_cli-0.2.0/src/agentcap/history.py +510 -0
  17. {agentcap_cli-0.1.3 → agentcap_cli-0.2.0}/src/agentcap/license.py +36 -0
  18. agentcap_cli-0.2.0/src/agentcap/loop.py +365 -0
  19. agentcap_cli-0.2.0/src/agentcap/plans.py +70 -0
  20. {agentcap_cli-0.1.3 → agentcap_cli-0.2.0}/src/agentcap/pricing.py +51 -1
  21. {agentcap_cli-0.1.3 → agentcap_cli-0.2.0}/src/agentcap/proxy.py +207 -24
  22. agentcap_cli-0.2.0/src/agentcap/quota.py +936 -0
  23. agentcap_cli-0.2.0/src/agentcap/report.py +204 -0
  24. {agentcap_cli-0.1.3 → agentcap_cli-0.2.0}/src/agentcap/runner.py +186 -3
  25. {agentcap_cli-0.1.3 → agentcap_cli-0.2.0}/src/agentcap/upstreams.py +4 -0
  26. {agentcap_cli-0.1.3 → agentcap_cli-0.2.0}/src/agentcap/usage.py +132 -2
  27. agentcap_cli-0.2.0/src/agentcap/waste.py +448 -0
  28. agentcap_cli-0.2.0/tests/conftest.py +73 -0
  29. agentcap_cli-0.2.0/tests/fixtures/agents/claude/projects/-home-dev-shop/sess-p/subagents/agent-a1b2c3.jsonl +2 -0
  30. agentcap_cli-0.2.0/tests/fixtures/agents/claude/projects/-home-dev-shop/sess-p/subagents/agent-d4e5f6.jsonl +1 -0
  31. agentcap_cli-0.2.0/tests/fixtures/agents/claude/projects/-home-dev-shop/sess-p.jsonl +17 -0
  32. agentcap_cli-0.2.0/tests/fixtures/agents/codex/sessions/2026/10/29/rollout-2026-10-29T09-00-00-thr-parent.jsonl +14 -0
  33. agentcap_cli-0.2.0/tests/fixtures/agents/codex/sessions/2026/10/29/rollout-2026-10-29T09-00-50-thr-child.jsonl +3 -0
  34. agentcap_cli-0.2.0/tests/fixtures/agents/codex/sessions/2026/10/29/rollout-2026-10-29T09-01-20-thr-fork.jsonl +3 -0
  35. agentcap_cli-0.2.0/tests/fixtures/history/claude/.credentials.json +1 -0
  36. agentcap_cli-0.2.0/tests/fixtures/history/claude/projects/-home-dev-shop/1f0c-sess-a.jsonl +8 -0
  37. agentcap_cli-0.2.0/tests/fixtures/history/codex/auth.json +1 -0
  38. agentcap_cli-0.2.0/tests/fixtures/history/codex/sessions/2026/10/29/rollout-2026-10-29T10-00-00-0199aaaa-bbbb-cccc-dddd-eeeeeeeeeeee.jsonl +8 -0
  39. agentcap_cli-0.2.0/tests/test_agents.py +162 -0
  40. agentcap_cli-0.2.0/tests/test_analytics.py +268 -0
  41. agentcap_cli-0.2.0/tests/test_anthropic_proxy.py +230 -0
  42. agentcap_cli-0.2.0/tests/test_anthropic_units.py +217 -0
  43. agentcap_cli-0.2.0/tests/test_budget.py +170 -0
  44. agentcap_cli-0.2.0/tests/test_cc_plugin.py +244 -0
  45. agentcap_cli-0.2.0/tests/test_claude_adapter_and_tiers.py +164 -0
  46. {agentcap_cli-0.1.3 → agentcap_cli-0.2.0}/tests/test_cli.py +319 -9
  47. agentcap_cli-0.2.0/tests/test_e2e_claude.py +137 -0
  48. {agentcap_cli-0.1.3 → agentcap_cli-0.2.0}/tests/test_estimate.py +1 -1
  49. agentcap_cli-0.2.0/tests/test_history.py +200 -0
  50. {agentcap_cli-0.1.3 → agentcap_cli-0.2.0}/tests/test_license.py +69 -2
  51. {agentcap_cli-0.1.3 → agentcap_cli-0.2.0}/tests/test_pricing.py +4 -2
  52. {agentcap_cli-0.1.3 → agentcap_cli-0.2.0}/tests/test_proxy_core.py +1 -0
  53. agentcap_cli-0.2.0/tests/test_quota.py +496 -0
  54. agentcap_cli-0.2.0/tests/test_report_cli.py +68 -0
  55. agentcap_cli-0.2.0/tests/test_runaway.py +135 -0
  56. {agentcap_cli-0.1.3 → agentcap_cli-0.2.0}/tests/test_runner.py +125 -4
  57. agentcap_cli-0.1.3/PKG-INFO +0 -379
  58. agentcap_cli-0.1.3/README.md +0 -349
  59. agentcap_cli-0.1.3/landing/README.md +0 -166
  60. agentcap_cli-0.1.3/src/agentcap/loop.py +0 -118
  61. {agentcap_cli-0.1.3 → agentcap_cli-0.2.0}/.gitignore +0 -0
  62. {agentcap_cli-0.1.3 → agentcap_cli-0.2.0}/LICENSE +0 -0
  63. {agentcap_cli-0.1.3 → agentcap_cli-0.2.0}/src/agentcap/demo.py +0 -0
  64. {agentcap_cli-0.1.3 → agentcap_cli-0.2.0}/src/agentcap/devtools/__init__.py +0 -0
  65. {agentcap_cli-0.1.3 → agentcap_cli-0.2.0}/src/agentcap/ledger.py +0 -0
  66. {agentcap_cli-0.1.3 → agentcap_cli-0.2.0}/tests/license_support.py +0 -0
  67. {agentcap_cli-0.1.3 → agentcap_cli-0.2.0}/tests/proxy_support.py +0 -0
  68. {agentcap_cli-0.1.3 → agentcap_cli-0.2.0}/tests/test_adapters.py +0 -0
  69. {agentcap_cli-0.1.3 → agentcap_cli-0.2.0}/tests/test_alerts.py +0 -0
  70. {agentcap_cli-0.1.3 → agentcap_cli-0.2.0}/tests/test_clamp.py +0 -0
  71. {agentcap_cli-0.1.3 → agentcap_cli-0.2.0}/tests/test_ledger.py +0 -0
  72. {agentcap_cli-0.1.3 → agentcap_cli-0.2.0}/tests/test_loop.py +0 -0
  73. {agentcap_cli-0.1.3 → agentcap_cli-0.2.0}/tests/test_proxy_cancel.py +0 -0
  74. {agentcap_cli-0.1.3 → agentcap_cli-0.2.0}/tests/test_proxy_extras.py +0 -0
  75. {agentcap_cli-0.1.3 → agentcap_cli-0.2.0}/tests/test_proxy_streaming.py +0 -0
  76. {agentcap_cli-0.1.3 → agentcap_cli-0.2.0}/tests/test_upstreams.py +0 -0
  77. {agentcap_cli-0.1.3 → agentcap_cli-0.2.0}/tests/test_usage.py +0 -0
@@ -0,0 +1,665 @@
1
+ Metadata-Version: 2.5
2
+ Name: agentcap-cli
3
+ Version: 0.2.0
4
+ Summary: API-key spend guard for unattended Codex CLI, Gemini CLI and Claude Code runs: hard per-run cap, kills the process at the limit.
5
+ Project-URL: Homepage, https://agentcap.launchbench.studio
6
+ Project-URL: Repository, https://github.com/Blitz00X/agentcap
7
+ Project-URL: Issues, https://github.com/Blitz00X/agentcap/issues
8
+ Author-email: Kutay Karahan <kutaykarahan6@gmail.com>
9
+ License-Expression: MIT
10
+ License-File: LICENSE
11
+ Keywords: ai-agents,budget,claude-code,codex-cli,cost-control,gemini-cli,llm,proxy,spend-cap
12
+ Classifier: Development Status :: 4 - Beta
13
+ Classifier: Environment :: Console
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: Operating System :: POSIX
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Programming Language :: Python :: 3.13
20
+ Classifier: Topic :: Software Development
21
+ Requires-Python: >=3.11
22
+ Requires-Dist: httpx>=0.27
23
+ Requires-Dist: starlette>=0.37
24
+ Requires-Dist: uvicorn>=0.30
25
+ Provides-Extra: dev
26
+ Requires-Dist: pytest-asyncio>=0.23; extra == 'dev'
27
+ Requires-Dist: pytest>=8; extra == 'dev'
28
+ Requires-Dist: respx>=0.21; extra == 'dev'
29
+ Description-Content-Type: text/markdown
30
+
31
+ # AgentCap
32
+
33
+ **Stop Claude Code and Codex runs that loop or eat your weekly quota.** AgentCap stops a run
34
+ that repeats the same tool call or keeps failing, and stops a job at its share of your
35
+ Claude Max/Pro or ChatGPT weekly / 5-hour quota, with an evidence receipt of why. Free
36
+ `agentcap waste` shows where your tokens already went: subagents, Opus, cache misses,
37
+ tool loops and error streaks.
38
+
39
+ ```text
40
+ $ agentcap waste --since 7d
41
+ SUBAGENTS $41.20 25% of spend in 31 subagent/forked threads
42
+ OPUS $38.90 24% of spend
43
+ CACHE MISSES $6.10 57 cache re-writes after the TTL ran out (5 min, or 1 h)
44
+ REPEATED TOOL CALLS $9.80 12 streaks of >= 3 identical calls in a row
45
+ TOOL ERROR STREAKS $4.30 5 streaks of >= 3 failing calls in a row
46
+ Pro would have stopped this run at $3.12 / at 4 repeats (Bash x11 in 7f3a91c2, $2.40 after that).
47
+ ```
48
+ *(illustrative numbers; run it on your own logs, it is read-only)*
49
+
50
+ ## Stop loops and quota burn (Pro)
51
+
52
+ ```bash
53
+ agentcap run --quota 5% -- claude # subscription: stop at 5% of the weekly quota, or on a loop
54
+ agentcap run --quota 10% --window 5h -- codex # same for Codex on a ChatGPT plan
55
+ agentcap run --cap 2 -- codex exec "fix tests" # API key: $2 cap + loop/burn breaker
56
+ ```
57
+
58
+ - **Loop breaker.** Same tool call (name + input) 4 times in a row, or 8 failing tool calls in a
59
+ row: the run is stopped (exit 4). On subscriptions it works without touching your login or
60
+ traffic: Claude Code via an official `PreToolUse` hook (denies the 4th identical call, then
61
+ SIGINT if the agent keeps going); Codex by reading its own rollout file (SIGINT). On API keys the
62
+ proxy also catches identical requests and `--max-burn` $/min spikes.
63
+ - **Per-job quota %.** Stop one job at its share of the account's weekly or 5-hour limit.
64
+ - **Evidence receipt.** Each stop prints and saves why (`same tool call 4 times in a row (Bash)`,
65
+ `this job used 5.1% of the weekly quota`) as numbers only, never prompts.
66
+ - **Free** runs the same detectors in observe-only mode and prints what Pro would have done.
67
+
68
+ Honest limits: Claude tool-error streaks are only caught on API-key runs (the subscription hook sees
69
+ the call, not its result); the stop can be one request late; quota % is account-level; verified on
70
+ fixtures, fake CLIs and real Claude Code 2.1.197 hooks, **not yet on a real Max/ChatGPT account.**
71
+
72
+ ## The API-key cap
73
+
74
+ AgentCap runs
75
+ the CLI behind a local proxy on `127.0.0.1` and applies a local spend cap to the
76
+ run. Before each request it reserves the worst-case cost; when the budget is gone
77
+ it kills the local process and tells you why. No dashboard, no account, no code
78
+ changes for tools that honour a base-URL environment variable.
79
+
80
+ Claude Code and Codex CLI are routed automatically (Gemini CLI too). AgentCap meters API-key
81
+ traffic — `POST /v1/responses` and `/v1/chat/completions` (Codex CLI uses the
82
+ Responses API) plus Gemini `generateContent` / `streamGenerateContent` and Anthropic `POST /v1/messages`. ChatGPT
83
+ or Google sign-in (OAuth/subscription) traffic is not metered.
84
+
85
+ ## What it is
86
+
87
+ AgentCap is a small, local, serverless spend-cap proxy. You give it a command
88
+ and a cap:
89
+
90
+ ```bash
91
+ agentcap run --cap 2 -- codex exec "fix the failing tests"
92
+ ```
93
+
94
+ Everything the child sends to OpenAI or Gemini is routed through a proxy on
95
+ `127.0.0.1`. AgentCap reserves the worst-case cost of each request before it is
96
+ forwarded, settles the real usage afterwards, and terminates the agent's process
97
+ group if the cap would be exceeded. This is a local spend cap, not a
98
+ mathematical guarantee: with conservative reservation it reserves worst-case
99
+ cost before each request, so overshoot is rare but possible when providers count
100
+ more tokens than estimated.
101
+
102
+ ![agentcap demo (simulated: fake local API, no real money)](https://raw.githubusercontent.com/Blitz00X/agentcap/main/docs/demo.gif)
103
+
104
+ *Simulated demo — fake local API, no key, no money.*
105
+
106
+ ## Install
107
+
108
+ The package is published on PyPI as `agentcap-cli` (the name `agentcap` is
109
+ taken), but the command it installs is still `agentcap`.
110
+
111
+ ```bash
112
+ # install the command globally
113
+ pipx install agentcap-cli
114
+
115
+ # or into the current environment
116
+ pip install agentcap-cli
117
+ ```
118
+
119
+ No pipx? macOS: `brew install pipx && pipx ensurepath`; Linux: `python3 -m pip install --user pipx && python3 -m pipx ensurepath`.
120
+
121
+ From a checkout:
122
+
123
+ ```bash
124
+ uv venv .venv
125
+ uv pip install -e .
126
+
127
+ # or install this checkout as the global command
128
+ pipx install .
129
+ ```
130
+
131
+ ## Install in VS Code / Cursor
132
+
133
+ The **AgentCap** editor extension (0.2.0) starts Claude Code or Codex in an
134
+ integrated terminal behind `agentcap run --cap`, shows live run spend in the
135
+ status bar, warns at 80% / 95%, and shows a modal when the cap (exit 3) or Pro's
136
+ loop breaker (exit 4) stops the run. It needs the `agentcap` CLI above.
137
+
138
+ It is **not on the VS Code Marketplace or Open VSX yet**. Install the `.vsix`
139
+ attached to the [GitHub release](https://github.com/Blitz00X/agentcap/releases):
140
+
141
+ ```bash
142
+ code --install-extension agentcap-0.2.0.vsix # VS Code
143
+ cursor --install-extension agentcap-0.2.0.vsix # Cursor
144
+ ```
145
+
146
+ or *Extensions → … → Install from VSIX…*. Then run **AgentCap: Start Codex
147
+ with cap** (or Claude Code) from the command palette; set the cap with
148
+ **AgentCap: Set cap**.
149
+
150
+ ![AgentCap stopping a fake Codex run at a $0.20 cap in VS Code](landing/vscode-demo.gif)
151
+
152
+ *Real VS Code recording; the agent is a fake Codex script talking to AgentCap's
153
+ local fake upstream, so no real API call or spend is involved.*
154
+
155
+ ## Quickstart
156
+
157
+ ```bash
158
+ # Codex CLI under a $2 cap (API-key mode: uses OPENAI_API_KEY)
159
+ agentcap run --cap 2 -- codex exec "fix the failing tests"
160
+
161
+ # Gemini CLI under a $2 cap (API-key mode: uses GEMINI_API_KEY)
162
+ agentcap run --cap 2 -- gemini -p "refactor utils.py"
163
+
164
+ # Gemini CLI in a folder you have not trusted yet
165
+ agentcap run --cap 2 --trust-workspace -- gemini -p "refactor utils.py"
166
+
167
+ # Run your own Python agent (it must honour OPENAI_BASE_URL)
168
+ agentcap run --cap 1 -- python my_agent.py
169
+
170
+ # Keep a proxy open for several terminals
171
+ agentcap serve --port 8787 --cap 5
172
+
173
+ # Simulated, fully local demo (fake API, no key, no money)
174
+ agentcap demo
175
+
176
+ # Inspect spend
177
+ agentcap status --port 8787
178
+ agentcap status --db
179
+
180
+ # Inspect the bundled price table
181
+ agentcap pricing
182
+ agentcap pricing google/gemini-4-argon
183
+ ```
184
+
185
+ Uses your API key (`OPENAI_API_KEY` / `GEMINI_API_KEY`). ChatGPT or Google
186
+ sign-in (OAuth/subscription) traffic is not metered.
187
+
188
+ `agentcap run` accepts `--cap` (default `$5`, or `$AGENTCAP_CAP`),
189
+ `--hour-cap` / `--day-cap` and `--max-burn` (Pro), `--allow-unmetered`, `--no-clamp`, `--port`,
190
+ `--trust-workspace` and `--quiet`.
191
+
192
+ ### CLI routing
193
+
194
+ - **Codex CLI 0.163** ignores `OPENAI_BASE_URL`, so AgentCap passes
195
+ `-c model_provider=agentcap` and a `model_providers.agentcap` block (Responses
196
+ API over HTTP, websockets disabled) right after the executable. If your command
197
+ already sets `model_provider`, `model_providers.*` or `openai_base_url` with
198
+ `-c`/`--config`, AgentCap refuses to start (exit code 2) rather than let
199
+ traffic bypass the proxy.
200
+ - **Gemini CLI 0.58–0.66** needs an auth type in headless mode, and from 0.60 it
201
+ also refuses system settings files that are not root-owned. AgentCap therefore
202
+ runs Gemini with a temporary `GEMINI_CLI_HOME`: its `.gemini` directory links
203
+ your real entries (history, `trustedFolders.json`, credentials) and holds a
204
+ copied `settings.json` with the auth type forced to `gemini-api-key`. The
205
+ overlay is removed afterwards; nothing in your real `~/.gemini` is modified.
206
+ `--trust-workspace` adds `GEMINI_CLI_TRUST_WORKSPACE=true` for Gemini.
207
+ - `npx @openai/codex ...` and `npx @google/gemini-cli ...` are recognised too.
208
+
209
+ Add `--trust-workspace` for Gemini CLI runs in folders you have not trusted yet;
210
+ without it, headless Gemini may refuse the workspace.
211
+
212
+ At the end of a run AgentCap warns **“no model requests observed — protection
213
+ not verified”** if the proxy saw no model traffic. That means the agent may have
214
+ bypassed the proxy, so check the command and auth mode.
215
+
216
+ ## Claude Code (new in 0.1.5)
217
+
218
+ ```bash
219
+ export ANTHROPIC_API_KEY=sk-ant-...
220
+ agentcap run --cap 3 -- claude -p "fix the failing tests"
221
+ # Pro: agentcap run --cap 3 --hour-cap 10 --day-cap 25 -- npx @anthropic-ai/claude-code -p "..."
222
+ ```
223
+
224
+ AgentCap points Claude Code at its local proxy (`ANTHROPIC_BASE_URL=http://127.0.0.1:<port>/anthropic`)
225
+ and meters every `POST /v1/messages`, streamed or not:
226
+
227
+ - Prices come from Anthropic's published table (docs.claude.com pricing, checked 2026-10-30):
228
+ input, cache reads, 5-minute cache writes (1.25x input), 1-hour cache writes (2x input) and output.
229
+ Thinking tokens are billed as output and are covered by `max_tokens`.
230
+ - Before a request goes out, AgentCap reserves its worst case (`max_tokens` of output, all prompt
231
+ tokens as 1-hour cache writes). If that does not fit the remaining budget it lowers `max_tokens`
232
+ (and a manual thinking budget) or refuses the request. It never raises a limit.
233
+ - Unknown models, unknown `inference_geo` values and fast mode (`speed: "fast"`, not priced yet) are
234
+ blocked (fail-closed). `inference_geo: "us"` is charged at 1.1x.
235
+ - `count_tokens` and `GET /v1/models` pass through for free. Other Anthropic endpoints are blocked
236
+ unless you pass `--allow-unmetered`.
237
+ - AgentCap refuses to start Claude Code when `CLAUDE_CODE_USE_BEDROCK`, `_VERTEX` or `_FOUNDRY` is set,
238
+ or when a Claude settings file sets its own `ANTHROPIC_BASE_URL` in `env`. Those would send
239
+ traffic around the cap.
240
+
241
+ Limits:
242
+
243
+ - With a Claude subscription login instead of an API key, the cap counts API-list-price
244
+ equivalents, not your plan's billing.
245
+ - Costs are estimates from provider-reported usage. Your Anthropic invoice is authoritative.
246
+ - A large first request needs a cap that fits it. Claude Code's first request often reserves
247
+ about $0.50–$1. AgentCap prints a suggested `--cap` when it refuses one.
248
+
249
+ ## Install as a Claude Code plugin (Max / Pro subscriptions)
250
+
251
+ The easiest path on a Claude Max or Pro plan. Inside Claude Code:
252
+
253
+ ```
254
+ /plugin marketplace add Blitz00X/agentcap
255
+ /plugin install agentcap@agentcap
256
+ /agentcap:setup # once: adds AgentCap's read-only statusLine (your own line keeps showing)
257
+ /agentcap:quota 5% # this session may use 5% of the weekly quota (`2% 5h` for the 5-hour window)
258
+ /agentcap:status # session 3.1% / 5% (weekly)
259
+ /agentcap:off # clear it; /agentcap:unsetup restores your old statusLine
260
+ ```
261
+
262
+ No pip install: the plugin is stdlib Python (`python3` on PATH). How it works:
263
+
264
+ - Claude Code only exposes the subscription `rate_limits` % to the **statusLine** command, and a
265
+ plugin can't set the main statusLine. So `/agentcap:setup` asks once and writes it to
266
+ `~/.claude/settings.json` (backup `settings.json.agentcap-backup`, previous line chained,
267
+ `/agentcap:unsetup` undoes it).
268
+ - Plugin hooks: `PreToolUse` warns at 80% and, on **Pro**, denies tool calls at the limit;
269
+ `Stop` prints a receipt (`session 4.2% / 5% (weekly)`). **Free:** live meter + one notice
270
+ at the limit (`Pro would stop the agent here`). Pro is read from the licence the `agentcap`
271
+ CLI stores after `agentcap license activate` (paste the key at the hidden prompt).
272
+ - Loop breaker (works with or without `/agentcap:quota`): `PreToolUse` hashes each tool call
273
+ (name + input, per session and per subagent; polling tools like `TaskOutput`/`BashOutput`
274
+ are ignored). The 4th identical call in a row is denied with `continue: false` on **Pro**;
275
+ **Free** gets one notice per streak. `PostToolUse` / `PostToolUseFailure` count failing
276
+ tool calls: 8 in a row stops the agent on Pro (`continue: false`), Free gets a notice.
277
+ Tool input and output are never stored, only a 16-char hash and counts; these per-session
278
+ files are deleted after 7 days (on `SessionStart`).
279
+ - Read-only: no OAuth token, credentials file or API traffic is touched.
280
+
281
+ Honest limits: the % is account-level (parallel sessions count), the stop can be one request
282
+ late, and the share updates when the statusLine refreshes. Verified with real Claude Code
283
+ 2.1.197 (plugin install from the marketplace, hooks loaded, `/agentcap:quota` executed,
284
+ PreToolUse deny blocked the tool) against a local fake API and synthetic `rate_limits`;
285
+ **not yet checked against a real Max account.**
286
+
287
+ ## Works with Claude Max / ChatGPT subscriptions (quota mode)
288
+
289
+ On a subscription there is no dollar bill, but there is a weekly and a 5-hour usage limit.
290
+ Quota mode caps **one job's share** of it:
291
+
292
+ ```bash
293
+ agentcap run --quota 5% -- claude # stop this job after 5% of the weekly quota
294
+ agentcap run --quota 10% --window 5h -- codex # or 10% of the 5-hour window
295
+ agentcap quota # read-only: last seen usage (Free)
296
+ ```
297
+
298
+ - **Read-only, ToS-safe.** AgentCap never proxies, reads or reuses your subscription login
299
+ or tokens, and never touches subscription traffic. The official, unmodified CLI talks to
300
+ Anthropic/OpenAI directly.
301
+ - **Claude Code:** for this run only, AgentCap adds a settings layer with `claude --settings <file>`
302
+ (your `~/.claude/settings.json` and project settings are never edited). It contains a
303
+ statusline command that records the official `rate_limits` (`five_hour` / `seven_day`
304
+ `used_percentage`, `resets_at`) and then runs **your own statusline command unchanged**,
305
+ plus a `PreToolUse` hook that denies further tool calls with a clear reason once the job's
306
+ share reaches the limit. If the agent does not stop, AgentCap sends it SIGINT. Exit code 3.
307
+ - **Codex CLI:** AgentCap tails the `token_count` events Codex writes to
308
+ `~/.codex/sessions/**/rollout-*.jsonl` (`rate_limits.primary/secondary.used_percent`,
309
+ `window_minutes`, `resets_at`) and sends SIGINT at the limit. Exit code 3.
310
+ - Baseline at job start (exact when a reading from the last 15 minutes exists, otherwise the
311
+ first response is not counted), window resets mid-job are handled, 80% warning,
312
+ per-job receipt: `this job used 4.2% of the weekly quota`. Pro alerts (Telegram/webhook)
313
+ and receipt files work the same as for dollar caps.
314
+ - **Free:** `agentcap quota` and observe-only runs that print the job's share and
315
+ `Pro's quota mode would have stopped this job at 5%`. **Pro:** stopping at the limit.
316
+
317
+ **Honest limits.** The percentage is **account-level**: a parallel session or claude.ai/chatgpt.com
318
+ use in the same window counts against the job (AgentCap warns when it sees another session).
319
+ Values arrive once per model response, so a job **can overshoot by up to one request**.
320
+ Claude Code only reports `rate_limits` for Pro/Max logins and only in interactive sessions
321
+ (the statusline does not run in `claude -p`). Codex's rollout format is undocumented and may change.
322
+ **Verified so far on fixtures and fake CLIs only** (plus real Claude Code 2.1.197: the `--settings`
323
+ layer, the chained statusline and the `PreToolUse` deny were checked against a local fake API);
324
+ a check on a real Max / ChatGPT account is still pending.
325
+
326
+ ## Try it without an API key
327
+
328
+ `agentcap demo` is a simulated demo. It starts a fake API on a random loopback
329
+ port, runs a tiny child against it with a 5-cent cap, and prints `(simulated)` at
330
+ the end. It needs no API key, makes no real provider calls, and works from a
331
+ plain `pipx install agentcap-cli`. Exit code `3` means the cap stopped the child.
332
+
333
+ ### Simulated demo (fake local API, no real money)
334
+
335
+ ```text
336
+ $ agentcap demo
337
+ SIMULATED DEMO — fake local API, no real provider, no real money. Dollar amounts are simulated.
338
+ agentcap [run-3bc1257940cb]: 50% of the $0.05 run cap used ($0.0252).
339
+ agentcap [run-3bc1257940cb]: 80% of the $0.05 run cap used ($0.0408).
340
+ agentcap [run-3bc1257940cb]: budget low, limiting output to 15303 tokens per request
341
+ agentcap [run-3bc1257940cb]: RUN CAP HIT (scope=run, cap=$0.05, spent=$0.0499). Stopping the agent.
342
+ agentcap run summary
343
+ run id: run-3bc1257940cb
344
+ requests: 44
345
+ refused requests: 2
346
+ spent: $0.0500
347
+ cap: $0.05
348
+ reserved-but-unsettled: $0.0000
349
+ clamped requests: 8
350
+ reason: cap_exceeded
351
+ exit code: 3
352
+ (simulated)
353
+ ```
354
+
355
+ From a checkout, `python -m agentcap.devtools.fake_upstream --port 9000` still
356
+ starts the bundled fake upstream on loopback for manual metering experiments; the
357
+ test suite uses `httpx.MockTransport` and never calls the network.
358
+
359
+ ## Supported & tested
360
+
361
+ | Tool | Verified version | Command and auth | Routing |
362
+ | --- | --- | --- | --- |
363
+ | Codex CLI | 0.163 | `codex exec "…"` with `OPENAI_API_KEY`; ChatGPT sign-in is not metered. | Automatically, via an injected custom provider (`-c model_provider=agentcap …`). |
364
+ | Gemini CLI | 0.58–0.66 | `gemini -p "…"` with `GEMINI_API_KEY`; Google sign-in is not metered. | Automatically, via a temporary `GEMINI_CLI_HOME` overlay (your `~/.gemini` is linked, its `settings.json` is copied with the auth type forced to `gemini-api-key`; nothing in `~/.gemini` is modified). Add `--trust-workspace` to `agentcap run` for untrusted folders. |
365
+ | Claude Code | 2.1.197 | `claude -p "…"` with `ANTHROPIC_API_KEY`; Claude subscription sign-in is not metered. | Automatically, via `ANTHROPIC_BASE_URL`. Tested end-to-end against a local fake Anthropic API only (not against Anthropic billing yet). |
366
+ | Your own script | Any | Uses the OpenAI or Gemini SDK with base-URL environment variables. | No code changes: AgentCap sets `OPENAI_BASE_URL`, `GOOGLE_GEMINI_BASE_URL` and `ANTHROPIC_BASE_URL`. |
367
+
368
+ Tested with a real Gemini API key on Gemini CLI 0.66 (spend metered from Google's
369
+ usageMetadata, output clamped to the cap). Codex CLI 0.165 verified against real
370
+ OpenAI-compatible upstreams: Ollama Cloud (gpt-oss:20b) and OpenRouter (free model
371
+ poolside/laguna-s-2.1:free via the Responses API) — real responses, ledger token counts
372
+ matched OpenRouter's reported usage exactly, cap stop with exit 3; not against OpenAI
373
+ billing. Gemini CLI 0.58 and Codex CLI 0.163 are tested end-to-end against a local fake API only.
374
+
375
+ Models without a bundled price (for example OpenRouter or Ollama ids) are blocked until you add a price via `AGENTCAP_PRICING_FILE`.
376
+
377
+ **Platforms:** Linux and macOS. Windows: not yet (use WSL2).
378
+
379
+ ## How it works
380
+
381
+ 1. `agentcap run` starts the proxy on a random free port, bound **only** to
382
+ `127.0.0.1`, and waits for `/_agentcap/status`.
383
+ 2. The child process is started in its own process group with:
384
+
385
+ ```text
386
+ OPENAI_BASE_URL=http://127.0.0.1:PORT/openai/v1
387
+ GOOGLE_GEMINI_BASE_URL=http://127.0.0.1:PORT/gemini
388
+ GEMINI_API_BASE_URL=http://127.0.0.1:PORT/gemini
389
+ AGENTCAP_RUN_ID=...
390
+ AGENTCAP_PROXY=http://127.0.0.1:PORT
391
+ ```
392
+
393
+ 3. Before forwarding a request, the proxy estimates the prompt size and the
394
+ maximum output size, then atomically reserves that worst-case USD amount in
395
+ a local SQLite ledger. The input estimate is padded by a conservative
396
+ `input_safety_factor` (1.25 by default) to cover system prompts, tool
397
+ schemas, images and tokenizer differences that the local estimate cannot
398
+ see. Concurrent requests reserve against the same budget.
399
+ 4. After the upstream responds, the real usage is parsed and the reservation is
400
+ settled to the actual cost (rounded up to the micro-dollar). Settlement uses
401
+ the provider's reported tokens, never the padded estimate. If the provider
402
+ bills more input tokens than estimated, that one settlement can exceed its
403
+ reservation; AgentCap emits an `overshoot` alert and the run's spend may end
404
+ slightly above the cap.
405
+ 5. If the worst case does not fit the remaining budget but the prompt itself
406
+ does, the proxy **clamps the output limit** to exactly what fits (at least
407
+ `256` tokens by default) and reserves only that amount. The agent keeps
408
+ running; real usage still settles the reservation. Clamping is on by default
409
+ and can be disabled with `--no-clamp`.
410
+ 6. If even a minimal clamped request cannot fit, the request is blocked and the
411
+ whole child process group is terminated (`SIGTERM`, then `SIGKILL` after
412
+ 5s). `agentcap run` exits with code `3`. Pro's loop/burn breaker exits
413
+ with `4` (same step 4 times in a row, 8 failing tool results in a row, or a
414
+ burn rate above `--max-burn` $/min; see Free vs Pro).
415
+ The kill and its red alert fire at most once per run; later rejected
416
+ requests just receive `429` responses.
417
+ 7. Unknown models and unparseable bodies are rejected (fail-closed); the request
418
+ is never forwarded unmetered.
419
+
420
+ The proxy makes only two kinds of request-body change: it adds
421
+ `stream_options.include_usage` to OpenAI Chat Completions streams so final
422
+ usage is available, and (unless `--no-clamp` is given) it lowers the request's
423
+ output limit when the worst-case reservation would cross the remaining budget.
424
+ For OpenAI that is `max_completion_tokens` (or the legacy `max_tokens` if the
425
+ body already used it) or `max_output_tokens` for the Responses API; for Gemini
426
+ it is `generationConfig.maxOutputTokens`. An existing smaller limit is never
427
+ raised. Everything else is forwarded byte-for-byte, including credentials.
428
+
429
+ Reasoning/thinking tokens are billed as output and count against the same
430
+ output limit, so a clamp also caps them.
431
+
432
+ ## Metered endpoints
433
+
434
+ | Provider | Endpoints |
435
+ | --- | --- |
436
+ | OpenAI | `POST /v1/chat/completions`, `/v1/responses`, `/v1/completions`, `/v1/embeddings` |
437
+ | Gemini | `generateContent`, `streamGenerateContent` (other Gemini endpoints pass through) |
438
+
439
+ Token counting (`countTokens`) and `GET` requests are free passthroughs.
440
+ Request bodies are billed at price-book rates; embeddings are input-only.
441
+
442
+ ## Limitations
443
+
444
+ - Tools that AgentCap can route (Codex CLI, Gemini CLI) or that honour
445
+ `OPENAI_BASE_URL` / `GOOGLE_GEMINI_BASE_URL` and send API keys can be metered.
446
+ OAuth or subscription logins are **not** metered.
447
+ - Prices are a local table, not a live feed. Check them with
448
+ `agentcap pricing`; override any entry in
449
+ `~/.config/agentcap/pricing.json` (or `$AGENTCAP_PRICING_FILE`).
450
+ - The proxy rewrites a request only to add `stream_options.include_usage` to
451
+ OpenAI chat streams and, unless `--no-clamp` is set, to lower its output
452
+ limit to what the remaining budget can afford. Prompts are never changed.
453
+ - Estimates are deliberately conservative, so a reservation can be larger than
454
+ the eventual cost. The cap is enforced before each request with a worst-case
455
+ reservation and concurrent requests reserve against the same budget. This is
456
+ not a mathematical guarantee: if a provider bills more input tokens than
457
+ estimated (for example server-side system prompts, tool schemas, images or
458
+ tokenizer differences), the final spend can exceed the cap by that one
459
+ request's estimation error. AgentCap emits an `overshoot` alert when a
460
+ settlement exceeds its reservation.
461
+ - The ledger lives at `~/.local/share/agentcap/ledger.sqlite3`
462
+ (override with `$AGENTCAP_DB`).
463
+
464
+ ## Privacy
465
+
466
+ Prompts and keys pass through the local proxy in memory; AgentCap never stores
467
+ or uploads them. Free sends nothing anywhere. Pro sends alert metadata (run id,
468
+ spend, reason) only to webhook/Telegram destinations you configure, and
469
+ validates your licence key with Polar about once a week.
470
+
471
+ The ledger keeps token counts, costs, model names, timestamps and request
472
+ hashes — never prompts, response contents, API keys or Authorization headers.
473
+
474
+ **Pro licence checks:** activating a Pro key (and the periodic re-check) sends
475
+ only the licence key, the Polar organization id and an anonymous machine
476
+ fingerprint hash (SHA-256; it contains no hostname and no username) to Polar's
477
+ public licence API at `api.polar.sh`. Free users make no licence requests at
478
+ all.
479
+
480
+ ## `agentcap waste` and usage history (Free, new in 0.2)
481
+
482
+ ```bash
483
+ agentcap waste # subagent + Opus share, cache misses, tool loops, error streaks ($ each)
484
+ agentcap report --by agent # session -> subagent tree with $ and Opus share
485
+ agentcap import # read-only: ~/.claude/projects, ~/.codex/sessions, AgentCap's ledger
486
+ agentcap report --by day # Free: day | session | model | project, tokens + API-equivalent $
487
+ agentcap report --by model --since 7d --csv
488
+
489
+ agentcap budget set --task-usd 2 --day-usd 20 --task-quota 5% --window 5h
490
+ agentcap run -- codex exec "..." # uses the $2 task cap from the budget
491
+ agentcap run --quota -- claude # uses the 5% / 5h quota from the budget
492
+ ```
493
+
494
+ - **Store:** `~/.local/share/agentcap/usage.db` (`$XDG_DATA_HOME` respected, mode 600). `import` is
495
+ idempotent; it reads only `*.jsonl` session logs and AgentCap's own files. It never opens auth or
496
+ credential files, never stores prompt or response text, and never touches network or OAuth traffic.
497
+ Unknown or changed log lines are skipped and counted, not fatal.
498
+ - **Budget:** one file, `~/.config/agentcap/budget.json`. Scopes: task (one `agentcap run` = one agent
499
+ session) in $, hour/day across runs in $ (Pro), and per-job % of the subscription quota (Pro stops).
500
+ A flag or `AGENTCAP_CAP` always beats the budget. On Free, a budget hour/day cap is ignored with a note.
501
+ - **Early warning:** when the current burn rate would hit the run cap within ~10 minutes, AgentCap
502
+ prints (and on Pro sends) one `cap_eta` alert: "cap is hit in ~N min".
503
+ - **$ is API-equivalent:** what the same tokens would cost at list API prices — not your subscription bill.
504
+ - **Subagents:** Claude Code `<session>/subagents/agent-*.jsonl` and `isSidechain` lines; Codex
505
+ `session_meta` `source.subagent.thread_spawn.parent_thread_id` and `forked_from_id`. These formats
506
+ are undocumented and change between CLI versions.
507
+ - **`waste` heuristics:** a cache miss is a cache write larger than the cache read after the prompt
508
+ cache TTL ran out (5 min; 1 h when written with `ephemeral_1h`; Codex: a big uncached prompt after
509
+ > 5 min idle). Tool inputs are hashed, never printed. Not in local logs: `agent_summary` / title
510
+ background calls and HTTP retries (planned: local OTel receiver).
511
+
512
+ ### Pro extras: analytics (`agentcap report <view>`)
513
+
514
+ | view | what you get |
515
+ | --- | --- |
516
+ | `forecast` | 5h / weekly quota: "limit hits at Tue 14:20 (~1.5h)", with an early-warning mark |
517
+ | `calibration` | "this week 1% of quota = 1.4M tokens ≈ $1.49", tracked per reset period so you can see if your limit shrank |
518
+ | `savings` | cache-write waste ($ of cache writes never read) and API-vs-plan breakeven with a plan recommendation (plan prices: `agentcap/plans.py`, override in `~/.config/agentcap/plans.json`) |
519
+ | `receipts` | per job / session / repo receipts, `--csv` export, plus AgentCap run receipts |
520
+
521
+ Calibration pairs quota % samples (Codex `rate_limits` in rollouts; Claude statusline readings recorded
522
+ during `agentcap run --quota`) with the tokens imported in the same window. It is an estimate; small %
523
+ steps are noisy. No team aggregation: everything stays on your machine.
524
+
525
+ ## Free vs Pro (0.2)
526
+
527
+ **Free (MIT License, forever):** the per-run spend cap.
528
+ - Per-run `--cap` (`--hour-cap` / `--day-cap` exit 2 on Free with a clear message)
529
+ - Output clamping, fail-closed metering, terminal alerts
530
+ - Claude Code, Codex, any SDK script (and Gemini CLI)
531
+ - `agentcap waste`, `agentcap report --by agent` (subagent tree), `agentcap import`, `agentcap report` by day/session/model/project, `agentcap budget`, the `cap_eta` early warning
532
+
533
+ When the Pro detectors below would have fired on a Free run, AgentCap does not stop it.
534
+ It prints one line: `Pro's loop breaker would have stopped this at $X.XX`.
535
+
536
+ **Pro, $12 one-time (launch week, until 10 Nov; then $19): stop runs that loop or eat your quota.**
537
+
538
+ **Get Pro:** buy at https://agentcap.launchbench.studio/#pricing (Polar checkout). Polar then
539
+ emails you an **Access purchase** link; the key is in the Polar customer portal (not in the
540
+ email body). Run `agentcap license activate`, paste the key at the hidden prompt, and check `agentcap license
541
+ status` (`tier: pro`). One key works on up to 3 machines; `agentcap license deactivate` frees one.
542
+ The VS Code/Cursor extension and the Claude Code plugin use the same CLI licence.
543
+
544
+ - **Subscription quota mode + loop breaker:** `agentcap run --quota 5% -- claude|codex` stops a job at
545
+ its share of your Claude Max/Pro or ChatGPT quota, or when it repeats the same tool call 4 times /
546
+ fails 8 tool calls in a row (see above).
547
+ - **API-key loop/burn breaker:** stops the agent (exit 4) before the next request is sent when
548
+ (a) the same step repeats 4 times in a row (the last tool call + its result, normalised;
549
+ the growing conversation history is ignored), (b) 8 consecutive tool results are errors, or
550
+ (c) spend exceeds `--max-burn` USD/minute over a rolling 2-minute window (default `2.00`,
551
+ `--max-burn off` disables). Byte-identical repeats are still caught too.
552
+ - **Hour and day caps:** cross-run `--hour-cap` and `--day-cap`.
553
+ - **Phone and webhook alerts:** Telegram (`AGENTCAP_TELEGRAM_BOT_TOKEN`, `AGENTCAP_TELEGRAM_CHAT_ID`)
554
+ and webhook (`AGENTCAP_WEBHOOK_URL`) alerts for cap hits, loop kills and the end-of-run receipt.
555
+ Tokens are read from the environment and are never printed or logged.
556
+ - **Extras — usage analytics:** `agentcap report forecast | calibration | savings | receipts` (see above).
557
+ - **Spend receipt:** a JSON file per run (`~/.local/state/agentcap/receipts/<run>.json`, or
558
+ `AGENTCAP_RECEIPT_DIR`) with requests, spend, caps, the stop reason and the exit code. It contains
559
+ numbers only, never prompts. The same one-line receipt is sent to Telegram and the webhook.
560
+
561
+ [Buy AgentCap Pro — $12 launch week](https://buy.polar.sh/polar_cl_qagsvUdwQ0dRvaW7X5ynEJg5md27pEctIRAr40MBeLi)
562
+
563
+ ### Purchase terms
564
+
565
+ - Pro is $12 one-time (launch week, until 10 Nov; then $19), no subscription.
566
+ - 14-day no-questions refund — email
567
+ [kutaykarahan6@gmail.com](mailto:kutaykarahan6@gmail.com).
568
+ - One licence key activates on up to 3 machines.
569
+ - The key is checked with Polar about once a week.
570
+ - If the licence server is unreachable your Pro keeps working (fail-open); only
571
+ an explicit Polar rejection of a refunded or revoked key downgrades it.
572
+ - If AgentCap is discontinued, Pro keeps working and you can ask for a refund
573
+ within 14 days of purchase.
574
+ - The Free tier (per-run cap) needs no key and makes no network calls.
575
+
576
+ After purchase you receive a licence key by email (via Polar). Activate it with
577
+ `agentcap license activate` (paste the key at the hidden prompt). `agentcap license deactivate` asks the
578
+ license server to release this activation (freeing the slot for another
579
+ machine) and then removes the local license; if the server cannot be reached the
580
+ local license is kept and the command exits 1 so you can retry. Use
581
+ `agentcap license deactivate --local-only` to remove just the local file — the
582
+ activation then still counts toward your 3 machines until you release it in the
583
+ Polar customer portal.
584
+
585
+ ## How it compares
586
+
587
+ | Tool | What it does and how it enforces a cap |
588
+ | --- | --- |
589
+ | RelayPlane | [relayplane.com](https://relayplane.com): free, MIT-licensed local proxy with daily/hourly/per-request/per-run caps, routing and a kill switch. It enforces budgets at the proxy — blocking or warning on breach — and is aimed at Anthropic/OpenAI chat routing. A good fit for gateway-style setups. |
590
+ | LoopGuard | [tryloopguard.com](https://tryloopguard.com): free MIT CLI that integrates with Claude Code, Codex CLI and Cursor (no proxy, works with subscriptions) with per-session/daily caps and a no-progress loop killer; paid tier ($9/month) adds phone/Slack alerts and remote pause. A good fit if you use subscriptions or Claude Code. |
591
+ | LiteLLM budgets | Budgets per key, user or team in the LiteLLM proxy; budgets need its database. A good fit if you already run a LiteLLM gateway; it is a server you deploy and configure. |
592
+ | OpenRouter credit limits / provider spend caps | Account- or key-level and typically monthly (OpenRouter credit limits, OpenAI and Google spend caps). Provider caps are evaluated with a delay — Google has described about 10 minutes for the Gemini API cap — so a fast loop can overshoot. |
593
+ | AgentCap | Local proxy for API-key traffic from Claude Code, Codex CLI, Gemini CLI or your own script: run cap (Free) with conservative reservation and output clamping, kills the process group at the cap and prints why. Pro (unattended pack): hour/day caps, loop/burn breaker, Telegram/webhook alerts, spend receipt, $19 one-time. |
594
+
595
+ The comparison above is from public pages; see the RelayPlane detail below.
596
+
597
+ ## AgentCap vs RelayPlane
598
+
599
+ RelayPlane is a good tool. If it fits you, use it. The facts below come from RelayPlane's own
600
+ website as of 2026-10-30. We have not tested RelayPlane hands-on.
601
+
602
+ | | RelayPlane (per its site) | AgentCap |
603
+ |---|---|---|
604
+ | License | MIT | MIT License (the whole open-source CLI; Pro features are unlocked by a paid licence key) |
605
+ | Per-run / session / hour / day caps | Free | Run cap Free; hour/day caps Pro |
606
+ | Kill switch | Yes | Yes. Stops the agent's process group (exit 3) |
607
+ | Over-budget response | HTTP 429 `budget_exceeded` | HTTP 429, and the request is never sent |
608
+ | Output reservation | Capped at 4096 output tokens | Full `max_tokens` worst case, plus clamping to fit |
609
+ | Loop breaker | Not listed on their site | Pro |
610
+ | Telegram / webhook alerts, spend receipt | Not listed on their site | Pro |
611
+
612
+ The difference that matters for runaway bills: AgentCap reserves the worst case each request
613
+ can cost before sending it, so a single long response cannot overshoot the cap.
614
+
615
+ Pick what matches your setup — these tools can also be combined.
616
+
617
+ ## FAQ
618
+
619
+ **Does clamping output hurt quality?** Yes, it can: when the budget is tight
620
+ AgentCap lowers max output tokens so the call fits; answers can be shorter or
621
+ cut off. Use `--no-clamp` to refuse instead.
622
+
623
+ **Does stopping roll back what the agent did?** No. At the cap AgentCap sends
624
+ SIGTERM then SIGKILL; files or remote changes already made stay. Use git / small
625
+ steps.
626
+
627
+ **Is the ledger my provider bill?** No. It is a local estimate from published
628
+ prices and reported usage; when usage is missing it charges the full reservation
629
+ (conservative). Your provider invoice is authoritative.
630
+
631
+ **Is the day cap shared across machines?** No. Hour/day caps are per machine
632
+ (local SQLite ledger). A license covers 3 machines, each with its own budget.
633
+
634
+ **What does one-time purchase include?** $12 once in launch week ($19 after 10 Nov), all 0.x updates; not a
635
+ promise of future major versions. 14-day refund window per purchase terms.
636
+
637
+ ## License
638
+
639
+ MIT — see [LICENSE](LICENSE). Copyright (c) 2026 Kutay Karahan.
640
+
641
+ After purchase, copy your license key from your Polar order (purchase email / Polar customer portal), then run `agentcap license activate`, paste the key at the hidden prompt, and check with `agentcap license status` (expect `tier: pro`).
642
+
643
+ The Pro licence key is separate from the source licence. How it is checked:
644
+
645
+ - On activation the key is validated against Polar's public licence API
646
+ (`api.polar.sh`). After that it is re-checked at most about once every 7 days.
647
+ - The result is cached in `~/.config/agentcap/license.json` (overridable with
648
+ `$AGENTCAP_LICENSE_FILE`).
649
+ - The licence check fails open: if you are offline, or Polar cannot be reached,
650
+ a previously validated licence keeps working. Network failures (timeouts,
651
+ connection errors, 5xx, unexpected responses) never downgrade it, and
652
+ revalidation is retried about every 7 days. Only an explicit rejection from
653
+ Polar (for example a refunded or revoked key) falls back to the free tier.
654
+ - `AGENTCAP_POLAR_ORG_ID` selects the Polar organization the key belongs to.
655
+
656
+ ## Development
657
+
658
+ ```bash
659
+ uv venv .venv
660
+ uv pip install -e '.[dev]'
661
+ .venv/bin/pytest -q
662
+ ```
663
+
664
+ Tests use mocked upstreams (`httpx.MockTransport`) and never make real network
665
+ calls; no real API keys are required.