Skip to content

Add --x402-max-amount local spend limit for x402 sessions - #372

Open
jancurn wants to merge 1 commit into
mainfrom
claude/pr-369-review-ujpqzu
Open

Add --x402-max-amount local spend limit for x402 sessions#372
jancurn wants to merge 1 commit into
mainfrom
claude/pr-369-review-ujpqzu

Conversation

@jancurn

@jancurn jancurn commented Aug 14, 2026

Copy link
Copy Markdown
Member

An x402 session currently pays whatever a tool call turns out to cost. --x402-max-amount <usd> caps every single payment — a payment above the cap is refused locally, before anything is signed, and the call fails with the amount that was asked for.

  • checked in signPayment(), the one choke point all three payment paths share (proactive _meta.x402 signing, HTTP 402 challenges, payment-required tool results)
  • for upto, caps the maximum authorization you sign
  • refusal is never swallowed as "signing failed", so the call can't quietly go out unpaid
  • stored in sessions.json and restored on reconnect/restart, so a crashed session comes back capped
  • shown in the session list as [x402 max $0.50]

Refs #369, which proposed the same local guard bundled with a hardcoded third-party payment-approval service. This is the local half only: no network call, no vendor, no extra payment per tool call. It deliberately leaves out that PR's other two guards — the resource/server origin check (breaks mcp:// payment resources, and no benefit without the vendor) and per-call signature scoping (conflicts with the deliberate prepaid-token reuse from #247/#368).

https://claude.ai/code/session_011DCnYpi347tXWKMrhmVgLB


Generated by Claude Code

An x402 session currently pays whatever a tool call turns out to cost.
--x402-max-amount <usd> caps every single payment: the amount is checked in
signPayment(), the one choke point all three payment paths go through
(proactive _meta.x402 signing, HTTP 402 challenges, and payment-required tool
results), so a payment over the cap is refused before anything is signed and
the call fails with the amount that was asked for.

The cap is stored in sessions.json and restored on reconnect and restart, so a
crashed session comes back capped rather than uncapped.

Refs #369, which proposed the same local guard alongside a hardcoded
third-party payment-approval service. This is the local half only: no network
call, no vendor, no extra payment per tool call.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011DCnYpi347tXWKMrhmVgLB
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants