Add --x402-max-amount local spend limit for x402 sessions - #372
Open
jancurn wants to merge 1 commit into
Open
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.signPayment(), the one choke point all three payment paths share (proactive_meta.x402signing, HTTP 402 challenges, payment-required tool results)upto, caps the maximum authorization you signsessions.jsonand restored on reconnect/restart, so a crashed session comes back capped[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