plugin-state
FreeNo executable scriptsNot checkedPick and write client state in DSH plugins with the plugin-ui bindings — TanStack Query for Host/async data, TanStack Form + zod for multi-field forms, xstate…
by astahmer★ 21 GitHub starsAbout this skill
Plugin state
Rule of thumb (current audit decisions: plugins/@dshfiles/plugin-ui/docs/state-ownership.md):
| State | Use | Import |
|---|---|---|
| Host / async data | useQuery / useMutation |
@dshfiles/plugin-ui/query |
| Multi-field form | useAppForm + zod schema |
@dshfiles/plugin-ui/form |
| Flow with ≥3 tangled states | xstate v5 machine | @dshfiles/plugin-ui/machine |
| localStorage | createStoredValue |
@dshfiles/plugin-ui/hooks/stored-value |
| Debounced input | useDebouncedValue |
@dshfiles/plugin-ui/hooks/debounced-value |
Do not add @tanstack/*, xstate or zod UI deps to a plugin directly — plugin-ui pins them.
Flow ownership
A lifecycle split across flags, refs and timers is the bug, even before it fires: every reachable bad combination eventually is. The rules, and the reasoning, live in state ownership:
- Pick the smallest owner that makes the bad state unrepresentable: a union for two or three states with no
timers, a machine for three or more tangled states or any timer/cancellation/child work, Query for Host data,
Ref.modify/Effect.ensuring/ a puretransitionon the Host side. - A machine owns all of its flow. When a component wraps one, its parallel flags, refs and effects move in; a second source of truth beside a machine is the bug.
- Per-key state is per key: anything fed by events from several Sessions, accounts or paths keys by that id.
- A Host write that creates something (mint a code, start a job, open a session) never runs from an effect keyed on props or a callback built from them: panel adapters and slot renderers pass a new props object on every render. Run it from a user event or a machine state's entry, once per open. Phone pairing minted a code per sidebar render until the Host refused more.
- Reproduce first, and leave a flow alone with one line saying why when it is already contained.
Query
Wrap each slot root once inside dshx decorate(...) (one client per plugin bundle):
ctx.slots.register(
{ name: 'main', key: PANEL_ID },
decorate(props => (
<PluginQueryProvider>
<SecretCatalogPanel t={props.t} />
</PluginQueryProvider>
)),
)
Keys start with the plugin id, signal is forwarded, mutations invalidate by key, polling is refetchInterval
(never setInterval):
// ai-accounts/src/accounts-queries.ts
export const aiAccountsKeys = { usage: ['ai-accounts', 'usage'] as const }
usage: (accounts, refetchInterval: number) =>
queryOptions({ queryKey: aiAccountsKeys.usage, queryFn: async ({ signal }) => normalizeUsage(await accounts.usage(undefined, { signal })), refetchInterval })
// secret-catalog/src/secret-catalog-panel.tsx
const createMutation = useMutation({
mutationFn: (input: SecretCreateForm) => api.create({ ...input, cwd }),
onSuccess: () => queryClient.invalidateQueries({ queryKey: ['secret-catalog', 'list'] }),
})
errorMessage(error, fallback) renders a failure without leaking non-Error values. A Host { ok: false } result
should throw inside mutationFn so each mutation owns its error.
Form
// secret-catalog/src/secret-mutation-dialog.tsx
const form = useAppForm({
defaultValues: secretCreateFormDefaults({ scope, environment }),
validationLogic: revalidateLogic(),
validators: { onDynamic: secretCreateFormSchema }, // zod 4 = Standard Schema
onSubmit: ({ value }) => props.onCreate(toSecretCreateInput(value)),
})
<form.AppField name="alias">{field => <field.TextField label={t('fieldAlias')} monospace required />}</form.AppField>
Fields: TextField, TextAreaField, SelectField, CheckboxField, SwitchField, plus form.SubmitButton. Skip
the form store when the draft re-syncs from another source (it becomes a second source of truth).
Machine
Only for flows like select → prepare → confirm → receipt. Machines own flow state; data stays in Query.
Split ownership between React, the machine, its actors and the URL with the shared actor-state-ownership skill. Host
calls go through fromPromise actors with the signal forwarded, so leaving a state aborts the call. Pilot:
jujutsu/src/workspace-restore-machine.ts.
actors: {
confirm: fromPromise<Receipt, { client: RestoreClient; previewId: string }>(async ({ input, signal }) =>
unwrap(await input.client.confirmWorkspaceRestore({ previewId: input.previewId }, signal))),
},
const [snapshot, send, actor] = useMachine(workspaceRestoreMachine, { input: { client, workspacePath, targetCommitId } })
useEffect(() => {
const sub = actor.on('restored', () => onRestored.current()
Install plugin-state in Claude Code & Claude Desktop
Sign up to install this skill
Create a free account to reveal the install command and save the skill to your library.
- Reveal the one-line install command
- Save skills to your synced library
- Get notified when skills update
Allowed tools
Tools this skill is permitted to call.
No restriction — this skill can use any tool.
FAQ
What does the plugin-state skill do?
Pick and write client state in DSH plugins with the plugin-ui bindings — TanStack Query for Host/async data, TanStack Form + zod for multi-field forms, xstate v5 for tangled flows, createStoredValue for localStorage, useDebouncedValue for debounce. Use when a plugin component grows useState/useEffect/setInterval for server data, a form, a multi-step flow, or persisted preferences.
How do I install the plugin-state skill?
Copy the skill folder into ~/.claude/skills (the Claude Code tab above does this in one command), or install it as a plugin.
Does the plugin-state skill run scripts?
No, this skill is instructions only (SKILL.md) with no executable scripts.
Related skills
skill-creator
Create new skills, modify and improve existing skills, and measure skill performance. Use when users want to create a skill from scratch, edit, or optimize an…
by Anthropicdiscernment-nudge
After you give a substantive answer or draft that the user may act on — advice or recommendations, drafted artifacts such as goals, plans, pitches, proposals…
by Anthropicdata-consolidate
Joins the plant's scheduled exports and connector data into one working dataset — ERP items (NetSuite or Infor M3), sales orders, production work orders…
by Anthropicinspection-to-capa
Runs the quality chain end to end: writes the nonconformance against the requirement it violates, searches history at the moment of writing to say whether…
by Anthropic