/polar:polar-configfrom Polar
Manages a Polar billing catalog as code using polar.config.ts/json and the Polar CLI. Handles meters, benefits, products, prices, validation, drafting, publishing, and pruning.
Ships in Polar. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
A billing config is one file that declares an organization's meters, benefits and products. The Polar CLI compares the file with what is on Polar, then drafts and publishes the difference, so a pricing change is reviewed like any other code change.
| File | For |
|---|---|
polar.config.ts | JavaScript and TypeScript projects |
polar.config.json | Every other project: Python, Go, Ruby, PHP and so on |
A Python project uses the JSON file, plus a generated file of names for its code (Step 5).
The other way to manage a catalog is the dashboard, which every organization uses until config is turned on. Use this skill when the project has a config file or the user asks to manage the catalog in code. Don't move an organization to a config file on your own: mention it when it fits and let the user choose.
You do the engineering: write the file, run the commands, fix what they report. The user decides the business.
--json to every polar command you run, and read its fields, not its text. Each step below lists them. Tell the user the result in your own words, with amounts as money: price_amount: 2500 is $25.00, and a metered unit_amount is in cents too.validate changes nothing. Run it as often as you need.init, draft, publish and disable change the organization. Run each only after the user has said yes to what it will do.Look for polar.config.ts or polar.config.json in the project. If there is one, go to Step 2.
If there is none, init writes it from the organization's existing meters, benefits and products. Tell the user what it does and wait for a yes:
disable undoes this, but only until a second catalog version is published.The commands in this skill need the Polar CLI: npm install -g @polar-sh/cli.
polar auth whoami --json
polar config init --sandbox --json
whoami returns the active organization, with its slug and environment, and the signed-in environments. When the account has several organizations, run polar auth org <slug> once to make one active for every command; --org <slug> overrides it for a single command. The config file does not record which organization it belongs to, so before draft or publish check that whoami shows the right one, and ask the user when you cannot tell.
If the CLI is not signed in, and the user has not already told you in setup-polar, ask whether they have a Polar organization:
polar auth login --sandbox, which opens a browser.POST /v1/organizations/ (a name and a slug). Then run this skill's commands with your access token: POLAR_ACCESS_TOKEN=<access token> POLAR_ENVIRONMENT=sandbox polar config init --json. Once the catalog is in place, hand the organization over with a claim: ask for the email address the user will sign in with, and put the full verification_uri and the user_code in your reply, copied exactly. After the claim, use the access token it returns; the old one stops working. Until the claim succeeds the user can't open the organization in the dashboard, so don't give them a dashboard link before then. Only if they ask to create it themselves, send them to https://sandbox.polar.sh/start, then they run polar auth login --sandbox.init picks the format from the nearest project file: TypeScript with a package.json, JSON with a pyproject.toml or with neither. Pass --format ts or --format json to choose. For TypeScript it also installs the package the config imports.
init fails with "already exists" when the config file is there. Don't work around it: the file is the config, go to Step 2.
Read the result:
status | What to do |
|---|---|
written | The file is at file. Tell the user what imported counts and list everything in skipped: those resources stay on Polar as they are and are not in the file. For a new organization the sections are empty; Step 2 shows what goes in them. |
external_ids_required | Nothing was written. Show the user the suggested IDs in external_ids. Run polar config init --json --confirm to accept them all, or pass --external-id <id>=<external ID> for each one they want to name. |
Three rules hold in both formats:
external_id field in JSON, and it is how Polar matches an entry to an existing resource. Changing it removes the old resource and creates a new one, so never rename one. To change what customers see, change the name.., _, : and -. Prefer snake_case: it stays a valid name in generated code."products": [] takes every product off sale. validate lists these as removed, with reason: "missing". Nothing is deleted on Polar and customers keep what they have, but treat every removal validate reports as something the user must have asked for. The same holds inside settings: see Settings below.Each section is a function that receives its helpers and returns the entries by key. Amounts are in the currency's major unit: usd(29) is $29.00. Every price in a product must list the same currencies.
import { defineConfig, eq, eur, perThousand, usd } from '@polar-sh/config'
export default defineConfig({
meters: ({ meter }) => ({
api_calls: meter('API calls').where(eq('name', 'api_call')).count(),
tokens: meter('Output tokens')
.where(eq('name', 'completion'))
.unit('token')
.sum('output_tokens'),
}),
benefits: ({ flag, credits }) => ({
priority_support: flag('Priority support'),
included_calls: credits('Included API calls').meter('api_calls').units(1000),
}),
products: ({ product, free, fixed, meter }) => ({
free: product('Free').prices(free()).recurring('monthly'),
pro: product('Pro')
.prices(
fixed().amount(usd(29), eur(27)),
meter('api_calls')
.flat()
.amount(perThousand(usd(2)), perThousand(eur(1.9))),
)
.recurring('monthly')
.grants(['priority_support', 'included_calls']),
}),
})
eq, ne, gt, gte, lt, lte, like, notLike, and, or, then aggregate with .count(), or .sum, .avg, .min, .max or .unique of a property. eq('name', 'api_call') matches the event name. A config with an events section (a schema per event) selects events with .on(events.api_call) instead; follow whichever the file uses.flag(name), a feature the app checks, or credits(name).meter(key).units(n), usage included before a metered price charges. Add .rollover() to carry unused credits over..prices(...), then .recurring('monthly'), .recurring('yearly'), .recurring(3, 'months') or .once(), and optionally .grants([...]), .trial(14, 'days') and .description(text).free(), fixed(), seats(), units() and meter(key). Tiered prices use .graduated(...) or .volume(...) with tier(). A product takes at most one fixed or free price, one seat-based or unit-based price, and one price per meter; anything else is a type error.The package is fully typed. For anything not shown here, read its type declarations in node_modules rather than guessing: a wrong helper or an unknown meter or benefit key is a type error.
settings holds organization-wide settings in four groups: payments (the default currency, and tax: location, inclusive or exclusive), subscriptions, customerPortal and customerNotifications. Keys are camelCase in TypeScript (allowMultipleSubscriptions) and snake_case in JSON (allow_multiple_subscriptions). Settings take effect on publish.
settings describes every setting. One it leaves out goes back to its default, and validate shows that reset as a change. A file with no settings section leaves the organization's settings alone.init and reset write only the settings that differ from their default, and an empty settings when none do. So a short or empty section is correct: never delete the section or a line in it to tidy up, and never add a setting the user did not ask for.For the settings in each group, read the package's types in TypeScript; in JSON, validate names the keys a group accepts.
The file is one object. Each section is a list, and each entry carries its external_id. Entries refer to each other by external ID: a benefit names its meter, a product lists its benefits.
{
"meters": [
{
"external_id": "api_calls",
"name": "API calls",
"filter": { "conjunction": "and", "clauses": [{ "property": "name", "operator": "eq", "value": "api_call" }] },
"aggregation": { "func": "count" }
}
],
"benefits": [
{
"external_id": "priority_support",
"description": "Priority support",
"type": "feature_flag"
},
{
"external_id": "included_calls",
"description": "1,000 API calls a month",
"type": "meter_credit",
"properties": { "meter": "api_calls", "units": 1000, "rollover": false }
}
],
"products": [
{
"external_id": "free",
"name": "Free",
"recurring_interval": "month",
"prices": [{ "amount_type": "fixed", "price_currency": "usd", "price_amount": 0 }],
"benefits": []
},
{
"external_id": "pro",
"name": "Pro",
"recurring_interval": "month",
"prices": [
{ "amount_type": "fixed", "price_currency": "usd", "price_amount": 2900 },
{ "amount_type": "metered_unit", "price_currency": "usd", "meter": "api_calls", "unit_amount": "0.2" }
],
"benefits": ["priority_support", "included_calls"]
}
]
}
Money is in cents, and this is where JSON configs go wrong. There are no helpers like usd(29), so check every amount twice, and read each one back against what the user said.
| Field | Written as | Example |
|---|---|---|
price_amount on a fixed price | Whole cents, a number. 0 is free. | 2900 is $29.00 |
unit_amount on a metered or tiered price | Cents per unit, a string, fractions allowed | "0.2" is $0.002 per call, so $2 per 1,000 |
cap_amount | Whole cents, a number | 10000 caps the charge at $100.00 |
filter holds clauses joined by conjunction (and or or). A clause has a property, an operator (eq, ne, gt, gte, lt, lte, like, not_like) and a value. The property name is the event name; any other property is read from the event's metadata. aggregation is { "func": "count" }, or sum, avg, min, max or unique with a "property". unit is optional: scalar (the default), token, or custom with a custom_label.type is feature_flag, a feature the app checks, or meter_credit, usage included before a metered price charges, with properties naming the meter, the units and whether unused units rollover.recurring_interval is day, week, month or year; add recurring_interval_count for every 3 months. Leave recurring_interval out for a one-time purchase. It cannot change once the product exists. Optional: description, and a trial with trial_interval and trial_interval_count.amount_type is fixed, metered_unit, metered_tiers, seat_based or unit_based. A free plan is a fixed price of 0. A metered price needs a recurring product.metered_tiers, seat_based and unit_based) go in "tiers": { "type": "graduated", "tiers": [...] }, with volume as the other type. Each tier has a unit_amount and a bound, the last unit it covers; the last tier has no bound.Unknown keys, comments and trailing commas are rejected. For anything not shown here, write your best guess and run validate: an error names the field and lists the values it accepts. When the organization already has resources, the entries init wrote are the most reliable examples.
polar config validate --json
entries lists each resource by section and id, with an action of created, updated, unchanged or removed, and for a change the diff of each field, before and after.issues lists problems with a severity (error or warning), a code, the path of the entry (meters.tokens.name), a message and the location in the file.live is the live catalog, as id and name (its version), or null.draft is the unpublished draft, or null: drift lists changes in the file that the draft lacks (null when the file has errors), conflicts changes the draft has that the file lacks (Step 4).Fix every issue with severity error in the file and validate again. Show every warning to the user and act on it. "No events with this name have been received yet" is expected until the app sends that event; check the event name for a typo, then move on. new_version_id means publishing gives an existing product, benefit or meter a new Polar ID: its message names the current ID and the external ID to use instead (Step 5).
If validate reports a change to something you did not touch, the file is out of date with Polar. Stop and show the user instead of drafting over it.
Then tell the user in plain words what would be created, updated and removed, with the old and new value of every price that changes.
When an existing product, benefit or meter is updated, publishing gives it a new Polar ID. Before you show the plan, search the app for its current ID: an env variable such as POLAR_PRODUCT_ID, or the ID itself in code or .env files. If the app uses one, say in the plan that publishing will break that code, and include switching it to the external ID (Step 5) as part of the change, so the user's yes covers both.
Ask before each command. --confirm skips the CLI's own question, which a shell without a terminal cannot answer, so the user's yes to you is the confirmation.
polar config draft --confirm --json
polar config publish --confirm --json
Their output says what happened; no need to validate again to confirm:
draft saves the file to the draft catalog; nothing a customer sees changes yet. status is applied, rejected (the file has errors, in issues) or conflict (below). With applied, entries are as in validate, issues holds any warnings and draft is the draft catalog as id and name.publish makes the draft live: new checkouts sell it. Existing customers stay on the version they bought. published is true when the draft went live, false when there was none. live is the live catalog, whose name is its version (v1, v2, ...), and draft is now null. There is no status or version.draft stops with "status": "conflict" when the draft on Polar has changes the local file lacks, such as a teammate's change drafted from a copy of the file they have not committed. Carrying on would throw those away. conflicts lists them like entries: action is what the draft did, and diff goes from the file's value (before) to the draft's (after). Don't pick a way out yourself: show the user that list and ask which of these they want.
polar config draft --force --confirm --json makes the draft on Polar match the local file and discards the other changes.polar config reset --confirm --json rewrites the local file to match Polar: the draft when there is one, the live catalog otherwise (source). It replaces the whole file, so comments and anything not on Polar are lost.publish needs the owner or admin role. If it says "You don't have permission to publish the catalog", tell the user an owner or admin has to publish.
validate, draft and publish read the organization's catalogs first, which needs the catalogs:read scope, and publish also needs catalogs:write. If a command fails because one of them is missing, the login predates these scopes: ask the user to run polar auth login again. With an access token, the token needs that scope.
Between draft and publish, four things look wrong and are not:
validate still lists the drafted changes in entries, because it compares the file with the live catalog. draft.drift is empty once the draft has them.draft run again reports the same entries as created or updated.publish: publish before you test usage.publish makes a new catalog version (v1, v2, ...) and gives a changed product a new ID on Polar. The old one stays for its customers, which is why code uses external IDs (Step 5).publish ships the draft, not the file. Before publishing, run validate and publish only when draft.drift is []. If it lists changes, the file changed after the last draft: run draft again first. If the user took a change back after it was drafted, it shows up there too: say so and show them; do not publish over it.
When the user asks for production, a separate organization with its own catalog, have them run polar auth login --production, check polar auth whoami --json, then repeat Steps 3 and 4 with the same file.
| The user wants to | Do this |
|---|---|
| Rename what customers see | Change the name. Keep the key. |
| Change a price | Edit it, draft and publish. Existing subscribers keep their price. |
| Stop selling a product | Mark it deprecated, draft and publish. Don't delete the entry: a product with active subscriptions that is missing from the file is an error. |
| Change what a meter counts | Polar rejects a change to the filter or aggregation of a meter that has billed usage. Add a new meter under a new key and deprecate the old one. |
| Clean up the file | Run polar config prune --confirm --json. It removes deprecated entries nothing uses any more and changes nothing on Polar. entries lists every deprecated one with its customers_count and referenced_by; removed says whether the file changed. |
Deprecate with .deprecated() in TypeScript and "deprecated": true in JSON. A deprecated entry stays for the customers who have it, and nothing new can use it. A live product cannot grant a deprecated benefit: take the benefit out of the product's list first.
Application code refers to the config by external ID: the product to sell, the benefit to check, the meter to read, the event to send. A typo in one of those strings fails silently at run time.
With a JSON config, generate them:
polar config generate --json
It writes one file (file, with status written or unchanged) next to the config with the external IDs and event names as constants and types. For a Python project that is polar_types.py:
from polar_types import Benefits, Events, Meters, Products
Products.pro # "pro"
Events.api_call # "api_call", from the meters' filters
pyproject.toml, requirements.txt, setup.py or Pipfile means Python). Pass --language py when it cannot tell. Python is the only language so far; in another language, use the external IDs as plain strings.--out src/myapp/polar_types.py puts the file elsewhere. It never replaces a file it did not write.polar config generate --check writes nothing and fails when the file is missing or out of date; add it to CI, with the same --out if you used one.The API takes external IDs directly from version 2027-01. Import the client from polar.v2027_01 in Python or @polar-sh/sdk/2027-01 in TypeScript, and pass the generated names where you have them, such as external_products=[Products.pro].
Products, benefits, meters and custom fields are versioned: each published change gives one a new Polar ID; its external ID (a custom field's slug) stays the same. A stored Polar ID goes stale: a checkout with an old product ID fails with "Product is no longer sold", and an old benefit or meter ID won't match what new customers get.
Never keep one in the app's code, config or env file (no POLAR_PRODUCT_ID) or paste in the new ID after a publish. Pass the external ID; Polar resolves it to the version on sale:
| The app wants to | Pass |
|---|---|
| Sell a product | external_products to checkouts.create |
| Change a subscription's plan | external_product_id to subscriptions.update |
| Start a free plan or a trial without a checkout | external_product_id and external_customer_id to subscriptions.create, in @polar-sh/sdk 1.4.0 or later. The customer must already exist |
| Check or grant a customer's benefit | external_benefit_id to benefitGrants.list or benefitGrants.create |
| Read or credit a customer's meter | external_meter_id to customerMeters.list or customerMeters.credits |
| Filter subscriptions, orders, checkouts or metrics by product | external_product_id |
| Fetch the product, benefit or meter itself, such as the prices on a pricing page | external_id and catalog_status: "live" to products.list, benefits.list or meters.list |
import { createPolar } from "@polar-sh/sdk/2027-01";
const polar = createPolar({ accessToken: process.env.POLAR_ACCESS_TOKEN! });
const { items } = await polar.products.list({ external_id: "pro", catalog_status: "live" });
const pro = items[0]; // the version on sale, or undefined when "pro" is not live
In Python: polar.products.list(external_id=Products.pro, catalog_status="live").items. The token needs a read scope, such as products:read.
Keep catalog_status: "live": without it the list also returns retired and drafted versions, even with is_archived: false.
subscription.product.external_id. Customer state has only benefit_id and meter_id, so filter by external_benefit_id or external_meter_id instead.custom_field_data is keyed by slug, which never changes.Once the config is in the repository, CI can show every pricing change on its pull request and save or publish it when it merges. Set this up only when the user asks, with the polar-config-ci skill.
To sell the products, hand off to polar-integration for the Checkout, Customer Portal and Webhooks endpoints, following "Projects with a billing config" in its Checkout recipe so the app sells by external ID, and to polar-testing to try them in sandbox. polar-integration is written for TypeScript; in another language, build the same endpoints from the SDK docs and the API reference, with the external IDs from Step 5.
What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
Other plugins' skills for the same job
npx claudepluginhub polarsource/agent-toolkit-source --plugin polar2 plugins ship this exact skill · first indexed Dec 3, 2026
6 skills in this plugin
/polar-config-ciSet up CI for a Polar billing config (polar.config.ts or polar.config.json). Use this skill whenever the user wants to: (1) show the changes a pull request makes to the config as a comment on it, with polar config validate --pr-comment; (2) save the config to the draft or publish it when a pull request merges; (3) create the access tokens and repository secrets CI needs for that; (4) fix a config workflow that fails in GitHub Actions or Buildkite.
/polar-integrationAdd Polar billing to a TypeScript/JavaScript app using the @polar-sh/sdk package. Use this skill whenever the user wants to add a Checkout endpoint, a Customer Portal endpoint, or a Webhooks endpoint for Polar to any framework — Next.js, Express, Hono, Astro, SvelteKit, Remix, TanStack Start, Nuxt, Fastify, Elysia, Deno, Supabase Edge Functions, Cloudflare Workers, Bun, etc./