Overview
Coding assistants know little about shipd. Give them this page and they’ll write correct shipd code. It’s also available as plain Markdown athttps://docs.useshipd.com/ai.md.
The navbar separates Docs, Guides, SDKs, Integrations, API docs, Tutorials, and Changelog. Shared examples have synchronized TypeScript and Go tabs: choose an SDK once to switch the matching examples on that page. Framework-specific examples document the SDK supported by that framework.
For direct application control, connect an agent through MCP under Guides → Operations. The endpoint is
https://mcp.useshipd.com/mcp; mutations require idempotency keys and updates require observed versions. Pending changes must be reviewed in the dashboard. MCP tools and request guarantees live under API docs → Operations APIs.
Every page also has a menu to copy it as Markdown or open it in Claude, ChatGPT, or Cursor.
To give your assistant shipd context permanently, add this to your project’s CLAUDE.md, AGENTS.md, or editor rules:
shipd context for coding assistants
shipd is a feature flag service. Flags are defined in TypeScript, Go, or version-1 JSON, synced with a shared CLI, and evaluated locally in memory by an SDK.Packages
Go workflow
The CLI readsshipd.config.go directly and generates Go accessors by default, unless typesLanguage overrides the output language. Define an exported var Config = config.ShipdConfig{...} in a self-contained Go file inside your module. The CLI evaluates that file with Go; imported packages and helper declarations in the same file are supported. It does not load sibling Go files, so keep application dependencies in imported packages. Do not define main in the definition file. shipd pull rewrites the Go definitions and regenerates accessors; review the resulting diff because comments and helper code are replaced. Use generated accessors like flags.NewCheckout(client, ctx) and flags.Defaults().
Files
Define flags
shipd push. It creates missing flags, updates changed definitions, and regenerates TypeScript types or Go accessors. It never deletes flags; --prune archives flags missing from the file.
Evaluate on a server
Streaming requires a WebSocket implementation. Node.js 22+ provides one globally. On Node.js 20, supply a compatible constructor through theWebSocket option; otherwise, the client uses polling.
Evaluate in React
src/lib/shipd-react.ts
Evaluation model
- The SDK downloads a snapshot of one environment from
https://edge.useshipd.com, keeps it in memory, and refreshes it every 30 seconds or on a WebSocket notification. isEnabled,getVariant,getNumber, andgetJsonmake no network requests and never throw.- Value order: no snapshot or unknown key →
defaults[key]; flag disabled → fallthrough, skipping rules; first matching rule → its serve; otherwise → fallthrough. - Evaluation context is
{ userId?, attributes?, segmentIds? }. Per-call context overridescreateClient({ context }). In browsers (shipdit/client),identify()traits sit between the two; serveridentify()only records an event and never changes context. - Percentage rollouts hash the flag key and
userId, or a chosen attribute. A missing bucket attribute makes the condition fall through. - Targeting rules, rollouts, and enabled state are set in the dashboard, not in
shipd.config.tsorshipd.config.go.
Credentials
Rules for assistants
- Import
defineFlagsfromshipdit/config, never fromshipdit. - Import
createClientfromshipditon servers and fromshipdit/clientin browsers. - Type the client with the generated
FlagDefinitions:createClient<FlagDefinitions>(…). Never write flag types by hand. - Pass a
defaultsentry for every flag. Use the safe value (usually “off”). - Create one client per process and reuse it. Never create a client per request.
await shipd.ready()once at startup, before serving traffic that reads flags.- On servers, pass
{ userId, attributes }per call. Serveridentify()only records an event; it never sets evaluation context. - Call
createShipdReactonce, in a"use client"module, and use hooks from that same call. - Add or change flags by editing
shipd.config.ts(Go:shipd.config.go) and runningshipd push. Don’t create flags in the dashboard for code-managed projects. - Don’t pass
endpointorstreamEndpoint; they were removed. Usestream: truefor realtime updates. For a custom stream gateway, preserve its URL withoverrides.streamEndpointandstream: true. Reserveoverrides.unsafeEndpointfor development and tests; never use it in production.
Rules for Go
- Import the SDK as
shipd "github.com/alasti-company/useshipd.com/sdks/go"and definitions from itsconfigsubpackage. Onego get github.com/alasti-company/useshipd.com/sdks/goinstalls both. - Define flags in
shipd.config.go, nevershipd.config.ts. Runshipd types gen(Node.js 22.12+ and@shipdit/cli) to write accessors. - Call generated accessors such as
flags.NewCheckout(client, ctx)instead ofclient.IsEnabled("new-checkout", ctx), and passDefaults: flags.Defaults()toshipd.New. - Create one
*shipd.Clientper process withshipd.Newand share it across goroutines. - Call
Readyonce at startup with a bounded context. It returns the fetch error as soon as the first fetch fails; log it and serve defaults. - Pass a
shipd.EvaluationContexton every evaluation.Identifyonly queues telemetry. - On shutdown, call
Shutdown(ctx)with a bounded context. It attempts to flush pending events and closes even on delivery failure; check or log its returned error.Closedoes not flush. Never setOverrides.UnsafeEndpointin application code. - JSON flags return
anyand numbers arefloat64; convert at the call site. - In tests, use an
HTTPClientthat fails,DisablePolling, andDisableEvents. To test targeting rules, pass snapshot JSON asBootstrap.
Common mistakes
- Call the edge API directly to evaluate flags.
- Put a server SDK key, management API key, or service account token in browser code.
- Use a management API key or service account token as an SDK key, or an SDK key with the CLI.
- Edit
src/generated/flags.tsby hand. - Assume
shipd pushdeletes flags missing fromshipd.config.ts. It leaves them;--prunearchives them. - Run
shipd push --prunewithout reading the plan. It archives every flag not in the file. - Put targeting rules or rollout percentages in
shipd.config.ts. They’re dashboard state. - Forget that
defaultinshipd.config.tsis the fallthrough of the environment you push to.shipd pushresets a fallthrough changed in the dashboard back to it. Updatedefault(or runshipd pull) first. - Assume disabling a flag turns it off. A disabled flag serves its fallthrough. To turn a feature off, set the fallthrough to
false. - Use
--forceto get past a conflict. Runshipd pull, re-apply the edit, and push again. - Treat
shipd pushexit code5as success. The change is waiting for approval. - Rely on percentage rollouts without supplying their bucket attribute (
userIdby default). - Import
shipdit/client/reactin server code.
- Supply
defaultsfor every flag. - Evaluate locally with the SDK.
- Commit
src/generated/flags.tsalong withshipd.config.ts(Go:flags_gen.goalong withshipd.config.go). - Run
shipd diff --exit-codein pull request CI, andshipd push --cion merge with a service account token inSHIPD_API_KEY. - Set
SHIPD_API_URL=https://api.useshipd.comin CI. Without a saved login, the CLI defaults tohttp://localhost:8000. - Await
shipd.close()on shutdown. In Go, drain active handlers first, then callShutdown(ctx)with a bounded context and check its error.
CLI cheat sheet
Where to look next
- SDK reference · CLI reference ·
shipd.config.tsreference - Core concepts · Glossary
- Examples: complete apps to adapt