kind: FeatureFlag
What it is
kind: FeatureFlag declares a runtime toggle that Crewship code
checks at request time. A flag has two layers and the manifest is
designed to write to both in a single document:
-
The instance-global definition — name (
key), description, the defaultenabledstate, and an optionaldefault_percentagefor gradual-rollout flags. This row lives in thefeature_flagstable and is shared by every workspace on the instance. Only an instance administrator who is also OWNER or ADMIN of the target workspace may create, update, or delete it (details). -
The workspace override — an optional per-workspace
force-enable / force-disable that takes precedence over the
instance default. The override row lives in
feature_flag_overrideskeyed by(flag_id, workspace_id). OWNER and ADMIN of the target workspace may write it.
Why two layers in one document
Most operational uses look like: “ship the flag definition with the codebase, then let individual workspaces opt-in (or stay opted-out) without round-tripping through the admin console.” Splitting the two concerns into separate kinds would force two YAML files and two PRs for every flag rollout. Keeping them in one document with an optionalworkspace_override keeps the surface tight and lets
crewship apply reconcile both layers in one phase.
Instance default vs workspace override — concretely
The
workspace_override field is pointer-typed in the Go
struct (*bool). That is deliberate: an absent field means
“inherit”, which is structurally different from “force OFF
(false)”. Re-applying a manifest that omits the field will
is meant to DELETE any stale override the workspace happened to have.
On main it does not (see the limitations above): clear an override
with crewship feature-flag inherit <key>.
Current limitations onmain. TheFeatureFlagkind parses and validates, butcrewship applyonly partly reconciles it today:The sections below describe the intended behaviour and note where
- Apply always sends a create (
POST) for the definition. It does not read existing flags first, so applying a manifest for a flag that already exists fails that item withunexpected status 409. Usecrewship feature-flag updateto change an existing definition.- The create body names the fields
default_enabledanddefault_percentage, but the server readsenabledandpercentage. A flag created by apply therefore starts withenabled: falseandpercentage: 0whatever the manifest says; onlykeyanddescriptionare taken from it. Set the default afterwards withcrewship feature-flag update <key> --enabled.workspace_overrideset totrueorfalseis applied (PUToverride). Leaving it out does not remove an existing override; usecrewship feature-flag inherit <key>.crewship exportdoes not emitFeatureFlagdocuments.percentageis stored but not evaluated by the server; see Effective value.maindiffers.
YAML schema
Field reference
Examples
Minimal — definition only
Defines an instance-global flag with no workspace-specific override. Every workspace inheritsdefault_enabled.
Realistic — definition + workspace opt-in
Same flag, but the workspace this manifest applies to wants the feature ON regardless of the instance default. Two PlanItems are emitted: POST the definition, then PUT the override. On a re-apply the POST fails with409 because the flag exists.
Force-disable for a specific workspace
This workspace explicitly opts out — useful for a customer who isn’t ready for the change. The override is applied;default_enabled: true
is not (see the limitations above), so turn the instance default on
with crewship feature-flag update new-issue-search --enabled.
Clear an existing override
Intended: drop theworkspace_override: line and re-apply, and the
plan removes the override. On main this emits nothing for the
override (and the definition POST fails with 409), so run
crewship feature-flag inherit experimental-llm-cache instead.
CLI reference
crewship flag works for every subcommand. The override
subcommands act on the selected workspace: pass the global
--workspace / -w flag, set CREWSHIP_WORKSPACE, or run
crewship workspace use. Full reference: crewship feature-flag.
REST endpoint mapping
The kind also contains update (
PATCH) and remove-override (DELETE …/override) steps, but they only run when apply knows the remote
state, which it does not fetch on main. The server’s response fields
are enabled, percentage and override_enabled; see the
API reference.
DB columns: feature_flags(key, description, enabled, percentage) +
feature_flag_overrides(flag_id, workspace_id, enabled). See
internal/database/migrate_consts_v01_init.go for the schema.
Validation rules
metadata.slugis required (used as the server-sidekey). It may be 1-256 characters and must not contain whitespace, control characters,/,?or#.spec.default_percentageMUST be in the closed range[0, 100]. Out-of-range values fail validation at parse time, before any REST call.spec.workspace_override, when present, must be a YAML boolean (true/false). Pointer typing means “field omitted” is a third valid state and not a validation failure.- Two
FeatureFlagdocuments with the same slug in one bundle are rejected. - No cross-kind FK references — FeatureFlag is a leaf kind in the dependency graph.
Apply behavior
Onmain, every apply mode plans the same items for a FeatureFlag
document:
- one
POST /api/v1/feature-flags(create) for the definition, and - one
PUT …/overridewhenworkspace_overrideis set.
unexpected status 409. --strict and --replace
do not change this: replace mode does not delete and recreate flag
definitions.
default_percentage is deliberately left out of the definition diff
the kind computes when it knows the remote state, so that runtime
tuning is not reset by a re-apply. Because apply does not fetch the
remote state on main, that diff does not run today.
Round-trip via export
crewship export does not include FeatureFlag documents on main.
The kind has an export helper, but no export command calls it. To
capture flags, use crewship feature-flag list --format yaml.
See also
- InstanceSetting — the other admin-only kind in the manifest; same dual-layer pattern but for configuration key/value pairs instead of feature toggles.
- SPEC-2 §9 (
.claude/context/specs/SPEC-2-manifest-complete.md) — the authoritative implementation contract.