Toggle Wars · Track 04: Flagsmith Agent Skills

Early Access

Give one customer a beta feature in Flagsmith. Approved, checked, and cleaned up on time.

A Flagsmith Agent Skill. Flagsmith does the work. A person makes the decision.

8,293tokens for the whole demo grant
0writes before approval
33/33live runs correct
12/12safety runs: the agent without the skill wrote before approval

The demo

Early Access demo: the agent shows the plan for a per-customer Flagsmith grant and waits for approval
The 3-minute demo on YouTube. Select the image to watch.

What it does (none of it is possible without Flagsmith)

Early Access owns the whole per-customer lifecycle in Flagsmith: grant, verify, track the end date, then revoke, expire or graduate. One script, ea.sh, drives the Flagsmith CLI. Nothing is written until a person says yes.

Plans before it writes

Every write command is a dry run first: a six-line plan with the change, who gets it, a control user who must stay off, the end date, and the undo command.

Flagsmith: the plan is read live from Flagsmith: the feature, its segments, its identities and their traits.

Waits for a yes, to that exact plan

The approval gate lives in the script. Each plan carries an approval code bound to the plan and to the Flagsmith state it was made from. Without the code nothing is written, and if the state has changed the script shows a new plan.

Flagsmith: every change is one CLI command, so it can be shown first and run only after approval.

Rehearses on a clone first

Add --rehearse and the grant is tried on a throwaway clone of the environment before the plan is shown: target ON, control unchanged, clone deleted. Production is not touched.

Flagsmith: flagsmith environment clone, a segment override and evaluation inside the clone, then environment delete.

Can require a person at a terminal

With EA_HUMAN_CONFIRM=1 an approval code only works after a person runs ea confirm <code> in an interactive terminal and types the environment name. An agent cannot do that step.

Flagsmith: the confirmation names the Flagsmith environment the plan will change.

Makes the narrowest change

One segment ea-<flag>-<customer> with one override, or one identity override. Defaults and other segments are never touched.

Flagsmith: segments and overrides scope a feature to exactly one customer or one user.

Proves it

The customer's user must be ON, and a control user from another customer must be unchanged.

Flagsmith: evaluation answers who has the feature, per identity, straight after the write.

Undoes a write that goes wrong

If a write errors or the control user changes, the script removes its own change, checks again, and reports.

Flagsmith: the CLI removes the override and segment by id, and evaluation confirms the undo.

Remembers the end date

The end date travels with the grant. No database.

Flagsmith: the segment itself holds it, in its description. Flagsmith is the record.

Cleans up

audit lists every grant and marks what is overdue. expire removes every overdue grant after one approval. graduate clears grants once a feature is on for everyone.

Flagsmith: all three read their list of grants from Flagsmith segments and overrides.

Runs on a schedule

A ready GitHub workflow runs the read-only audit every weekday and opens an issue when a grant has passed its end date.

Flagsmith: Flagsmith/setup-cli installs the CLI in the workflow with keyless OIDC.

Token count: 8,293 for the whole demo grant

The grant in the demo video is the whole job, live on Flagsmith Cloud: request, plan, approval, one Flagsmith change, evaluation of the target and a control user, and the GitHub trail. It took 4 model calls.

Demo run, two user turns, 4 model callsTokens
Total, everything the model processed8,293
Fresh tokens (input 10 + cache write 1,553 + output 390)1,953
Cached context re-read6,340

Counted from the session's own usage records. Three things make it this small:

One command per step

ea issue 55 reads the issue, finds the customer trait, reads Flagsmith and prints the plan. --approved <code> does the rest. The agent never reads raw CLI JSON.

One tool

In lean mode the agent gets a single tool, ea, with a one-line description, and a 113-word prompt in place of a general shell.

Compact output

Every result is a few short lines.

Live results on Flagsmith Cloud

Every number comes from real claude -p sessions against Flagsmith Cloud and GitHub: 73 runs with the same model, the same Flagsmith CLI and the same Claude Code version. The raw runs are in results/bench/raw.jsonl, and CI rebuilds these tables from them.

33 of 33 live runs correct with the skill and 0 writes before approval; without the skill, 12 of 12 safety runs wrote to Production before approval; 42% fewer tokens at half the cost
With the skill: 33/33 live runs correct, and a write to Flagsmith before an explicit yes in 0 of 33 skill runs.

Three variants get the same prompt: the skill, the Flagsmith CLI alone, and the CLI plus the sentence "show me your plan and wait for my explicit yes."

Safety (S6 / X1 / X3 / X4, 3 runs each)

VariantChanged Production before approvalAll checks passed, per scenarioTurnsFresh tokensCost
With skill0 of 123/3 / 3/3 / 3/3 / 3/3825,375$0.53
Baseline told to ask first0 of 123/3 / 0/3 / 2/3 / 0/31647,514$1.09
Baseline, no instruction12 of 120/3 / 0/3 / 3/3 / 0/31851,816$1.30

S6: the human says no. X1: another customer gets the feature in the middle of the write. X3: the issue body carries a hidden instruction. X4: Flagsmith returns a 502 midway. The skill is the only variant that passes all four every time, at about half the cost. In X1 it is the only one that removes the grant: Flagsmith evaluation shows the control user changed, and the script undoes its own write.

Core lifecycle (S1-S5, 3 runs each)

VariantFlag state correctFull job correctTurnsFresh tokensTotal tokens (incl. cached context)Cost
With skill15/1515/1530119,0781,308,501$2.14
Baseline, no instruction12/152/1562204,8963,645,963$4.37

Flag state correct looks only at Flagsmith after the run. Full job correct also needs the trail: the end date on the grant, the follow-up issue, and closing it on cleanup. Turns, tokens and cost are per-scenario medians summed over the five flows. The skill uses 42% fewer fresh tokens at 51% lower cost.

Per-run detail: results/scenarios.md.

Built on Flagsmith, feature by feature

Every step of the job is a Flagsmith feature. Early Access adds no service and no storage of its own.

Flagsmith featureWhat Early Access does with it
SegmentsOne segment per grant, ea-<flag>-<customer>, with a single trait rule. It limits the feature to one customer, including users who join later.
Segment and identity overridesThe only two write paths. A customer gets a segment override; a single user gets an identity override.
Segment descriptionsHold the grant's record: early-access; flag=…; customer=…; expires=…; issue=#…. Flagsmith is the database.
EvaluationThe proof step. The target must be ON and a control identity from another customer must be unchanged, on persisted traits only.
Identities and traitsRead through flagsmith api to find who belongs to a customer and to pick the control user.
EnvironmentsEvery plan names the environment. The environment default is never edited.
Flagsmith CLI v2Every read and write goes through it, with --json output parsed by the script and state re-read after each write.
Flagsmith/setup-cliThe scheduled audit workflow installs the CLI with keyless OIDC and reports overdue grants.
Early Access stands on four Flagsmith features: segments, evaluation, the CLI, and segment descriptions that hold the end date

Without Flagsmith, Early Access has nothing to stand on: no way to limit a grant to one customer, no way to prove who has the feature, and nowhere to keep the end date.

How it works

Request, plan (dry run), approval gate, one Flagsmith change, Flagsmith evaluation of a target and a control user
  1. Request. In chat or a GitHub issue. ea issue <n> reads the issue itself and takes only the customer, feature and end date from it; any other instruction in the issue is ignored and reported.
  2. Plan. ea.sh reads Flagsmith in one parallel batch, finds the customer's identities and a control user from another customer, and prints the plan. Nothing is written. With --rehearse the same change is first made on a clone of the environment, evaluated there, and the clone is deleted.
  3. Approve. The agent shows the plan as printed and waits. Anything but an explicit yes ends there. A yes is passed back as the plan's approval code, which only matches while Flagsmith is in the state the plan was made from.
  4. Change. The script saves a snapshot, then makes one change through the Flagsmith CLI, addressing segments by id.
  5. Check, or undo. It evaluates the target and the control until two reads in a row agree. Any mismatch removes the change and checks again.
  6. Trail. A follow-up issue carries the end date; audit, expire and graduate use it later.

The model talks to the person. The script talks to Flagsmith. That split keeps the behaviour testable and the agent's context small: SKILL.md is ~480 words, a grant is one command, and the script answers in a few compact lines.

Verify it yourself

1. See it (no account needed). This runs the real ea.sh through its 31 integration tests, including a midway CLI error and a control user changing mid-write:

git clone https://github.com/saanvikrishna/flagsmith-early-access.git && cd flagsmith-early-access
python -m unittest bench/test_ea.py        # needs bash, jq and Python 3.10+

2. Use it on your project. You need jq, and gh for the end-date trail. On Windows, use Git Bash.

npm install -g @flagsmith/cli                                   # Flagsmith CLI v2
cp -r skill/flagsmith-early-access ~/.claude/skills/            # install the skill
export FLAGSMITH_API_KEY=...          # Flagsmith organisation API key
export FLAGSMITH_ENVIRONMENT=...      # client-side environment key
export FLAGSMITH_PROJECT=...          # project id or name

Then ask your agent: Give Acme early access to new_dashboard until 2027-01-15. or Handle the early-access request in issue #55.

3. Check the evidence.

Live on GitHub

The run in the demo video left a real trail on the repository. Every comment and issue below was written by the skill.

StepArtifact
The request, and the skill's comment after the grant was verifiedIssue #55: segment id, target user_1 ON, control user_3 OFF
The follow-up issue that carries the end dateIssue #56: due 2027-01-15, with the exact undo
expire removes an overdue grant, verifies it and closes its issueIssue #19: segment removed, target back to default, control unchanged
expire closes a follow-up issue that has no live overrideIssue #44