CLI.
Nine commands. Small, scriptable, friendly to coding agents. The local commands never call the
network and never ask you to log in. Only dif auth, and dif connect without --key, talk to dif analytics.
Run dif from the repo root or any descendant. It walks upward until it finds dif/config.yaml. Every command takes --json as a global flag for
machine-readable output. Exit codes are documented per command; 0 means success,
non-zero means a specific kind of failure you can branch on in CI.
Run dif --help for the auto-generated overview.
dif site and dif events. Run dif --version to check, and install again to
upgrade.$dif init
Scaffold a dif/ workspace in the current directory. Safe to re-run: when every
dif-owned file already matches what init would write, it changes nothing and exits 0. It refuses to overwrite a dif-owned file whose content differs unless you pass --force.
Flags
| flag | default | notes |
|---|---|---|
--surface <name> | home | Name of the first surface to create. |
--events <mode> | asks, or cloud | How events are delivered: cloud (delivery to dif analytics) or custom (you export the exposure and track handlers in dif/events/). Without the flag, dif init asks on a terminal and
uses cloud otherwise. |
--key <dif_pk_…> | none | Publishable key from your dif analytics project. It sets cloud events mode and writes the
key into dif/config.yaml. It cannot be combined with --events custom. |
--force | off | Overwrite dif-owned files whose content differs: structural files, skill files, and .cursor/rules/dif.mdc. |
--agents <list> | all four | Comma-separated: claude (CLAUDE.md + .claude/skills/dif-*), general (AGENTS.md), cursor (.cursor/rules/dif.mdc), copilot (.github/copilot-instructions.md), or none. Omit to scaffold all
four. none can't be combined with the others. --no-agent-files still works as a deprecated alias for --agents none. |
--agents-only | off | Refresh agent files only: the .claude/skills/dif-* skills, .cursor/rules/dif.mdc, and the managed dif blocks. Rewrites dif's own files, the
skill files and .cursor/rules/dif.mdc, without --force. An edit you
made to one of them is overwritten. Never touches dif/. Combine with --agents to pick targets. Needs a dif/config.yaml in the current
directory. Cannot be combined with --surface, --force, --events, --key, --project-type or --features. |
--project-type <list> | none | Comma-separated kinds of project: marketing, app, ecommerce. Written to project_type. Omit it to
leave the key out of the config. |
--features <list> | all three | Comma-separated list of the enabled features: analytics, flags, experiments. A feature you leave out is written as false under features. With all three on,
the block is left out, which means the same thing. |
--yes | off | Accept the default for every prompt. --json and a non-terminal imply it. |
An unknown value in --project-type or --features is a usage error: exit 2, and with --json the object has "error": "usage". The check
runs before any prompt or write. With --json, the success object also carries project_type (an array, empty when the flag is omitted) and features.
$dif init --project-type app,ecommerce --features analytics,flags --yes --json
Example
$dif init ✓ created dif/experiments/{active,concluded} ✓ created dif/surfaces/ ✓ created dif/audiences/ ✓ wrote dif/config.yaml ✓ wrote dif/.gitignore ✓ wrote dif/surfaces/home.md ✓ wrote dif/audiences/locale.ts ✓ wrote dif/audiences/device_type.ts ✓ wrote .claude/skills/ (dif-author-experiment, dif-conclude-experiment, dif-connect-cloud, dif-generate-surfaces, dif-triage-experiments, dif-setup-analytics) ✓ wrote .cursor/rules/dif.mdc ✓ merged dif guidance into CLAUDE.md ✓ merged dif guidance into AGENTS.md ✓ merged dif guidance into .github/copilot-instructions.md
CLAUDE.md, AGENTS.md, and .github/copilot-instructions.md get a managed dif block; existing content around it
is preserved. .cursor/rules/dif.mdc is dif's own file. A dif block in a legacy .cursorrules from an older dif is refreshed, but a new .cursorrules is
never created. Pass --agents none to skip agent files entirely, or a subset like --agents claude,cursor to scaffold only those. --no-agent-files still
works — it's a deprecated alias for --agents none.
--agents-only is new in dif v0.7.0. After you upgrade dif, run dif init --agents-only to get the new skills and agent guidance. It keeps dif/config.yaml, your surfaces and their learnings, and your audience files as they
are. It overwrites any edit you made under .claude/skills/dif-* or to .cursor/rules/dif.mdc, so commit those first.
Exit codes
| code | meaning |
|---|---|
0 | workspace created, or already initialized with matching files (--json reports "already_initialized": true) |
2 | a dif-owned file exists with different content and --force wasn't passed; also
run from $HOME, an invalid --agents list, an unknown --project-type or --features value, or --agents-only with no dif/config.yaml or with --agents none |
1 | an unexpected filesystem or command error |
invarianta fresh dif init followed by dif validate and dif build passes with zero experiments.
$dif connect
Point an existing workspace at dif analytics. Writes the project's publishable key into the events: block of dif/config.yaml and forces cloud mode, preserving every
other setting and comment. Doesn't build — dif build regenerates the client with the
new key.
There are two paths:
- With a key. Pass the
dif_pk_…key from your dif analytics project. No network call and no login. - With a login. Omit
--key. Connect uses yourdif auth loginsession to link or create the dif analytics project and fetch its key.
Flags
| flag | default | notes |
|---|---|---|
--key <dif_pk_…> | — | The publishable key from your dif analytics project. Rejected if it's empty, malformed, or
looks like a secret server key (dif_live_… / dif_test_…) or a site
key (dif_site_…). Can't be
combined with --org, --project, --create or --name. |
--url <url> | https://cloud.dif.sh | Only needed for a self-hosted deployment. With a login, it must match the host you signed in to. |
--org <slug> | your only org | The org to use. Optional when your login belongs to exactly one org. With --create and several orgs, it is required. |
--project <slug> | — | Link to an existing project. |
--create | off | Create a new project. Can't be combined with --project. |
--name <name> | folder name | Name for --create. The default is the workspace folder name. |
With a key
$dif connect --key dif_pk_live_… ✓ connected dif/config.yaml to dif.sh Cloud next: run dif build to regenerate the client with your key
With a login
Run dif auth login first. Connect then reads your
orgs and uses the only one, or the one --org names. It links the project that --project names, or creates one with --create. With none of these flags
on a terminal, it asks you to pick.
$dif connect --create ✓ connected dif/config.yaml to dif.sh Cloud created project acme-shop (https://cloud.dif.sh/acme-shop) Install the GitHub App to sync specs: https://github.com/apps/dif-sh/installations/new?state=… next: run dif build to regenerate the client with your key
With --json, or with no terminal, connect never prompts. When it needs a choice, it
exits 2 with needs_selection and lists what you can pick from. projects lists the selected org only, or every org when --org is missing.
Run it again with --project or --create:
{
"ok": false,
"error": "needs_selection",
"message": "choose a project: pass --project <slug> or --create",
"orgs": [{ "slug": "acme", "name": "Acme" }],
"projects": [{ "slug": "acme-shop", "name": "acme-shop", "org": "acme", "repo": "acme/shop" }]
}Success:
{
"ok": true,
"project": { "slug": "acme-shop", "org": "acme", "created": true },
"config": "dif/config.yaml",
"mode": "cloud",
"switched_from_custom": false,
"dashboard_url": "https://cloud.dif.sh/acme-shop",
"repo": {
"status": "unlinked",
"detected": "acme/shop",
"github_install_url": "https://github.com/apps/dif-sh/installations/new?state=…"
},
"next": "dif build"
}repo.detected comes from git remote get-url origin when it points at
GitHub, and is null otherwise. repo.status is "linked" when
the project already has a repo, or "unlinked". A new project can wait for its repo:
events flow right away, and spec sync starts after you install the GitHub App from github_install_url. The URL is left out when the repo is linked, and it is null when the dif analytics server has no GitHub App (local or self-hosted). In the needs_selection project list, repo is null for a project
that has no repo yet.
If the workspace was in mode: custom, connect switches it to cloud and warns that dif/events/{exposure,track}.ts are no longer used. See events for both modes. The dif-connect-cloud skill runs
the whole login and connect flow for a coding agent.
Orgs
Every dif analytics project belongs to an org, such as your company or team. Your role in the org sets what you can do in its projects:
| role | what it can do |
|---|---|
owner | Everything an admin can do. Only owners claim email domains and turn domain auto-join on. |
admin | Admin on every project in the org, including new ones. |
member | Gets the role that each project gives it. Can create projects unless an owner turns that off. Cannot use, link or claim GitHub installs. |
There are two ways into an org:
- Invite. An owner or admin invites your email from the org's settings. Then you accept it at cloud.dif.sh/orgs. dif never accepts an invitation for you, not even when you sign in.
- Verified domain. An owner claims an email domain, such as
example.com, that matches their own verified login email. Auto-join is off by default. When the owner turns it on, a login joins the org as amemberwhen it signs in, but only after it verifies an email on that domain. Public mail domains, such asgmail.com, cannot be claimed.
A login with no org gets the no_org error from dif connect --create. Connect does not make an org for you. Ask your team for an
invite and accept it, or create an org.
Then run connect again. With more than one org, pass --org <slug>.
GitHub App installs belong to the org, not to the person who installed them. When you are not an owner of the GitHub org, GitHub asks an owner to approve the install. After the approval, an org owner or admin in dif analytics can link a repo from that install. Members cannot use, link or claim installs.
Exit codes
| code | meaning |
|---|---|
0 | connected |
1 | malformed --key, a filesystem error, or a dif analytics error |
2 | nothing changed: no dif.sh workspace here (no_workspace; run dif init first), not_logged_in, token_invalid, needs_selection, no_org, org_not_found, project_not_found, or usage (--project with --create) |
$dif auth Analytics
Sign the CLI in to dif analytics. The CLI shows a URL and a short code, you approve it in the
browser, and the CLI stores a token. This works over SSH, in a container, and when a coding agent
runs the CLI for you. Only dif connect without --key needs a login.
login
There are three ways to run it:
- Interactive.
dif auth loginprints the URL and code to stderr, opens the browser, and waits for your approval. With--jsonit prints only the final object. - Start, for agents.
dif auth login --no-waitstarts the login, stores the pending code, and returns at once with the URL and code. An agent's shell shows output only after the command exits, so the agent shows the URL and code to you from here. - Finish, for agents.
dif auth login --resumewaits for the code that--no-waitstored.
| flag | default | notes |
|---|---|---|
--no-wait | off | Start the login, print the URL and code, and return at once. |
--resume | off | Wait for the login that --no-wait started. |
--timeout <seconds> | 600 | Stop waiting after this many seconds. On a timeout the command returns authorization_pending and keeps the code, so you can run --resume again. |
--no-browser | off | Print the URL only. The browser also stays closed when stderr is not a terminal. |
A login made before dif site and dif events existed lacks the site:manage and events:read scopes. Those commands then answer missing_scope. Run dif auth login again.
If the login fails with service_unavailable, dif analytics is down for a moment. Run dif auth login --resume once. If that fails too, start a new dif auth login. Until then, you can copy the site key from Settings → Site at cloud.dif.sh.
$dif auth login Open https://cloud.dif.sh/cli/activate?code=WDJB-MJHT and confirm the code WDJB-MJHT ✓ logged in as dev@example.com
The two-step form, as an agent runs it:
$dif auth login --no-wait --json{
"ok": true,
"status": "pending",
"verification_uri": "https://cloud.dif.sh/cli/activate",
"verification_uri_complete": "https://cloud.dif.sh/cli/activate?code=WDJB-MJHT",
"user_code": "WDJB-MJHT",
"expires_in": 600
}$dif auth login --resume --json{
"ok": true,
"status": "logged_in",
"user": { "id": "…", "email": "dev@example.com" },
"expires_at": "2027-02-03T00:00:00Z"
}Check that the approval page shows the same code before you approve. If you have no dif
account yet, sign up on that page; it brings you back to the approval. When you are already
logged in, login starts a new login and replaces the stored token when it succeeds.
| error | exit | when |
|---|---|---|
authorization_pending | 2 | --resume hit --timeout before approval. The pending code is
kept. |
access_denied | 1 | You clicked Deny. The pending code is cleared. |
expired_token | 1 | The code expired. Start again. |
no_pending_login | 2 | --resume ran with no stored pending code. |
status
Shows the current login. It makes no network call unless you pass --verify, and it
never prints the token.
{ "ok": true, "logged_in": false }{
"ok": true,
"logged_in": true,
"source": "file",
"cloud_url": "https://cloud.dif.sh",
"user": { "id": "…", "email": "dev@example.com" },
"expires_at": "2027-02-03T00:00:00Z"
}source is "file" for a stored login or "env" for DIF_TOKEN. For a DIF_TOKEN login, user and expires_at appear only with --verify. --verify asks dif
analytics whether the token is still valid; a rejected token gives token_invalid.
logout
Revokes the token on the server (best effort) and deletes the stored login. A logout with no stored login still succeeds.
{ "ok": true, "revoked": true }"revoked": false means the server call failed or there was no stored login. The local
file is gone either way. Logout never touches DIF_TOKEN; unset it yourself.
Where the login lives
The token goes to $XDG_CONFIG_HOME/dif/credentials.json (default ~/.config/dif/credentials.json) with mode 0600. It starts with dif_cli_ and expires after 90 days without use; each dif analytics call moves the
expiry forward. A stored login is used only with the dif analytics URL that issued it.
| variable | effect |
|---|---|
DIF_TOKEN | A dif_cli_… token, for CI. It wins over the stored login. |
DIF_CLOUD_URL | The dif analytics base URL. The default is https://cloud.dif.sh. A stored login
applies only to the host that issued it, so a local login needs this set. |
DIF_TOKEN, for a dif_pat_… read token. dif auth and dif connect use DIF_TOKEN only when it holds a dif_cli_… token. With a read token there,
they print a note and use your dif auth login instead.JSON output and dif analytics errors
With --json, dif auth, dif connect, dif site and dif events print exactly one JSON
object on stdout and never prompt. Every object has ok. A failure adds a stable error code and an optional message. Branch on error, not on message or the exit code number.
{ "ok": false, "error": "not_logged_in", "message": "run dif auth login" }Exit 0 is success, 1 means the command ran and failed, and 2 means a precondition was not met, so nothing changed. These errors can come from
any command that calls dif analytics:
| error | exit | when |
|---|---|---|
not_logged_in | 2 | No token in DIF_TOKEN or the credentials file. |
token_invalid | 2 | The server rejected the token (revoked or expired). The CLI deletes the stored login. |
forbidden | 1 | The token is valid but lacks the role or scope. |
cloud_unreachable | 1 | DNS, TLS, timeout or connection failure. |
service_unavailable | 1 | The server answered 503: it is down or busy, and nothing changed. This never means zero
events. Wait a minute and run the command again. During login, run dif auth login --resume once, then start a new dif auth login. |
cloud_error | 1 | The server answered another 5xx or sent a body the CLI can't read. |
no_org | 2 | This login has no org, so dif connect --create has nowhere to put the project.
Join or create an org, as orgs says. |
missing_scope | 2 | Your login predates this command. Run dif auth login again. |
not_project_manager | 1 | dif site setup needs a project owner or admin. |
site_analytics_unavailable | 1 | Site analytics is not available for this project yet; dif site setup can't change this. |
site_not_set_up | 1 | No site key for this env. Run dif site setup. |
project_not_found | 2 | No project with that slug for this login. |
needs_selection | 2 | The project is unclear. Pass --project <slug>. |
bad_request | 2 | Dif analytics refused the request. This also covers stored plus new origins over 32, and a non-local origin on a test key. |
usage | 2 | A bad flag value, such as an --origin with a path, or more than 32 origins. |
no_tracking_plan | 2 | dif events --plan, and dif/tracking-plan.yaml is missing or not valid. |
rate_limited | 1 | HTTP 429. retry_after gives the wait in seconds. |
$dif site Analytics
Turn on site analytics for a project and check the install from the terminal. It needs dif auth login and a dif/ workspace. The project is --project,
else the one whose repo matches the git remote, else the only project your login can see. If that
is still unclear, the command answers needs_selection. You do not need to run dif connect first. The dif-setup-analytics skill runs these
commands for you.
setup
Turns site analytics on for one key (live or test) and adds the origins to
the key's allowed list. By default origins are added and never removed; with --replace the list becomes exactly the origins you pass. You can also remove one in Settings → Site. Only
project owners and admins can run it. A test key takes local origins only (localhost, 127.0.0.1, [::1], *.localhost and *.test).
| flag | default | notes |
|---|---|---|
--env live|test | required | Which publishable key to set up. |
--origin <origin> | required, repeatable | scheme://host[:port], no path. Up to 32, counted after adding to the stored list. |
--rate-limit <n> | 6000 for a new key; else unchanged | Events per minute, 1 to 60,000. |
--replace | off | Remove stored origins that you did not list. |
--project <slug> | from the git remote | Which project to set up. |
$dif site setup --env test --origin http://localhost:5173 --json { "ok": true, "project": "acme", "env": "test", "prefix": "0123abcd", "key": "dif_site_test_0123abcd_…", "allowed_origins": ["http://localhost:5173"], "rate_limit_per_min": 6000, "enabled": true }
key is the full publishable site key for env. Put it in the script tag as data-key.
dif_site_…) and the project key
(dif_pk_…) are not interchangeable. The site key sends page views only. Never put it
in dif/config.yaml: track and exposure requests refuse it with 403 site_key_not_allowed. dif/config.yaml keeps the project key that dif connect wrote.The live key is public and can be committed in the tag. A test key lives
only in a dev-only env file that production builds never read. key is null only for older keys whose text was not kept; copy it from Settings → Site.
Without --json it prints key: <key>, or a note to copy the key from
Settings.
check
Opens a 10-minute check window, then prints what the collector accepted and refused in the last
hour. It is the same check as Check live install in Settings → Site, and any
project member whose login has the scope can run it. With --wait <seconds> it
polls every 10 seconds until an event arrives or the time runs out. The refusal table says what each refusal
means.
| flag | default | notes |
|---|---|---|
--env live|test | required | Which key to check. |
--wait <seconds> | 0 | Poll every 10 seconds, up to this many seconds. |
--project <slug> | from the git remote | Which project to check. |
Read status first: seen, unknown_key, unavailable or error. The counts mean something only when status is seen. Otherwise accepted_last_hour, last_accepted_ms, last_origin and pageviews_last_hour are null (null is not zero), and refused_last_hour is all
zeros, which tells you nothing.
$dif site check --env test --wait 30 --json { "ok": true, "project": "acme", "env": "test", "prefix": "0123abcd", "status": "seen", "accepted_last_hour": 3, "last_accepted_ms": 1764068400000, "last_origin": "http://localhost:5173", "pageviews_last_hour": 2, "refused_last_hour": { "origin": 0, "gates": 0, "rate": 0, "bad_request": 0 }, "lines": [ "3 events accepted in the last hour, last at 12:04:31, from http://localhost:5173.", "2 page views stored from the last hour." ] }
$dif events Analytics
Lists each event name dif analytics received in the window, with its count and the time it was last
seen (last_seen_ms, in milliseconds since the epoch). Built-in names start with $, such as $pageview. It reads live data only. Events sent with a test
key do not show here; use dif site check --env test for those. With --plan it reads dif/tracking-plan.yaml (see the tracking plan), marks each row in_plan, and adds each planned event that has not arrived with count 0,
so you see what is missing. The missing list names them.
| flag | default | notes |
|---|---|---|
--since | 24h | 1h, 24h or 7d. |
--plan | off | Add events from dif/tracking-plan.yaml that have not arrived. |
--project <slug> | from the git remote | Which project to read. |
$dif events --since 24h --plan --json { "ok": true, "project": "acme", "since": "24h", "missing": ["checkout_started"], "events": [ { "name": "$pageview", "count": 120, "last_seen_ms": 1764068400000, "builtin": true, "in_plan": false }, { "name": "checkout_started", "count": 0, "last_seen_ms": null, "builtin": false, "in_plan": true } ] }
$dif new
Draft a new experiment file. Reads up to three prior learnings from the surface and embeds them in the brief template as an HTML comment.
Flags
| flag | default | notes |
|---|---|---|
<id> | — | Kebab-case experiment id. Becomes the filename stem. |
--surface <name> | — | Required. Must exist under dif/surfaces/. |
--owner <email> | git config user.email | Falls back to git config. Errors if neither is set. |
--from <id> | — | Clone audience, variants, and exclusion_group from an
existing experiment (active or concluded). Owner, metrics, hypothesis, status, and body are
not copied. |
The draft starts with control and variant_a at 50/50 and today's date.
Example
$dif new checkout-cta-v3 --surface checkout → reading dif/surfaces/checkout.md found 3 prior learnings → drafted dif/experiments/active/checkout-cta-v3.md status: draft, owner: ada@acme.dev
Exit codes
| code | meaning |
|---|---|
0 | drafted |
1 | can't determine owner; pass --owner |
2 | id conflict (already exists) or --from source not found |
3 | surface does not exist |
invariantthe file dif new writes parses cleanly with dif validate.
$dif validate
Run every check against the workspace. Collects all errors and warnings in one pass (no fail-fast), so the report shows everything wrong at once. Writes nothing.
The validator reads:
dif/config.yaml;- every
.mdindif/experiments/active/andconcluded/; - every
.mdindif/surfaces/; - the resolver filenames in
dif/audiences/; .js/.jsx/.ts/.tsxsource fordif("<id>", ...)call sites (skipping.git,node_modules,target,dist,build, anddif/).
Checks, in order:
- Frontmatter parses; required fields present.
(E001) owneris a syntactically valid email.(E003)surfaceresolves to a loaded surface file.(E004)- Variant weights sum to 100.
(E005) - Every audience attribute is declared in
dif/config.yaml.(E006) - Every declared attribute has a resolver in
dif/audiences/.(E008) - Same-surface experiments share an
exclusion_groupor have provably-disjoint audiences.(E007) - Every
dif("<id>", ...)call site maps to an active experiment.(W001, warning)
The call-site scan for W001 skips hidden folders, gitignored paths, node_modules, target, dist, build and dif/. To skip more, such as sample code in your docs, list globs in build.ignore. These skips need dif
v0.11.0 or later; v0.10.0 scans hidden and gitignored folders too.
Every diagnostic code is documented on troubleshooting. --schema-only is reserved for a future fast editor path; today it runs the same full
suite.
Example
$dif validate ✓ all checks passed
$dif validate error E003 dif/experiments/active/bad.md:1:1: `owner` is not a valid email: `not-an-email` help: Use `name@example.com` format. error E008 dif/config.yaml: attribute `plan` has no resolver help: Create `dif/audiences/plan.ts` or run `dif scaffold-audiences`. ✗ 2 error(s), 0 warning(s)
Exit codes
| code | meaning |
|---|---|
0 | no errors (warnings allowed) |
1 | at least one error, or workspace loading failed |
$dif build
Run validate, then compile the runtime artifacts and the agent context file. Aborts
before writing if validation fails.
Flags
| flag | default | notes |
|---|---|---|
--out <dir> | dif/generated | Where to write the TypeScript. Absolute or workspace-relative. Keep it inside the workspace. |
Outputs
<out>/client.ts: registers each active experiment with the SDK by side effect. Deterministic: identical inputs produce byte-identical output.<out>/audiences.ts: theattributes()helper, importing only the resolvers referenced by active experiments. Also deterministic.dif/context.json: the agent context file. Carries a generation timestamp (so it churns on every build) plus a summary of every active experiment, each surface's most recent learning, and project conventions.
Example
$dif build ✓ validated 1 active experiment ✓ client → dif/generated/client.ts ✓ audiences → dif/generated/audiences.ts ✓ context → dif/context.json
Exit codes
| code | meaning |
|---|---|
0 | compiled |
1 | validation, loading, or generation failed |
invariantclient.ts and audiences.ts compile
under tsc --strict and are byte-identical for identical inputs.
$dif qa
Trace one user's assignment chain across every active experiment, and optionally mint a preview link. No exposure events are fired; qa runs entirely against the loaded workspace.
Flags
| flag | default | notes |
|---|---|---|
--user <id> | random | The user id to trace. Omit for a time-seeded synthetic id (so repeated runs sample different buckets). |
--force <exp>=<variant> | — | Force a variant. Repeatable. Bypasses audience and exclusion; emits no exposure. |
--attr <key>=<value> | — | Set an audience attribute. Value parsed as YAML (true, 42, US all keep their type). Repeatable. |
--preview-url <url> | — | Base URL for the preview link emitted when --force is set. |
Example
$dif qa --user u_8131 trace u_8131: • checkout-cta-v2 → variant_a (bucket 7993)
$dif qa --force checkout-cta-v2=variant_a --preview-url https://staging.example.com/checkout trace (synthetic user): • checkout-cta-v2 → variant_a (forced) preview: https://staging.example.com/checkout?_dif=checkout-cta-v2%3Dvariant_a
The preview URL carries a _dif query parameter encoding the forces. The browser SDK
and framework adapters read it and persist the force in a session cookie, so you can share a
screenshot or hand the link to a teammate.
Outcomes
variant (bucket N): bucketed normally; the SDK would fire an exposure for this assignment.variant (forced): picked by--force; bypasses audience.↛ audience miss: user didn't match the audience predicate.↛ exclusion loser (winner: <id>): matched, but a higher-priority experiment in the sameexclusion_groupwon.
Exit codes
| code | meaning |
|---|---|
0 | trace completed |
1 | invalid --force / --attr syntax, malformed YAML, or a workspace
error |
$dif conclude
Conclude an active experiment. Several writes in one transaction:
- Update the frontmatter:
status: active→concluded, setconcluded: <today>. - Replace the
## Decisionsection body. - Move
dif/experiments/active/<id>.md→dif/experiments/concluded/<YYYY-MM>-<id>.md. - Prepend one learning to
dif/surfaces/<surface>.mdunder## Learnings.
Edits are computed before writing; a later filesystem failure rolls back on a best-effort basis.
Flags
| flag | default | notes |
|---|---|---|
<id> | — | Experiment id. Must exist under dif/experiments/active/. |
--decision <text> | $EDITOR | Inline decision text. If omitted, dif opens $EDITOR, then $VISUAL,
then vi. Must be non-empty. |
--skip-learning | off | Don't append to the surface log. Rare; mostly a CI escape hatch. |
Example
$dif conclude checkout-cta-v2 --decision "Shipped variant_a. +2.1% on returning visitors." → moved dif/experiments/concluded/2026-05-checkout-cta-v2.md → drafted ## Decision block → appended to dif/surfaces/home.md "Shipped variant_a. +2.1% on returning visitors."
The first line of the decision becomes the surface log summary, prefixed with the conclusion date
and experiment id. Multi-line decisions stay in the experiment file's ## Decision block; only the first line is duplicated to the surface.
Exit codes
| code | meaning |
|---|---|
0 | concluded |
1 | missing experiment or surface, empty decision, editor failure, or a filesystem error |
invariantafter a successful conclude, dif validate and dif build still pass.
$dif scaffold-audiences
Add the starter audience resolver files to an existing project. Idempotent. Existing files are
kept unless --force is supplied.
Creates dif/audiences/ if needed and writes locale.ts and device_type.ts. It never modifies dif/config.yaml; it prints the
declaration snippet to add under audience_attributes yourself.
$dif scaffold-audiences ✓ wrote dif/audiences/locale.ts ✓ wrote dif/audiences/device_type.ts → add these to dif/config.yaml under audience_attributes: - { name: locale, type: string } - { name: device_type, type: enum, values: [mobile, tablet, desktop] }
Exit codes
| code | meaning |
|---|---|
0 | scaffold completed (including when existing files were kept) |