Updated
View as MarkdownCLI
The twelvebit CLI sets up a project from the terminal. It has no dependencies and needs Node.js 18 or later. Run it with npx, no install needed:
npx -y twelvebit@latest <command>init
npx -y twelvebit@latest init example.com- Signs you in with a device code. The link and the code are the first lines that the CLI prints, and it opens
https://twelvebit.app/deviceat once. Check that the code in the browser is the same, then approve. If the codes differ, deny. One approval per computer is enough: the sign-in is saved in~/.twelvebit/config.json, andinit,link,loginandbillingreuse it. Ifinitstops before the approval (for example at the command timeout of a coding agent), run it again: it continues with the same code and opens no new tab (since 0.3.2). - Finds the site for the domain, or creates it (with the time zone of your computer).
- Creates a site key named "CLI (your hostname)" and writes
TWELVEBIT_API_KEYto.env, but only when.gitignorecovers.env. Otherwise it prints the key once and tells you where to put it. The key gets the scopesread,write:eventsandwrite:config. Use--scopes read(or another comma-separated list ofread,write:events,write:config,admin) to limit it. See Scopes. - Writes a starter
analytics.yamlif there is none. - Writes agent guidance into the repo (see skills).
--no-skillsskips this step. - Detects the framework from
package.jsonand prints the script tag and where it goes. - Prints the next prompt for your coding agent.
This is the same workflow as the setup prompt in the dashboard and on the home page: the prompt tells the agent to run init, and no key passes through the chat.
Without a domain, init uses project: in analytics.yaml, then homepage in package.json. You can run init again at any time: it keeps what exists and reports the status.
Use the production domain. init refuses localhost, 127.0.0.1 and other local addresses: twelvebit does not track local development, by design (the script ignores those hosts and the server accepts events only from the site's domain). Verify the setup on production with status or check.
link
npx -y twelvebit@latest link example.comLinks this project to a site that already exists and never creates one. It signs you in like init (or uses the saved session), makes a site key for the project and writes TWELVEBIT_API_KEY to .env with the same rule as init (only when git ignores .env). When analytics.yaml exists without project:, it adds the domain. Without a domain, it uses project: in analytics.yaml, then homepage in package.json, then your only site. When no site matches, it lists the sites you can link and changes nothing. --scopes works as for init.
login, logout, whoami
login signs in with a device code, like init, without touching the project. logout removes the saved session for this server from ~/.twelvebit/config.json (it does not change .env). whoami shows the signed-in account and the site of the key in .env.
skills
Coming in 0.3.3.
--agentis not in the CLI on npm yet (0.3.2):npx -y twelvebit@latestignores the flag until 0.3.3 is published. Agents: do not use it yet.
npx -y twelvebit@latest skillsWrites a twelvebit section (between <!-- twelvebit:start --> and <!-- twelvebit:end -->) and the Claude Code skill .claude/skills/twelvebit/SKILL.md. They tell coding agents how to track events, run check and query the data through MCP. Claude Code reads CLAUDE.md and other agents read AGENTS.md. With --agent claude (or inside Claude Code, which the CLI finds by itself) the section goes in CLAUDE.md; with --agent codex, cursor or other it goes in AGENTS.md. The CLI creates that file when it is missing and also updates the other file when it exists. Without an agent, the section goes in AGENTS.md, or in CLAUDE.md when the repo has only that. A CLAUDE.md that links to AGENTS.md (a symbolic link or an @AGENTS.md line) gets no second copy. Other text in the files stays as it is. A re-run replaces only the section. The CLI refuses to write through a symbolic link.
validate
Checks analytics.yaml against the full schema without network: keys, names, types, enums, funnels, reserved names and names that would collide in generated code (a_1 and a1). It prints every problem with its path and exits with code 1. push and codegen run it first.
push
Uploads analytics.yaml. The server validates it and answers with the events that were added, removed and changed.
pull
Downloads the stored plan into analytics.yaml. Use --force to replace a local file that differs. The server does not keep comments, so the pulled file has none.
check
npx -y twelvebit@latest check --strictScans the source files (or the paths you give) for twelvebit("…") calls, track.…() calls and data-tb-goal attributes, and compares them with analytics.yaml: undeclared events, planned events not used, undeclared props, values outside an enum, missing required props and a stale analytics.gen.ts. With a site key it also reads the props the site received in the last 7 days (prop_drift in the install check). --offline skips that request, so the check needs no network and runs in CI and in broken builds. --strict exits with code 1 on drift. See Tracking plan.
With a site key, check also reports the install (since 0.3.2): "Receiving events from <domain>", or "Waiting for the first event from <domain>" with a look at https://<domain>/ (does the production page have the script tag yet?). Set TWELVEBIT_CHECK_URL to check another page. The install part never fails the check. It warns when the code turns on local tracking (data-allow-localhost) or when project: in analytics.yaml is a local address, because local development is not tracked, by design.
codegen
Writes analytics.gen.ts with one typed function per event, then pushes the plan. --no-push skips the push.
--server also writes track.server.ts (or the file in --server-out): a typed helper for Node servers with no dependencies. It reads TWELVEBIT_API_KEY (a site key with the write:events scope) and TWELVEBIT_URL from the environment and posts to the API:
import { track, identify, payment } from "./track.server";
await track.signupCompleted({ user_id: user.id }, { method: "google" }); // POST /api/v1/events
await identify({ visitor_id: req.cookies._tb_vid, user_id: user.id }); // POST /api/v1/identify
await payment({ amount: 49, currency: "USD", plan: "pro", renewal: false, // POST /api/v1/payments
transaction_id: invoice.id, visitor_id: req.cookies._tb_vid });A failed call throws TwelvebitError with status, code, message and hint from the API. The file compiles under tsc --strict. Keep it out of browser code: it reads a secret. check reports when the file is out of date.
integrations status
npx -y twelvebit@latest integrations status
npx -y twelvebit@latest integrations status stripe --jsonShows each integration (payment providers, stores, Search Console, Meta Ads, Google Ads, GitHub): connected or not, the last sync, the last event and the last error, from GET /api/v1/integrations. It never shows a secret. For an integration that is not connected it prints the dashboard link where a person connects it. --strict exits with code 1 when a connected integration has an error.
exclusions
npx -y twelvebit@latest exclusions
npx -y twelvebit@latest exclusions add --ips 203.0.113.0/24 --paths "/admin/**" --hostnames staging.example.com
npx -y twelvebit@latest exclusions remove --countries DE
npx -y twelvebit@latest exclusions add --hidden-countries RU --yesShows, adds or removes the entries of Settings → Exclusions: IP addresses and ranges, paths, hostnames, countries and hidden countries. Values are comma-separated. It calls GET and POST /api/v1/sites/{siteId}/exclusions, so the server checks each entry the same way as the dashboard (an entry that is not an IP address or range fails with invalid_ip). Adding an entry that is there changes nothing. --hidden-countries also hides the country's past data in every report (nothing is deleted), so add needs --yes. Changes need a key with write:config. --json prints the lists and the change_note.
billing
npx -y twelvebit@latest billing
npx -y twelvebit@latest billing checkout --plan growth --tier 100k --interval year --openbilling (or billing status) prints the plan of your account from GET /api/v1/billing: the status, the trial end, the events used in this monthly cycle against the plan, the sites and people against the limits, and whether the dashboard asks for a plan. Tracking never stops, whatever the state. billing checkout makes a Dodo Payments checkout link with POST /api/v1/billing/checkout (--plan starter|growth, --tier 10k|100k|200k|500k|1m|2m|5m|10m, --interval month|year; --open opens it): the person pays on Dodo's page, and the CLI never sees card data. With an active plan it changes the plan instead. It uses the saved sign-in (login), or a key with the admin scope. Only the account owner sees the details. On a server without billing, billing says that billing is not live there. --json prints the raw data.
status
Prints the install check: the first event from the production domain, recent events, counts, hosts, and which planned events have arrived. Until the first event arrives, it says "Waiting for the first event from <domain>" and what to do: deploy, then open the production site in a normal browser. Local development is not tracked, by design. --json prints the raw response.
mcp
npx -y twelvebit@latest mcp claude # prints the command for Claude Code
npx -y twelvebit@latest mcp claude --run # runs itAgents: claude, codex, cursor. With --run, Claude Code gets the site key from .env as a header, so it needs no browser approval (the CLI hides the key in the output). See MCP.
open
Opens the site's dashboard in the browser.
upgrade
npx -y twelvebit@latest upgradeReads the latest version of the twelvebit package on npm, compares it with the version that runs, and prints the command that runs the latest (npx -y twelvebit@latest <command>). It never installs or changes anything. --json prints current, latest and update_available.
Options and environment
| Option | Default | What it does |
|---|---|---|
--url | TWELVEBIT_URL, then https://twelvebit.app | The twelvebit server |
--env | .env | The env file for TWELVEBIT_API_KEY |
--manifest | analytics.yaml | The tracking plan file |
--out | analytics.gen.ts | The codegen output file |
--server-out | track.server.ts next to --out | The server codegen output file (codegen --server) |
| Variable | Use |
|---|---|
TWELVEBIT_API_KEY | The site key. Read from the environment, then from the env file. |
TWELVEBIT_URL | The twelvebit server, for self-hosting or local development. |
The device sign-in is saved in ~/.twelvebit/config.json (file mode 600), one entry per server.