agentcap-cli 0.1.4__tar.gz → 0.2.1__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.
- agentcap_cli-0.2.1/PKG-INFO +695 -0
- agentcap_cli-0.2.1/README.md +665 -0
- {agentcap_cli-0.1.4 → agentcap_cli-0.2.1}/pyproject.toml +5 -2
- {agentcap_cli-0.1.4 → agentcap_cli-0.2.1}/src/agentcap/__init__.py +1 -1
- {agentcap_cli-0.1.4 → agentcap_cli-0.2.1}/src/agentcap/adapters.py +101 -0
- {agentcap_cli-0.1.4 → agentcap_cli-0.2.1}/src/agentcap/alerts.py +78 -6
- agentcap_cli-0.2.1/src/agentcap/analytics.py +355 -0
- agentcap_cli-0.2.1/src/agentcap/budget.py +124 -0
- {agentcap_cli-0.1.4 → agentcap_cli-0.2.1}/src/agentcap/clamp.py +32 -1
- {agentcap_cli-0.1.4 → agentcap_cli-0.2.1}/src/agentcap/cli.py +195 -11
- agentcap_cli-0.2.1/src/agentcap/cli_history.py +218 -0
- {agentcap_cli-0.1.4 → agentcap_cli-0.2.1}/src/agentcap/data/pricing.json +162 -2
- {agentcap_cli-0.1.4 → agentcap_cli-0.2.1}/src/agentcap/devtools/fake_upstream.py +159 -0
- {agentcap_cli-0.1.4 → agentcap_cli-0.2.1}/src/agentcap/estimate.py +22 -3
- agentcap_cli-0.2.1/src/agentcap/eta.py +66 -0
- agentcap_cli-0.2.1/src/agentcap/history.py +512 -0
- {agentcap_cli-0.1.4 → agentcap_cli-0.2.1}/src/agentcap/license.py +5 -0
- agentcap_cli-0.2.1/src/agentcap/loop.py +365 -0
- agentcap_cli-0.2.1/src/agentcap/plans.py +70 -0
- {agentcap_cli-0.1.4 → agentcap_cli-0.2.1}/src/agentcap/pricing.py +51 -1
- {agentcap_cli-0.1.4 → agentcap_cli-0.2.1}/src/agentcap/proxy.py +199 -24
- agentcap_cli-0.2.1/src/agentcap/quota.py +1043 -0
- agentcap_cli-0.2.1/src/agentcap/report.py +204 -0
- {agentcap_cli-0.1.4 → agentcap_cli-0.2.1}/src/agentcap/runner.py +108 -4
- {agentcap_cli-0.1.4 → agentcap_cli-0.2.1}/src/agentcap/upstreams.py +4 -0
- {agentcap_cli-0.1.4 → agentcap_cli-0.2.1}/src/agentcap/usage.py +132 -2
- agentcap_cli-0.2.1/src/agentcap/waste.py +482 -0
- agentcap_cli-0.2.1/tests/conftest.py +73 -0
- agentcap_cli-0.2.1/tests/fixtures/agents/claude/projects/-home-dev-shop/sess-p/subagents/agent-a1b2c3.jsonl +2 -0
- agentcap_cli-0.2.1/tests/fixtures/agents/claude/projects/-home-dev-shop/sess-p/subagents/agent-d4e5f6.jsonl +1 -0
- agentcap_cli-0.2.1/tests/fixtures/agents/claude/projects/-home-dev-shop/sess-p.jsonl +17 -0
- agentcap_cli-0.2.1/tests/fixtures/agents/codex/sessions/2026/10/29/rollout-2026-10-29T09-00-00-thr-parent.jsonl +14 -0
- agentcap_cli-0.2.1/tests/fixtures/agents/codex/sessions/2026/10/29/rollout-2026-10-29T09-00-50-thr-child.jsonl +3 -0
- agentcap_cli-0.2.1/tests/fixtures/agents/codex/sessions/2026/10/29/rollout-2026-10-29T09-01-20-thr-fork.jsonl +3 -0
- agentcap_cli-0.2.1/tests/fixtures/history/claude/.credentials.json +1 -0
- agentcap_cli-0.2.1/tests/fixtures/history/claude/projects/-home-dev-shop/1f0c-sess-a.jsonl +8 -0
- agentcap_cli-0.2.1/tests/fixtures/history/codex/auth.json +1 -0
- agentcap_cli-0.2.1/tests/fixtures/history/codex/sessions/2026/10/29/rollout-2026-10-29T10-00-00-0199aaaa-bbbb-cccc-dddd-eeeeeeeeeeee.jsonl +8 -0
- agentcap_cli-0.2.1/tests/test_agents.py +246 -0
- agentcap_cli-0.2.1/tests/test_analytics.py +268 -0
- agentcap_cli-0.2.1/tests/test_anthropic_proxy.py +230 -0
- agentcap_cli-0.2.1/tests/test_anthropic_units.py +217 -0
- agentcap_cli-0.2.1/tests/test_budget.py +170 -0
- agentcap_cli-0.2.1/tests/test_cc_plugin.py +298 -0
- agentcap_cli-0.2.1/tests/test_claude_adapter_and_tiers.py +164 -0
- {agentcap_cli-0.1.4 → agentcap_cli-0.2.1}/tests/test_cli.py +62 -17
- agentcap_cli-0.2.1/tests/test_e2e_claude.py +137 -0
- {agentcap_cli-0.1.4 → agentcap_cli-0.2.1}/tests/test_estimate.py +1 -1
- agentcap_cli-0.2.1/tests/test_history.py +200 -0
- {agentcap_cli-0.1.4 → agentcap_cli-0.2.1}/tests/test_license.py +3 -0
- {agentcap_cli-0.1.4 → agentcap_cli-0.2.1}/tests/test_pricing.py +4 -2
- {agentcap_cli-0.1.4 → agentcap_cli-0.2.1}/tests/test_proxy_core.py +1 -0
- agentcap_cli-0.2.1/tests/test_quota.py +599 -0
- agentcap_cli-0.2.1/tests/test_report_cli.py +68 -0
- agentcap_cli-0.2.1/tests/test_runaway.py +135 -0
- {agentcap_cli-0.1.4 → agentcap_cli-0.2.1}/tests/test_runner.py +3 -3
- agentcap_cli-0.1.4/PKG-INFO +0 -405
- agentcap_cli-0.1.4/README.md +0 -375
- agentcap_cli-0.1.4/landing/README.md +0 -166
- agentcap_cli-0.1.4/src/agentcap/loop.py +0 -118
- {agentcap_cli-0.1.4 → agentcap_cli-0.2.1}/.gitignore +0 -0
- {agentcap_cli-0.1.4 → agentcap_cli-0.2.1}/LICENSE +0 -0
- {agentcap_cli-0.1.4 → agentcap_cli-0.2.1}/src/agentcap/demo.py +0 -0
- {agentcap_cli-0.1.4 → agentcap_cli-0.2.1}/src/agentcap/devtools/__init__.py +0 -0
- {agentcap_cli-0.1.4 → agentcap_cli-0.2.1}/src/agentcap/ledger.py +0 -0
- {agentcap_cli-0.1.4 → agentcap_cli-0.2.1}/tests/license_support.py +0 -0
- {agentcap_cli-0.1.4 → agentcap_cli-0.2.1}/tests/proxy_support.py +0 -0
- {agentcap_cli-0.1.4 → agentcap_cli-0.2.1}/tests/test_adapters.py +0 -0
- {agentcap_cli-0.1.4 → agentcap_cli-0.2.1}/tests/test_alerts.py +0 -0
- {agentcap_cli-0.1.4 → agentcap_cli-0.2.1}/tests/test_clamp.py +0 -0
- {agentcap_cli-0.1.4 → agentcap_cli-0.2.1}/tests/test_ledger.py +0 -0
- {agentcap_cli-0.1.4 → agentcap_cli-0.2.1}/tests/test_loop.py +0 -0
- {agentcap_cli-0.1.4 → agentcap_cli-0.2.1}/tests/test_proxy_cancel.py +0 -0
- {agentcap_cli-0.1.4 → agentcap_cli-0.2.1}/tests/test_proxy_extras.py +0 -0
- {agentcap_cli-0.1.4 → agentcap_cli-0.2.1}/tests/test_proxy_streaming.py +0 -0
- {agentcap_cli-0.1.4 → agentcap_cli-0.2.1}/tests/test_upstreams.py +0 -0
- {agentcap_cli-0.1.4 → agentcap_cli-0.2.1}/tests/test_usage.py +0 -0
|
@@ -0,0 +1,695 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: agentcap-cli
|
|
3
|
+
Version: 0.2.1
|
|
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 since the last request, or 1 h)
|
|
44
|
+
main session $2.30 21x subagents $3.80 36x
|
|
45
|
+
Tip: idle subagents re-wrote their own context 36x (~$3.80). Set subagentPromptCacheTtl: "1h" ...
|
|
46
|
+
STARTING CONTEXT 31 subagents, first request median 38.2k tok, largest 131.0k (7f3a91c2/a1b2c3d4)
|
|
47
|
+
REPEATED TOOL CALLS $9.80 12 streaks of >= 3 identical calls in a row
|
|
48
|
+
TOOL ERROR STREAKS $4.30 5 streaks of >= 3 failing calls in a row
|
|
49
|
+
Pro would have stopped this run at $3.12 / at 4 repeats (Bash x11 in 7f3a91c2, $2.40 after that).
|
|
50
|
+
```
|
|
51
|
+
*(illustrative numbers; run it on your own logs, it is read-only)*
|
|
52
|
+
|
|
53
|
+
## Stop loops and quota burn (Pro)
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
agentcap run --quota 5% -- claude # subscription: stop at 5% of the weekly quota, or on a loop
|
|
57
|
+
agentcap run --quota 10% --window 5h -- codex # same for Codex on a ChatGPT plan
|
|
58
|
+
agentcap run --cap 2 -- codex exec "fix tests" # API key: $2 cap + loop/burn breaker
|
|
59
|
+
agentcap approve # raise a stopped job's limit by 50% (at most twice)
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
On a $20/month Codex plan, two code-review prompts used the whole 5-hour limit
|
|
63
|
+
([Povilas Korop](https://x.com/PovilasKorop/status/2116114249655501050): $7.70 + $1.43 at API prices).
|
|
64
|
+
`--quota 10% --window 5h -- codex` stops the job before that.
|
|
65
|
+
|
|
66
|
+
Free tools like [claude-code-spend-stop](https://github.com/VedantBhayani/claude-code-spend-stop) and
|
|
67
|
+
[RelayPlane](https://relayplane.com) give you a free $ cap. AgentCap adds the loop breaker, a cap on
|
|
68
|
+
your subscription quota % and Codex support.
|
|
69
|
+
|
|
70
|
+
- **Loop breaker.** Same tool call (name + input) 4 times in a row, or 8 failing tool calls in a
|
|
71
|
+
row: the run is stopped (exit 4). On subscriptions it works without touching your login or
|
|
72
|
+
traffic: Claude Code via an official `PreToolUse` hook (denies the 4th identical call and ends
|
|
73
|
+
the turn; an interactive session stays open so you can `agentcap approve` or quit; headless
|
|
74
|
+
`claude -p` runs get SIGINT if they keep going); Codex by reading its own rollout file (SIGINT). On API keys the
|
|
75
|
+
proxy also catches identical requests and `--max-burn` $/min spikes.
|
|
76
|
+
- **Per-job quota %.** Stop one job at its share of the account's weekly or 5-hour limit.
|
|
77
|
+
- **Evidence receipt.** Each stop prints and saves why (`same tool call 4 times in a row (Bash)`,
|
|
78
|
+
`this job used 5.1% of the weekly quota`) and the last tool call's name, as numbers and tool
|
|
79
|
+
names only, never prompts or tool inputs.
|
|
80
|
+
- **Approve.** After a stop, `agentcap approve` (or `/agentcap:approve` in the plugin) raises the
|
|
81
|
+
limit by 50%, at most twice, and the run continues.
|
|
82
|
+
- **Free** runs the same detectors in observe-only mode and prints what Pro would have done.
|
|
83
|
+
|
|
84
|
+
Honest limits: Claude tool-error streaks are only caught on API-key runs (the subscription hook sees
|
|
85
|
+
the call, not its result); the stop can be one request late; quota % is account-level; verified on
|
|
86
|
+
fixtures, fake CLIs and real Claude Code 2.1.197 hooks, **not yet on a real Max/ChatGPT account.**
|
|
87
|
+
|
|
88
|
+
## The API-key cap
|
|
89
|
+
|
|
90
|
+
AgentCap runs
|
|
91
|
+
the CLI behind a local proxy on `127.0.0.1` and applies a local spend cap to the
|
|
92
|
+
run. Before each request it reserves the worst-case cost; when the budget is gone
|
|
93
|
+
it kills the local process and tells you why. No dashboard, no account, no code
|
|
94
|
+
changes for tools that honour a base-URL environment variable.
|
|
95
|
+
|
|
96
|
+
Claude Code and Codex CLI are routed automatically (Gemini CLI too). AgentCap meters API-key
|
|
97
|
+
traffic — `POST /v1/responses` and `/v1/chat/completions` (Codex CLI uses the
|
|
98
|
+
Responses API) plus Gemini `generateContent` / `streamGenerateContent` and Anthropic `POST /v1/messages`. ChatGPT
|
|
99
|
+
or Google sign-in (OAuth/subscription) traffic is not metered.
|
|
100
|
+
|
|
101
|
+
## What it is
|
|
102
|
+
|
|
103
|
+
AgentCap is a small, local, serverless spend-cap proxy. You give it a command
|
|
104
|
+
and a cap:
|
|
105
|
+
|
|
106
|
+
```bash
|
|
107
|
+
agentcap run --cap 2 -- codex exec "fix the failing tests"
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
Everything the child sends to OpenAI or Gemini is routed through a proxy on
|
|
111
|
+
`127.0.0.1`. AgentCap reserves the worst-case cost of each request before it is
|
|
112
|
+
forwarded, settles the real usage afterwards, and terminates the agent's process
|
|
113
|
+
group if the cap would be exceeded. This is a local spend cap, not a
|
|
114
|
+
mathematical guarantee: with conservative reservation it reserves worst-case
|
|
115
|
+
cost before each request, so overshoot is rare but possible when providers count
|
|
116
|
+
more tokens than estimated.
|
|
117
|
+
|
|
118
|
+

