Open-source x402 v2 policy linter

Catch automatic x402 payments missing a reviewable policy seam.

Monarch Shield parses JavaScript and TypeScript, follows selected official x402 imports and client aliases, and fails paid calls that have no recognized syntactic abort or denial return on the same client path.

Run the Doctor command locally or in CI. No account or API key.

Add to GitHub Actions
Run npx @monarch-shield/x402@0.2.0 doctor

Single-file static analysis. A pass does not prove that the policy is correct or the payment is safe.

Example Doctor result Blocked
01 Run Doctor npx @monarch-shield/x402@0.2.0 doctor --ci --strict
02 Unsafe payment path found

fetchWithPayment() can pay, but its x402 client has no recognized policy hook.

03 CI exits non-zero

Add a recognized syntactic abort or denial return to the same client path, then rerun Doctor.

BLOCK The branch fails the configured CI check until a recognized policy seam protects the client path.
View proof recording
10 public regression cases
3 documented client families represented in parser fixtures
no external adoption claimed
0 accounts or API keys to scan

One rule for automatic x402 buyer code

Doctor checks whether supported x402 payment creation has an earlier recognized syntactic abort or denial return on the same client path. It is a merge-time linter, not a runtime authorization or settlement system.

Guard found Guard missing Local CI SARIF

What the release candidate can prove

The product is strongest when the code, package, Action, docs, and claims all describe the same static-analysis contract.

Import and alias tracking

Distinguishes official x402 client imports from unrelated functions with similar names.

Client-aware policy checks

Rejects late hooks, observer-only hooks, and hooks attached to the wrong client.

Fail-closed analysis

Parse failures and selected dynamic, reassigned, or cross-file escapes fail instead of returning a clean scan.

Documented boundary

Custom wrappers, cross-file control flow, unsupported languages, and unrecognized x402 APIs still need manual review.

Reproduce the result

Ten public fixtures record expected status, exit code, policy-seam state, and analysis state. Packed-package checks rerun the corpus in a fresh temporary project.

Supported code shapes

@x402/fetch @x402/axios @x402/mcp @x402/core/client PAYMENT-SIGNATURE X-PAYMENT

Evidence boundary: these are maintainer-produced examples. No external adoption is claimed.

Supported in 0.2.0

Selected x402 v2 buyer APIs

These are analyzer targets, not partnership or compatibility claims. Each target is tied to a public fixture and regression test.

Custom wrappers and APIs outside this list require manual review.

What Doctor refuses to treat as policy

No hook

A paid wrapper created from an x402 client with no recognized policy seam fails.

Logging only

An onBeforePaymentCreation callback that only observes or logs cannot block payment creation.

Observer-only MCP hook

An MCP onBeforePayment observer cannot stop the automatic payment path.

Wrong client

A policy hook on one client does not protect a paid wrapper created with another client.

Late hook

A hook registered after the paid call does not satisfy the source-order rule.

Lookalike guard

A function named checkBeforePayment from another package is not trusted.

Incomplete analysis

Parse errors and selected dynamic or cross-file escapes fail closed.

Use Doctor as a merge-time check. Keep authorization, spend limits, simulation, delivery, and settlement controls in the runtime stack.

How It Works

01

Scan the repository

Doctor parses supported JavaScript and TypeScript and maps selected x402 imports and aliases.

02

Review precise findings

Each finding names the file, source location, x402 call type, and missing or incomplete policy state.

03

Patch and keep it in CI

Add a recognized syntactic abort or denial return to the real client path, rerun Doctor, and retain the check on pull requests.

Built for Coding Agents

Built for maintainers and coding agents

The repository includes CLI help, a GitHub Action, SARIF, a machine-readable corpus, agent instructions, and exact limitations.

Open documentation

A narrow x402 rule you can inspect and challenge.

Monarch Shield does not promise complete payment safety or prove general reachability. It checks for specific syntactic abort or denial returns and rejects obvious constant-dead branches.

Payment code changes Doctor checks before merge

Try it on a repository with payment code

Run the scanner locally, inspect every finding, and open an issue with a minimal fixture if Doctor misses a pattern or reports a false positive.

View the GitHub repository