CLI & SDK

Operate your CDN from your project

@cdnmn/cli puts the whole flow — detect, set up, verify, rewrite, and test — in your terminal, and honors a project’s AGENTS.md. @cdnmn/sdk is the typed client it’s built on, for programmatic access. Both are the same surface an AI agent uses; see For AI Agents.

Install

  • Global: npm install -g @cdnmn/cli (Node 22+), then cdnmn --help.
  • One-off, no install: npx @cdnmn/cli --help.
  • Programmatic: npm install @cdnmn/sdk.

Authenticate

cdnmn login runs the device-claim flow: it prints a code and opens the dashboard, you approve it, and the CLI receives a scoped, 24-hour bearer token. It requests only the scopes its commands need — pass --scopes to widen or narrow. The token is stored at ~/.config/cdnmn/config.json (mode 0600) and is never printed or logged.

In CI, set CDNMN_TOKEN in the environment rather than passing --token (a token on the command line is visible in the process list and shell history). The full auth model — scopes, the per-scope approval valve, and revocation — is in auth.md.

Commands

CommandWhat it does
cdnmn detect <url>Analyze a site and recommend an integration strategy.
cdnmn setup <origin>Create a project and print the domain-verification proof.
cdnmn verify --site <id>Run the domain-ownership check.
cdnmn rewrite [--apply]Rewrite your repo’s image URLs to the CDN host (dry-run by default).
cdnmn test --site <id>Verify delivery: reachability, format negotiation, same-host, size reduction.
cdnmn agents [print|init]Print or write the CDN.MN section of your AGENTS.md.

Rewriting image URLs

cdnmn rewrite walks your repo and points image URLs at your CDN hostname, keeping the same path. It is a dry run by default — it prints exactly what would change; add --apply to write.

--apply auto-writes Markdown only (.md / .markdown). For every other file type — HTML, CSS, JSX/TSX, Vue, MDX — a safe edit needs framework-aware parsing, so the rewrite reports each URL as a manual mapping (the exact from → to) for you or your agent to apply, and writes nothing to those files. What it does and doesn’t touch:

  • It changes only the host — the image path is preserved and it adds no query parameters. Width, quality, and format stay as they were: an image with no w serves at its origin-size default, and sizing is something your own markup supplies (a w you add snaps to your site’s configured ladder — see URL parameters).
  • It rewrites only formats the CDN can serve, and leaves everything else as a reported manual mapping — an already-CDN URL, an external/optimizer host, a URL with a query the edge won’t forward, or an SVG/other vector.
  • It reads a discovered AGENTS.md for a “do not auto-edit” signal — that one rule downgrades --apply to a dry run. It does not interpret arbitrary project rules (path scopes, required commands, per-file bans); the AGENTS.md check can only ever restrict the CLI, never widen what it touches.
  • Every applied change is backed up to .cdnmn-backup/; undo with cdnmn rewrite --revert. It refuses a dirty git tree without --force.

Verifying delivery

cdnmn test --site <id> (or --hostname <cdn…> --path …) fetches a delivered image from your own machine and checks it reaches the CDN with a 200 and an image type, negotiates AVIF/WebP from the Accept header, stays on-host with no downgrade, and — with --origin <url> — is smaller than the original. The request runs from your machine to your own CDN host; it is not a new server-side fetch.

The SDK

@cdnmn/sdk is a typed, zero-dependency client of the agent API (JSON-RPC/MCP over /api/mcp) plus the device-claim flow. fetch is injectable; sensitive mutations return a typed MutationResult (executed | approval_required | dry_run), and waitForApproval polls until the owner decides. It never prints the token — read it from the environment or a secret store at the point of use.

New to the CDN? Start with the Quickstart. Building an agent integration? See For AI Agents.

CLI & SDK — CDN.MN