|
|
119
|
+
|
|
120
|
+
*Simulated demo — fake local API, no key, no money.*
|
|
121
|
+
|
|
122
|
+
## Install
|
|
123
|
+
|
|
124
|
+
The package is published on PyPI as `agentcap-cli` (the name `agentcap` is
|
|
125
|
+
taken), but the command it installs is still `agentcap`.
|
|
126
|
+
|
|
127
|
+
```bash
|
|
128
|
+
# install the command globally
|
|
129
|
+
pipx install agentcap-cli
|
|
130
|
+
|
|
131
|
+
# or into the current environment
|
|
132
|
+
pip install agentcap-cli
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
No pipx? macOS: `brew install pipx && pipx ensurepath`; Linux: `python3 -m pip install --user pipx && python3 -m pipx ensurepath`.
|
|
136
|
+
|
|
137
|
+
From a checkout:
|
|
138
|
+
|
|
139
|
+
```bash
|
|
140
|
+
uv venv .venv
|
|
141
|
+
uv pip install -e .
|
|
142
|
+
|
|
143
|
+
# or install this checkout as the global command
|
|
144
|
+
pipx install .
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
## Install in VS Code / Cursor
|
|
148
|
+
|
|
149
|
+
The **AgentCap** editor extension (0.2.0) starts Claude Code or Codex in an
|
|
150
|
+
integrated terminal behind `agentcap run --cap`, shows live run spend in the
|
|
151
|
+
status bar, warns at 80% / 95%, and shows a modal when the cap (exit 3) or Pro's
|
|
152
|
+
loop breaker (exit 4) stops the run. It needs the `agentcap` CLI above.
|
|
153
|
+
|
|
154
|
+
It is **not on the VS Code Marketplace or Open VSX yet**. [Download agentcap-0.2.0.vsix](https://agentcap.launchbench.studio/agentcap-0.2.0.vsix)
|
|
155
|
+
(sha256 `175213b0979019cb472752ad71e613a48c6a22e7d899b761093ab7eac9867e70`) and install it:
|
|
156
|
+
|
|
157
|
+
```bash
|
|
158
|
+
curl -LO https://agentcap.launchbench.studio/agentcap-0.2.0.vsix
|
|
159
|
+
sha256sum agentcap-0.2.0.vsix # compare with the sha256 above
|
|
160
|
+
code --install-extension agentcap-0.2.0.vsix # VS Code
|
|
161
|
+
cursor --install-extension agentcap-0.2.0.vsix # Cursor
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
or *Extensions → … → Install from VSIX…*. Then run **AgentCap: Start Codex
|
|
165
|
+
with cap** (or Claude Code) from the command palette; set the cap with
|
|
166
|
+
**AgentCap: Set cap**.
|
|
167
|
+
|
|
168
|
+

|
|
169
|
+
|
|
170
|
+
*Real VS Code recording; the agent is a fake Codex script talking to AgentCap's
|
|
171
|
+
local fake upstream, so no real API call or spend is involved.*
|
|
172
|
+
|
|
173
|
+
## Quickstart
|
|
174
|
+
|
|
175
|
+
```bash
|
|
176
|
+
# Codex CLI under a $2 cap (API-key mode: uses OPENAI_API_KEY)
|
|
177
|
+
agentcap run --cap 2 -- codex exec "fix the failing tests"
|
|
178
|
+
|
|
179
|
+
# Gemini CLI under a $2 cap (API-key mode: uses GEMINI_API_KEY)
|
|
180
|
+
agentcap run --cap 2 -- gemini -p "refactor utils.py"
|
|
181
|
+
|
|
182
|
+
# Gemini CLI in a folder you have not trusted yet
|
|
183
|
+
agentcap run --cap 2 --trust-workspace -- gemini -p "refactor utils.py"
|
|
184
|
+
|
|
185
|
+
# Run your own Python agent (it must honour OPENAI_BASE_URL)
|
|
186
|
+
agentcap run --cap 1 -- python my_agent.py
|
|
187
|
+
|
|
188
|
+
# Keep a proxy open for several terminals
|
|
189
|
+
agentcap serve --port 8787 --cap 5
|
|
190
|
+
|
|
191
|
+
# Simulated, fully local demo (fake API, no key, no money)
|
|
192
|
+
agentcap demo
|
|
193
|
+
|
|
194
|
+
# Inspect spend
|
|
195
|
+
agentcap status --port 8787
|
|
196
|
+
agentcap status --db
|
|
197
|
+
|
|
198
|
+
# Inspect the bundled price table
|
|
199
|
+
agentcap pricing
|
|
200
|
+
agentcap pricing google/gemini-4-argon
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
Uses your API key (`OPENAI_API_KEY` / `GEMINI_API_KEY`). ChatGPT or Google
|
|
204
|
+
sign-in (OAuth/subscription) traffic is not metered.
|
|
205
|
+
|
|
206
|
+
`agentcap run` accepts `--cap` (default `$5`, or `$AGENTCAP_CAP`),
|
|
207
|
+
`--hour-cap` / `--day-cap` and `--max-burn` (Pro), `--allow-unmetered`, `--no-clamp`, `--port`,
|
|
208
|
+
`--trust-workspace` and `--quiet`.
|
|
209
|
+
|
|
210
|
+
### CLI routing
|
|
211
|
+
|
|
212
|
+
- **Codex CLI 0.163** ignores `OPENAI_BASE_URL`, so AgentCap passes
|
|
213
|
+
`-c model_provider=agentcap` and a `model_providers.agentcap` block (Responses
|
|
214
|
+
API over HTTP, websockets disabled) right after the executable. If your command
|
|
215
|
+
already sets `model_provider`, `model_providers.*` or `openai_base_url` with
|
|
216
|
+
`-c`/`--config`, AgentCap refuses to start (exit code 2) rather than let
|
|
217
|
+
traffic bypass the proxy.
|
|
218
|
+
- **Gemini CLI 0.58–0.66** needs an auth type in headless mode, and from 0.60 it
|
|
219
|
+
also refuses system settings files that are not root-owned. AgentCap therefore
|
|
220
|
+
runs Gemini with a temporary `GEMINI_CLI_HOME`: its `.gemini` directory links
|
|
221
|
+
your real entries (history, `trustedFolders.json`, credentials) and holds a
|
|
222
|
+
copied `settings.json` with the auth type forced to `gemini-api-key`. The
|
|
223
|
+
overlay is removed afterwards; nothing in your real `~/.gemini` is modified.
|
|
224
|
+
`--trust-workspace` adds `GEMINI_CLI_TRUST_WORKSPACE=true` for Gemini.
|
|
225
|
+
- `npx @openai/codex ...` and `npx @google/gemini-cli ...` are recognised too.
|
|
226
|
+
|
|
227
|
+
Add `--trust-workspace` for Gemini CLI runs in folders you have not trusted yet;
|
|
228
|
+
without it, headless Gemini may refuse the workspace.
|
|
229
|
+
|
|
230
|
+
At the end of a run AgentCap warns **“no model requests observed — protection
|
|
231
|
+
not verified”** if the proxy saw no model traffic. That means the agent may have
|
|
232
|
+
bypassed the proxy, so check the command and auth mode.
|
|
233
|
+
|
|
234
|
+
## Claude Code (new in 0.1.5)
|
|
235
|
+
|
|
236
|
+
```bash
|
|
237
|
+
export ANTHROPIC_API_KEY=sk-ant-...
|
|
238
|
+
agentcap run --cap 3 -- claude -p "fix the failing tests"
|
|
239
|
+
# Pro: agentcap run --cap 3 --hour-cap 10 --day-cap 25 -- npx @anthropic-ai/claude-code -p "..."
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
AgentCap points Claude Code at its local proxy (`ANTHROPIC_BASE_URL=http://127.0.0.1:<port>/anthropic`)
|
|
243
|
+
and meters every `POST /v1/messages`, streamed or not:
|
|
244
|
+
|
|
245
|
+
- Prices come from Anthropic's published table (docs.claude.com pricing, checked 2026-10-30):
|
|
246
|
+
input, cache reads, 5-minute cache writes (1.25x input), 1-hour cache writes (2x input) and output.
|
|
247
|
+
Thinking tokens are billed as output and are covered by `max_tokens`.
|
|
248
|
+
- Before a request goes out, AgentCap reserves its worst case (`max_tokens` of output, all prompt
|
|
249
|
+
tokens as 1-hour cache writes). If that does not fit the remaining budget it lowers `max_tokens`
|
|
250
|
+
(and a manual thinking budget) or refuses the request. It never raises a limit.
|
|
251
|
+
- Unknown models, unknown `inference_geo` values and fast mode (`speed: "fast"`, not priced yet) are
|
|
252
|
+
blocked (fail-closed). `inference_geo: "us"` is charged at 1.1x.
|
|
253
|
+
- `count_tokens` and `GET /v1/models` pass through for free. Other Anthropic endpoints are blocked
|
|
254
|
+
unless you pass `--allow-unmetered`.
|
|
255
|
+
- AgentCap refuses to start Claude Code when `CLAUDE_CODE_USE_BEDROCK`, `_VERTEX` or `_FOUNDRY` is set,
|
|
256
|
+
or when a Claude settings file sets its own `ANTHROPIC_BASE_URL` in `env`. Those would send
|
|
257
|
+
traffic around the cap.
|
|
258
|
+
|
|
259
|
+
Limits:
|
|
260
|
+
|
|
261
|
+
- With a Claude subscription login instead of an API key, the cap counts API-list-price
|
|
262
|
+
equivalents, not your plan's billing.
|
|
263
|
+
- Costs are estimates from provider-reported usage. Your Anthropic invoice is authoritative.
|
|
264
|
+
- A large first request needs a cap that fits it. Claude Code's first request often reserves
|
|
265
|
+
about $0.50–$1. AgentCap prints a suggested `--cap` when it refuses one.
|
|
266
|
+
|
|
267
|
+
## Install as a Claude Code plugin (Max / Pro subscriptions)
|
|
268
|
+
|
|
269
|
+
The easiest path on a Claude Max or Pro plan. Inside Claude Code:
|
|
270
|
+
|
|
271
|
+
```
|
|
272
|
+
/plugin marketplace add Blitz00X/agentcap
|
|
273
|
+
/plugin install agentcap@agentcap
|
|
274
|
+
/agentcap:setup # once: adds AgentCap's read-only statusLine (your own line keeps showing)
|
|
275
|
+
/agentcap:quota 5% # this session may use 5% of the weekly quota (`2% 5h` for the 5-hour window)
|
|
276
|
+
/agentcap:status # session 3.1% / 5% (weekly)
|
|
277
|
+
/agentcap:off # clear it; /agentcap:unsetup restores your old statusLine
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
No pip install: the plugin is stdlib Python (`python3` on PATH). How it works:
|
|
281
|
+
|
|
282
|
+
- Claude Code only exposes the subscription `rate_limits` % to the **statusLine** command, and a
|
|
283
|
+
plugin can't set the main statusLine. So `/agentcap:setup` asks once and writes it to
|
|
284
|
+
`~/.claude/settings.json` (backup `settings.json.agentcap-backup`, previous line chained,
|
|
285
|
+
`/agentcap:unsetup` undoes it).
|
|
286
|
+
- Plugin hooks: `PreToolUse` warns at 80% and, on **Pro**, denies tool calls at the limit;
|
|
287
|
+
`Stop` prints a receipt (`session 4.2% / 5% (weekly)`). **Free:** live meter + one notice
|
|
288
|
+
at the limit (`Pro would stop the agent here`). Pro is read from the licence the `agentcap`
|
|
289
|
+
CLI stores after `agentcap license activate` (paste the key at the hidden prompt).
|
|
290
|
+
- Loop breaker (works with or without `/agentcap:quota`): `PreToolUse` hashes each tool call
|
|
291
|
+
(name + input, per session and per subagent; polling tools like `TaskOutput`/`BashOutput`
|
|
292
|
+
are ignored). The 4th identical call in a row is denied with `continue: false` on **Pro**;
|
|
293
|
+
**Free** gets one notice per streak. `PostToolUse` / `PostToolUseFailure` count failing
|
|
294
|
+
tool calls: 8 in a row stops the agent on Pro (`continue: false`), Free gets a notice.
|
|
295
|
+
Tool input and output are never stored, only a 16-char hash and counts; these per-session
|
|
296
|
+
files are deleted after 7 days (on `SessionStart`).
|
|
297
|
+
- Read-only: no OAuth token, credentials file or API traffic is touched.
|
|
298
|
+
|
|
299
|
+
Honest limits: the % is account-level (parallel sessions count), the stop can be one request
|
|
300
|
+
late, and the share updates when the statusLine refreshes. Verified with real Claude Code
|
|
301
|
+
2.1.197 (plugin install from the marketplace, hooks loaded, `/agentcap:quota` executed,
|
|
302
|
+
PreToolUse deny blocked the tool) against a local fake API and synthetic `rate_limits`;
|
|
303
|
+
**not yet checked against a real Max account.**
|
|
304
|
+
|
|
305
|
+
## Works with Claude Max / ChatGPT subscriptions (quota mode)
|
|
306
|
+
|
|
307
|
+
On a subscription there is no dollar bill, but there is a weekly and a 5-hour usage limit.
|
|
308
|
+
Quota mode caps **one job's share** of it:
|
|
309
|
+
|
|
310
|
+
```bash
|
|
311
|
+
agentcap run --quota 5% -- claude # stop this job after 5% of the weekly quota
|
|
312
|
+
agentcap run --quota 10% --window 5h -- codex # or 10% of the 5-hour window
|
|
313
|
+
agentcap quota # read-only: last seen usage (Free)
|
|
314
|
+
```
|
|
315
|
+
|
|
316
|
+
- **Read-only, ToS-safe.** AgentCap never proxies, reads or reuses your subscription login
|
|
317
|
+
or tokens, and never touches subscription traffic. The official, unmodified CLI talks to
|
|
318
|
+
Anthropic/OpenAI directly.
|
|
319
|
+
- **Claude Code:** for this run only, AgentCap adds a settings layer with `claude --settings <file>`
|
|
320
|
+
(your `~/.claude/settings.json` and project settings are never edited). It contains a
|
|
321
|
+
statusline command that records the official `rate_limits` (`five_hour` / `seven_day`
|
|
322
|
+
`used_percentage`, `resets_at`) and then runs **your own statusline command unchanged**,
|
|
323
|
+
plus a `PreToolUse` hook that denies further tool calls with a clear reason once the job's
|
|
324
|
+
share reaches the limit and ends the turn (`continue: false`). An interactive session stays open
|
|
325
|
+
(run `agentcap approve` to continue, or quit). Headless `claude -p` runs, and sessions where
|
|
326
|
+
the hook never fired, get SIGINT. Exit code 3.
|
|
327
|
+
- **Codex CLI:** AgentCap tails the `token_count` events Codex writes to
|
|
328
|
+
`~/.codex/sessions/**/rollout-*.jsonl` (`rate_limits.primary/secondary.used_percent`,
|
|
329
|
+
`window_minutes`, `resets_at`) and sends SIGINT at the limit. Exit code 3.
|
|
330
|
+
- Baseline at job start (exact when a reading from the last 15 minutes exists, otherwise the
|
|
331
|
+
first response is not counted), window resets mid-job are handled, 80% warning,
|
|
332
|
+
per-job receipt: `this job used 4.2% of the weekly quota`. Pro alerts (Telegram/webhook)
|
|
333
|
+
and receipt files work the same as for dollar caps.
|
|
334
|
+
- **Free:** `agentcap quota` and observe-only runs that print the job's share and
|
|
335
|
+
`Pro's quota mode would have stopped this job at 5%`. **Pro:** stopping at the limit.
|
|
336
|
+
|
|
337
|
+
**Honest limits.** The percentage is **account-level**: a parallel session or claude.ai/chatgpt.com
|
|
338
|
+
use in the same window counts against the job (AgentCap warns when it sees another session).
|
|
339
|
+
Values arrive once per model response, so a job **can overshoot by up to one request**.
|
|
340
|
+
Claude Code only reports `rate_limits` for Pro/Max logins and only in interactive sessions
|
|
341
|
+
(the statusline does not run in `claude -p`). Codex's rollout format is undocumented and may change.
|
|
342
|
+
**Verified so far on fixtures and fake CLIs only** (plus real Claude Code 2.1.197: the `--settings`
|
|
343
|
+
layer, the chained statusline and the `PreToolUse` deny were checked against a local fake API);
|
|
344
|
+
a check on a real Max / ChatGPT account is still pending.
|
|
345
|
+
|
|
346
|
+
## Try it without an API key
|
|
347
|
+
|
|
348
|
+
`agentcap demo` is a simulated demo. It starts a fake API on a random loopback
|
|
349
|
+
port, runs a tiny child against it with a 5-cent cap, and prints `(simulated)` at
|
|
350
|
+
the end. It needs no API key, makes no real provider calls, and works from a
|
|
351
|
+
plain `pipx install agentcap-cli`. Exit code `3` means the cap stopped the child.
|
|
352
|
+
|
|
353
|
+
### Simulated demo (fake local API, no real money)
|
|
354
|
+
|
|
355
|
+
```text
|
|
356
|
+
$ agentcap demo
|
|
357
|
+
SIMULATED DEMO — fake local API, no real provider, no real money. Dollar amounts are simulated.
|
|
358
|
+
agentcap [run-3bc1257940cb]: 50% of the $0.05 run cap used ($0.0252).
|
|
359
|
+
agentcap [run-3bc1257940cb]: 80% of the $0.05 run cap used ($0.0408).
|
|
360
|
+
agentcap [run-3bc1257940cb]: budget low, limiting output to 15303 tokens per request
|
|
361
|
+
agentcap [run-3bc1257940cb]: RUN CAP HIT (scope=run, cap=$0.05, spent=$0.0499). Stopping the agent.
|
|
362
|
+
agentcap run summary
|
|
363
|
+
run id: run-3bc1257940cb
|
|
364
|
+
requests: 44
|
|
365
|
+
refused requests: 2
|
|
366
|
+
spent: $0.0500
|
|
367
|
+
cap: $0.05
|
|
368
|
+
reserved-but-unsettled: $0.0000
|
|
369
|
+
clamped requests: 8
|
|
370
|
+
reason: cap_exceeded
|
|
371
|
+
exit code: 3
|
|
372
|
+
(simulated)
|
|
373
|
+
```
|
|
374
|
+
|
|
375
|
+
From a checkout, `python -m agentcap.devtools.fake_upstream --port 9000` still
|
|
376
|
+
starts the bundled fake upstream on loopback for manual metering experiments; the
|
|
377
|
+
test suite uses `httpx.MockTransport` and never calls the network.
|
|
378
|
+
|
|
379
|
+
## Supported & tested
|
|
380
|
+
|
|
381
|
+
| Tool | Verified version | Command and auth | Routing |
|
|
382
|
+
| --- | --- | --- | --- |
|
|
383
|
+
| 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 …`). |
|
|
384
|
+
| 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. |
|
|
385
|
+
| 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). |
|
|
386
|
+
| 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`. |
|
|
387
|
+
|
|
388
|
+
Tested with a real Gemini API key on Gemini CLI 0.66 (spend metered from Google's
|
|
389
|
+
usageMetadata, output clamped to the cap). Codex CLI 0.165 verified against real
|
|
390
|
+
OpenAI-compatible upstreams: Ollama Cloud (gpt-oss:20b) and OpenRouter (free model
|
|
391
|
+
poolside/laguna-s-2.1:free via the Responses API) — real responses, ledger token counts
|
|
392
|
+
matched OpenRouter's reported usage exactly, cap stop with exit 3; not against OpenAI
|
|
393
|
+
billing. Gemini CLI 0.58 and Codex CLI 0.163 are tested end-to-end against a local fake API only.
|
|
394
|
+
|
|
395
|
+
Models without a bundled price (for example OpenRouter or Ollama ids) are blocked until you add a price via `AGENTCAP_PRICING_FILE`.
|
|
396
|
+
|
|
397
|
+
**Platforms:** Linux and macOS. Windows: not yet (use WSL2).
|
|
398
|
+
|
|
399
|
+
## How it works
|
|
400
|
+
|
|
401
|
+
1. `agentcap run` starts the proxy on a random free port, bound **only** to
|
|
402
|
+
`127.0.0.1`, and waits for `/_agentcap/status`.
|
|
403
|
+
2. The child process is started in its own process group with:
|
|
404
|
+
|
|
405
|
+
```text
|
|
406
|
+
OPENAI_BASE_URL=http://127.0.0.1:PORT/openai/v1
|
|
407
|
+
GOOGLE_GEMINI_BASE_URL=http://127.0.0.1:PORT/gemini
|
|
408
|
+
GEMINI_API_BASE_URL=http://127.0.0.1:PORT/gemini
|
|
409
|
+
AGENTCAP_RUN_ID=...
|
|
410
|
+
AGENTCAP_PROXY=http://127.0.0.1:PORT
|
|
411
|
+
```
|
|
412
|
+
|
|
413
|
+
3. Before forwarding a request, the proxy estimates the prompt size and the
|
|
414
|
+
maximum output size, then atomically reserves that worst-case USD amount in
|
|
415
|
+
a local SQLite ledger. The input estimate is padded by a conservative
|
|
416
|
+
`input_safety_factor` (1.25 by default) to cover system prompts, tool
|
|
417
|
+
schemas, images and tokenizer differences that the local estimate cannot
|
|
418
|
+
see. Concurrent requests reserve against the same budget.
|
|
419
|
+
4. After the upstream responds, the real usage is parsed and the reservation is
|
|
420
|
+
settled to the actual cost (rounded up to the micro-dollar). Settlement uses
|
|
421
|
+
the provider's reported tokens, never the padded estimate. If the provider
|
|
422
|
+
bills more input tokens than estimated, that one settlement can exceed its
|
|
423
|
+
reservation; AgentCap emits an `overshoot` alert and the run's spend may end
|
|
424
|
+
slightly above the cap.
|
|
425
|
+
5. If the worst case does not fit the remaining budget but the prompt itself
|
|
426
|
+
does, the proxy **clamps the output limit** to exactly what fits (at least
|
|
427
|
+
`256` tokens by default) and reserves only that amount. The agent keeps
|
|
428
|
+
running; real usage still settles the reservation. Clamping is on by default
|
|
429
|
+
and can be disabled with `--no-clamp`.
|
|
430
|
+
6. If even a minimal clamped request cannot fit, the request is blocked and the
|
|
431
|
+
whole child process group is terminated (`SIGTERM`, then `SIGKILL` after
|
|
432
|
+
5s). `agentcap run` exits with code `3`. Pro's loop/burn breaker exits
|
|
433
|
+
with `4` (same step 4 times in a row, 8 failing tool results in a row, or a
|
|
434
|
+
burn rate above `--max-burn` $/min; see Free vs Pro).
|
|
435
|
+
The kill and its red alert fire at most once per run; later rejected
|
|
436
|
+
requests just receive `429` responses.
|
|
437
|
+
7. Unknown models and unparseable bodies are rejected (fail-closed); the request
|
|
438
|
+
is never forwarded unmetered.
|
|
439
|
+
|
|
440
|
+
The proxy makes only two kinds of request-body change: it adds
|
|
441
|
+
`stream_options.include_usage` to OpenAI Chat Completions streams so final
|
|
442
|
+
usage is available, and (unless `--no-clamp` is given) it lowers the request's
|
|
443
|
+
output limit when the worst-case reservation would cross the remaining budget.
|
|
444
|
+
For OpenAI that is `max_completion_tokens` (or the legacy `max_tokens` if the
|
|
445
|
+
body already used it) or `max_output_tokens` for the Responses API; for Gemini
|
|
446
|
+
it is `generationConfig.maxOutputTokens`. An existing smaller limit is never
|
|
447
|
+
raised. Everything else is forwarded byte-for-byte, including credentials.
|
|
448
|
+
|
|
449
|
+
Reasoning/thinking tokens are billed as output and count against the same
|
|
450
|
+
output limit, so a clamp also caps them.
|
|
451
|
+
|
|
452
|
+
## Metered endpoints
|
|
453
|
+
|
|
454
|
+
| Provider | Endpoints |
|
|
455
|
+
| --- | --- |
|
|
456
|
+
| OpenAI | `POST /v1/chat/completions`, `/v1/responses`, `/v1/completions`, `/v1/embeddings` |
|
|
457
|
+
| Gemini | `generateContent`, `streamGenerateContent` (other Gemini endpoints pass through) |
|
|
458
|
+
|
|
459
|
+
Token counting (`countTokens`) and `GET` requests are free passthroughs.
|
|
460
|
+
Request bodies are billed at price-book rates; embeddings are input-only.
|
|
461
|
+
|
|
462
|
+
## Limitations
|
|
463
|
+
|
|
464
|
+
- Tools that AgentCap can route (Codex CLI, Gemini CLI) or that honour
|
|
465
|
+
`OPENAI_BASE_URL` / `GOOGLE_GEMINI_BASE_URL` and send API keys can be metered.
|
|
466
|
+
OAuth or subscription logins are **not** metered.
|
|
467
|
+
- Prices are a local table, not a live feed. Check them with
|
|
468
|
+
`agentcap pricing`; override any entry in
|
|
469
|
+
`~/.config/agentcap/pricing.json` (or `$AGENTCAP_PRICING_FILE`).
|
|
470
|
+
- The proxy rewrites a request only to add `stream_options.include_usage` to
|
|
471
|
+
OpenAI chat streams and, unless `--no-clamp` is set, to lower its output
|
|
472
|
+
limit to what the remaining budget can afford. Prompts are never changed.
|
|
473
|
+
- Estimates are deliberately conservative, so a reservation can be larger than
|
|
474
|
+
the eventual cost. The cap is enforced before each request with a worst-case
|
|
475
|
+
reservation and concurrent requests reserve against the same budget. This is
|
|
476
|
+
not a mathematical guarantee: if a provider bills more input tokens than
|
|
477
|
+
estimated (for example server-side system prompts, tool schemas, images or
|
|
478
|
+
tokenizer differences), the final spend can exceed the cap by that one
|
|
479
|
+
request's estimation error. AgentCap emits an `overshoot` alert when a
|
|
480
|
+
settlement exceeds its reservation.
|
|
481
|
+
- The ledger lives at `~/.local/share/agentcap/ledger.sqlite3`
|
|
482
|
+
(override with `$AGENTCAP_DB`).
|
|
483
|
+
|
|
484
|
+
## Privacy
|
|
485
|
+
|
|
486
|
+
Prompts and keys pass through the local proxy in memory; AgentCap never stores
|
|
487
|
+
or uploads them. Free sends nothing anywhere. Pro sends alert metadata (run id,
|
|
488
|
+
spend, reason) only to webhook/Telegram destinations you configure, and
|
|
489
|
+
validates your licence key with Polar about once a week.
|
|
490
|
+
|
|
491
|
+
The ledger keeps token counts, costs, model names, timestamps and request
|
|
492
|
+
hashes — never prompts, response contents, API keys or Authorization headers.
|
|
493
|
+
|
|
494
|
+
**Pro licence checks:** activating a Pro key (and the periodic re-check) sends
|
|
495
|
+
only the licence key, the Polar organization id and an anonymous machine
|
|
496
|
+
fingerprint hash (SHA-256; it contains no hostname and no username) to Polar's
|
|
497
|
+
public licence API at `api.polar.sh`. Free users make no licence requests at
|
|
498
|
+
all.
|
|
499
|
+
|
|
500
|
+
## `agentcap waste` and usage history (Free, new in 0.2)
|
|
501
|
+
|
|
502
|
+
```bash
|
|
503
|
+
agentcap waste # subagent + Opus share, cache misses, tool loops, error streaks ($ each)
|
|
504
|
+
agentcap report --by agent # session -> subagent tree with $ and Opus share
|
|
505
|
+
agentcap import # read-only: ~/.claude/projects, ~/.codex/sessions, AgentCap's ledger
|
|
506
|
+
agentcap report --by day # Free: day | session | model | project, tokens + API-equivalent $
|
|
507
|
+
agentcap report --by model --since 7d --csv
|
|
508
|
+
|
|
509
|
+
agentcap budget set --task-usd 2 --day-usd 20 --task-quota 5% --window 5h
|
|
510
|
+
agentcap run -- codex exec "..." # uses the $2 task cap from the budget
|
|
511
|
+
agentcap run --quota -- claude # uses the 5% / 5h quota from the budget
|
|
512
|
+
```
|
|
513
|
+
|
|
514
|
+
Tools like agent-tree show you what your subagents are doing; AgentCap also stops them when they loop
|
|
515
|
+
(same tool call 4x in a row or 8 tool errors in a row, Pro). `agentcap waste` lists cache misses first:
|
|
516
|
+
resuming a session after the cache expired re-writes the whole prompt cache, so start a new session (or `/clear`) after a break.
|
|
517
|
+
Misses are split into main session and subagents. An idle subagent re-writes only its own context
|
|
518
|
+
(not the whole conversation, unless it is a forked subagent), at 1.25x normal input. If your
|
|
519
|
+
subagents sit idle for more than 5 minutes, set `subagentPromptCacheTtl: "1h"`. A 1 h write costs
|
|
520
|
+
2x input, so it only pays off when the subagent is reused. `STARTING CONTEXT` shows how many tokens
|
|
521
|
+
each subagent's first request carries.
|
|
522
|
+
|
|
523
|
+
- **Store:** `~/.local/share/agentcap/usage.db` (`$XDG_DATA_HOME` respected, mode 600). `import` is
|
|
524
|
+
idempotent; it reads only `*.jsonl` session logs and AgentCap's own files. It never opens auth or
|
|
525
|
+
credential files, never stores prompt or response text, and never touches network or OAuth traffic.
|
|
526
|
+
Unknown or changed log lines are skipped and counted, not fatal.
|
|
527
|
+
- **Budget:** one file, `~/.config/agentcap/budget.json`. Scopes: task (one `agentcap run` = one agent
|
|
528
|
+
session) in $, hour/day across runs in $ (Pro), and per-job % of the subscription quota (Pro stops).
|
|
529
|
+
A flag or `AGENTCAP_CAP` always beats the budget. On Free, a budget hour/day cap is ignored with a note.
|
|
530
|
+
- **Early warning:** when the current burn rate would hit the run cap within ~10 minutes, AgentCap
|
|
531
|
+
prints (and on Pro sends) one `cap_eta` alert: "cap is hit in ~N min".
|
|
532
|
+
- **$ is API-equivalent:** what the same tokens would cost at list API prices — not your subscription bill.
|
|
533
|
+
- **Subagents:** Claude Code `<session>/subagents/agent-*.jsonl` and `isSidechain` lines; Codex
|
|
534
|
+
`session_meta` `source.subagent.thread_spawn.parent_thread_id` and `forked_from_id`. These formats
|
|
535
|
+
are undocumented and change between CLI versions.
|
|
536
|
+
- **`waste` heuristics:** a cache miss is a cache write larger than the cache read after the prompt
|
|
537
|
+
cache TTL ran out (5 min; 1 h when written with `ephemeral_1h`; Codex: a big uncached prompt after
|
|
538
|
+
> 5 min idle). Its $ is what the re-write cost above a cache read: 5 min writes at 1.25x input,
|
|
539
|
+
1 h writes at 2x input (Anthropic list prices). Tool inputs are hashed, never printed. Not in local logs: `agent_summary` / title
|
|
540
|
+
background calls and HTTP retries (planned: local OTel receiver).
|
|
541
|
+
|
|
542
|
+
### Pro extras: analytics (`agentcap report <view>`)
|
|
543
|
+
|
|
544
|
+
| view | what you get |
|
|
545
|
+
| --- | --- |
|
|
546
|
+
| `forecast` | 5h / weekly quota: "limit hits at Tue 14:20 (~1.5h)", with an early-warning mark |
|
|
547
|
+
| `calibration` | "this week 1% of quota = 1.4M tokens ≈ $1.49", tracked per reset period so you can see if your limit shrank |
|
|
548
|
+
| `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`) |
|
|
549
|
+
| `receipts` | per job / session / repo receipts, `--csv` export, plus AgentCap run receipts |
|
|
550
|
+
|
|
551
|
+
Calibration pairs quota % samples (Codex `rate_limits` in rollouts; Claude statusline readings recorded
|
|
552
|
+
during `agentcap run --quota`) with the tokens imported in the same window. It is an estimate; small %
|
|
553
|
+
steps are noisy. No team aggregation: everything stays on your machine.
|
|
554
|
+
|
|
555
|
+
## Free vs Pro (0.2)
|
|
556
|
+
|
|
557
|
+
**Free (MIT License, forever):** the per-run spend cap.
|
|
558
|
+
- Per-run `--cap` (`--hour-cap` / `--day-cap` exit 2 on Free with a clear message)
|
|
559
|
+
- Output clamping, fail-closed metering, terminal alerts
|
|
560
|
+
- Claude Code, Codex, any SDK script (and Gemini CLI)
|
|
561
|
+
- `agentcap waste`, `agentcap report --by agent` (subagent tree), `agentcap import`, `agentcap report` by day/session/model/project, `agentcap budget`, the `cap_eta` early warning
|
|
562
|
+
|
|
563
|
+
When the Pro detectors below would have fired on a Free run, AgentCap does not stop it.
|
|
564
|
+
It prints one line: `Pro's loop breaker would have stopped this at $X.XX`.
|
|
565
|
+
|
|
566
|
+
**Pro, $12 one-time (launch week, until 10 Nov; then $19): stop runs that loop or eat your quota.**
|
|
567
|
+
|
|
568
|
+
**Get Pro:** buy at https://agentcap.launchbench.studio/#pricing (Polar checkout). Polar then
|
|
569
|
+
emails you an **Access purchase** link; the key is in the Polar customer portal (not in the
|
|
570
|
+
email body). Run `agentcap license activate`, paste the key at the hidden prompt, and check `agentcap license
|
|
571
|
+
status` (`tier: pro`). One key works on up to 3 machines; `agentcap license deactivate` frees one.
|
|
572
|
+
The VS Code/Cursor extension and the Claude Code plugin use the same CLI licence.
|
|
573
|
+
|
|
574
|
+
- **Subscription quota mode + loop breaker:** `agentcap run --quota 5% -- claude|codex` stops a job at
|
|
575
|
+
its share of your Claude Max/Pro or ChatGPT quota, or when it repeats the same tool call 4 times /
|
|
576
|
+
fails 8 tool calls in a row (see above).
|
|
577
|
+
- **API-key loop/burn breaker:** stops the agent (exit 4) before the next request is sent when
|
|
578
|
+
(a) the same step repeats 4 times in a row (the last tool call + its result, normalised;
|
|
579
|
+
the growing conversation history is ignored), (b) 8 consecutive tool results are errors, or
|
|
580
|
+
(c) spend exceeds `--max-burn` USD/minute over a rolling 2-minute window (default `2.00`,
|
|
581
|
+
`--max-burn off` disables). Byte-identical repeats are still caught too.
|
|
582
|
+
- **Hour and day caps:** cross-run `--hour-cap` and `--day-cap`.
|
|
583
|
+
- **Phone and webhook alerts:** Telegram (`AGENTCAP_TELEGRAM_BOT_TOKEN`, `AGENTCAP_TELEGRAM_CHAT_ID`)
|
|
584
|
+
and webhook (`AGENTCAP_WEBHOOK_URL`) alerts for cap hits, loop kills and the end-of-run receipt.
|
|
585
|
+
Tokens are read from the environment and are never printed or logged.
|
|
586
|
+
- **Extras — usage analytics:** `agentcap report forecast | calibration | savings | receipts` (see above).
|
|
587
|
+
- **Spend receipt:** a JSON file per run (`~/.local/state/agentcap/receipts/<run>.json`, or
|
|
588
|
+
`AGENTCAP_RECEIPT_DIR`) with requests, spend, caps, the stop reason and the exit code. It contains
|
|
589
|
+
numbers only, never prompts. The same one-line receipt is sent to Telegram and the webhook.
|
|
590
|
+
|
|
591
|
+
[Buy AgentCap Pro — $12 launch week](https://buy.polar.sh/polar_cl_qagsvUdwQ0dRvaW7X5ynEJg5md27pEctIRAr40MBeLi)
|
|
592
|
+
|
|
593
|
+
### Purchase terms
|
|
594
|
+
|
|
595
|
+
- Pro is $12 one-time (launch week, until 10 Nov; then $19), no subscription.
|
|
596
|
+
- 14-day no-questions refund — email
|
|
597
|
+
[kutaykarahan6@gmail.com](mailto:kutaykarahan6@gmail.com).
|
|
598
|
+
- One licence key activates on up to 3 machines.
|
|
599
|
+
- The key is checked with Polar about once a week.
|
|
600
|
+
- If the licence server is unreachable your Pro keeps working (fail-open); only
|
|
601
|
+
an explicit Polar rejection of a refunded or revoked key downgrades it.
|
|
602
|
+
- If AgentCap is discontinued, Pro keeps working and you can ask for a refund
|
|
603
|
+
within 14 days of purchase.
|
|
604
|
+
- The Free tier (per-run cap) needs no key and makes no network calls.
|
|
605
|
+
|
|
606
|
+
After purchase you receive a licence key by email (via Polar). Activate it with
|
|
607
|
+
`agentcap license activate` (paste the key at the hidden prompt). `agentcap license deactivate` asks the
|
|
608
|
+
license server to release this activation (freeing the slot for another
|
|
609
|
+
machine) and then removes the local license; if the server cannot be reached the
|
|
610
|
+
local license is kept and the command exits 1 so you can retry. Use
|
|
611
|
+
`agentcap license deactivate --local-only` to remove just the local file — the
|
|
612
|
+
activation then still counts toward your 3 machines until you release it in the
|
|
613
|
+
Polar customer portal.
|
|
614
|
+
|
|
615
|
+
## How it compares
|
|
616
|
+
|
|
617
|
+
| Tool | What it does and how it enforces a cap |
|
|
618
|
+
| --- | --- |
|
|
619
|
+
| 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. |
|
|
620
|
+
| 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. |
|
|
621
|
+
| 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. |
|
|
622
|
+
| 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. |
|
|
623
|
+
| 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. |
|
|
624
|
+
|
|
625
|
+
The comparison above is from public pages; see the RelayPlane detail below.
|
|
626
|
+
|
|
627
|
+
## AgentCap vs RelayPlane
|
|
628
|
+
|
|
629
|
+
RelayPlane is a good tool. If it fits you, use it. The facts below come from RelayPlane's own
|
|
630
|
+
website as of 2026-10-30. We have not tested RelayPlane hands-on.
|
|
631
|
+
|
|
632
|
+
| | RelayPlane (per its site) | AgentCap |
|
|
633
|
+
|---|---|---|
|
|
634
|
+
| License | MIT | MIT License (the whole open-source CLI; Pro features are unlocked by a paid licence key) |
|
|
635
|
+
| Per-run / session / hour / day caps | Free | Run cap Free; hour/day caps Pro |
|
|
636
|
+
| Kill switch | Yes | Yes. Stops the agent's process group (exit 3) |
|
|
637
|
+
| Over-budget response | HTTP 429 `budget_exceeded` | HTTP 429, and the request is never sent |
|
|
638
|
+
| Output reservation | Capped at 4096 output tokens | Full `max_tokens` worst case, plus clamping to fit |
|
|
639
|
+
| Loop breaker | Not listed on their site | Pro |
|
|
640
|
+
| Telegram / webhook alerts, spend receipt | Not listed on their site | Pro |
|
|
641
|
+
|
|
642
|
+
The difference that matters for runaway bills: AgentCap reserves the worst case each request
|
|
643
|
+
can cost before sending it, so a single long response cannot overshoot the cap.
|
|
644
|
+
|
|
645
|
+
Pick what matches your setup — these tools can also be combined.
|
|
646
|
+
|
|
647
|
+
## FAQ
|
|
648
|
+
|
|
649
|
+
**Does clamping output hurt quality?** Yes, it can: when the budget is tight
|
|
650
|
+
AgentCap lowers max output tokens so the call fits; answers can be shorter or
|
|
651
|
+
cut off. Use `--no-clamp` to refuse instead.
|
|
652
|
+
|
|
653
|
+
**Does stopping roll back what the agent did?** No. At the cap AgentCap sends
|
|
654
|
+
SIGTERM then SIGKILL; files or remote changes already made stay. Use git / small
|
|
655
|
+
steps.
|
|
656
|
+
|
|
657
|
+
**Is the ledger my provider bill?** No. It is a local estimate from published
|
|
658
|
+
prices and reported usage; when usage is missing it charges the full reservation
|
|
659
|
+
(conservative). Your provider invoice is authoritative.
|
|
660
|
+
|
|
661
|
+
**Is the day cap shared across machines?** No. Hour/day caps are per machine
|
|
662
|
+
(local SQLite ledger). A license covers 3 machines, each with its own budget.
|
|
663
|
+
|
|
664
|
+
**What does one-time purchase include?** $12 once in launch week ($19 after 10 Nov), all 0.x updates; not a
|
|
665
|
+
promise of future major versions. 14-day refund window per purchase terms.
|
|
666
|
+
|
|
667
|
+
## License
|
|
668
|
+
|
|
669
|
+
MIT — see [LICENSE](LICENSE). Copyright (c) 2026 Kutay Karahan.
|
|
670
|
+
|
|
671
|
+
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`).
|
|
672
|
+
|
|
673
|
+
The Pro licence key is separate from the source licence. How it is checked:
|
|
674
|
+
|
|
675
|
+
- On activation the key is validated against Polar's public licence API
|
|
676
|
+
(`api.polar.sh`). After that it is re-checked at most about once every 7 days.
|
|
677
|
+
- The result is cached in `~/.config/agentcap/license.json` (overridable with
|
|
678
|
+
`$AGENTCAP_LICENSE_FILE`).
|
|
679
|
+
- The licence check fails open: if you are offline, or Polar cannot be reached,
|
|
680
|
+
a previously validated licence keeps working. Network failures (timeouts,
|
|
681
|
+
connection errors, 5xx, unexpected responses) never downgrade it, and
|
|
682
|
+
revalidation is retried about every 7 days. Only an explicit rejection from
|
|
683
|
+
Polar (for example a refunded or revoked key) falls back to the free tier.
|
|
684
|
+
- `AGENTCAP_POLAR_ORG_ID` selects the Polar organization the key belongs to.
|
|
685
|
+
|
|
686
|
+
## Development
|
|
687
|
+
|
|
688
|
+
```bash
|
|
689
|
+
uv venv .venv
|
|
690
|
+
uv pip install -e '.[dev]'
|
|
691
|
+
.venv/bin/pytest -q
|
|
692
|
+
```
|
|
693
|
+
|
|
694
|
+
Tests use mocked upstreams (`httpx.MockTransport`) and never make real network
|
|
695
|
+
calls; no real API keys are required.
|