/directive:migrating-to-directivefrom directive
Migrates state management code from Redux, Zustand, XState, MobX, Recoil, or Jotai to Directive. Provides concept mapping, step-by-step migration patterns, and before/after code examples.
Ships in directive. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
This skill applies when migrating TO Directive. The user should have or plan to install @directive-run/core: npm install @directive-run/core.
writing-directive-modulesgetting-started-with-directive| Redux | Directive | Notes |
|---|---|---|
| Store | System | createSystem() wraps modules |
| Slice / Reducer | Module | createModule() with schema + init |
| State fields | Facts | Schema keys with t.*() type builders |
| Selectors | Derivations | Auto-tracked, no createSelector needed |
| Actions | Requirements | Typed with UPPER_SNAKE_CASE |
| Thunks / Sagas | Resolvers | Async handlers with retry, dedup |
| Middleware | Plugins | Lifecycle hooks |
useSelector | useSelector | From @directive-run/react |
dispatch(action) | system.dispatch(event) | Or constraint auto-triggers |
configureStore | createSystem | With plugins instead of middleware |
// BEFORE: Redux Toolkit
const counterSlice = createSlice({
name: "counter",
initialState: { value: 0, status: "idle" },
reducers: {
increment: (state) => { state.value += 1; },
decrement: (state) => { state.value -= 1; },
},
extraReducers: (builder) => {
builder.addCase(fetchCount.fulfilled, (state, action) => {
state.value = action.payload;
state.status = "loaded";
});
},
});
// AFTER: Directive
const counter = createModule("counter", {
schema: {
value: t.number(),
status: t.string<"idle" | "loading" | "loaded">(),
},
init: (facts) => {
facts.value = 0;
facts.status = "idle";
},
// Reducers become direct mutations:
// system.facts.value += 1 (no action dispatch needed)
//
// Async thunks become constraint + resolver:
constraints: {
needsData: {
when: (facts) => facts.status === "idle",
require: { type: "FETCH_COUNT" },
},
},
resolvers: {
fetchCount: {
requirement: "FETCH_COUNT",
retry: { attempts: 3, backoff: "exponential" },
resolve: async (req, context) => {
context.facts.status = "loading";
const response = await fetch("/api/count");
const data = await response.json();
context.facts.value = data.count;
context.facts.status = "loaded";
},
},
},
});
| Zustand | Directive | Notes |
|---|---|---|
create() | createModule() | Module is more structured |
| State object | Schema + init | Explicit types with t.*() |
| Actions (set) | Direct mutation | system.facts.x = y |
| Selectors | Derivations | Auto-tracked |
| Middleware | Plugins | Built-in logging, devtools |
useStore | useSelector | From React adapter |
// BEFORE: Zustand
const useStore = create((set) => ({
bears: 0,
increasePopulation: () => set((state) => ({ bears: state.bears + 1 })),
removeAllBears: () => set({ bears: 0 }),
}));
// AFTER: Directive
const bearStore = createModule("bear-store", {
schema: { bears: t.number() },
init: (facts) => { facts.bears = 0; },
});
const system = createSystem({ module: bearStore });
// Actions become direct mutations:
system.facts.bears += 1; // increasePopulation
system.facts.bears = 0; // removeAllBears
| XState | Directive | Notes |
|---|---|---|
| Machine | Module | States → facts, transitions → constraints |
| States | Fact values | status: t.string<"idle" | "loading">() |
| Context | Facts | All state in schema |
| Events | Events / Requirements | dispatch() or auto-triggered |
| Guards | Constraint when() | Predicate functions |
| Actions | Resolver resolve() | Async handlers |
| Services | Resolvers | With retry policies |
useMachine | useSystem | React adapter |
// BEFORE: XState
const toggleMachine = createMachine({
id: "toggle",
initial: "inactive",
states: {
inactive: { on: { TOGGLE: "active" } },
active: { on: { TOGGLE: "inactive" } },
},
});
// AFTER: Directive
const toggle = createModule("toggle", {
schema: {
status: t.string<"active" | "inactive">(),
},
init: (facts) => { facts.status = "inactive"; },
events: {
TOGGLE: (facts) => {
facts.status = facts.status === "active" ? "inactive" : "active";
},
},
});
const system = createSystem({ module: toggle });
// Trigger: system.dispatch({ type: "TOGGLE" });
| MobX | Directive | Notes |
|---|---|---|
observable | Facts (schema) | Proxy-based, similar feel |
computed | Derivations | Auto-tracked in both |
action | Events / direct mutation | Both work |
reaction | Constraints | When/require pattern |
autorun | Effects | Fire-and-forget |
| Recoil/Jotai | Directive | Notes |
|---|---|---|
| Atoms | Facts | Individual state units |
| Selectors/Derived atoms | Derivations | Auto-tracked |
useRecoilValue | useSelector | React adapter |
| Async selectors | Constraint + Resolver | Explicit async pattern |
1. Identify state shape
→ Map to schema with t.*() type builders
→ Every state field → fact
2. Identify computed values
→ Map to derive {} block
→ Auto-tracked, no dependency arrays needed
3. Identify synchronous actions
→ Direct mutations: system.facts.x = y
→ Or events: events: { ACTION_NAME: (facts, payload) => { ... } }
4. Identify async operations
→ Constraint: when should this async work trigger?
→ Resolver: how to fulfill the requirement?
→ Add retry policies for network calls
5. Identify side effects
→ Map to effects {} block
→ Logging, analytics, DOM sync
6. Identify middleware
→ Map to plugins [] array
→ Use built-in: loggingPlugin, devtoolsPlugin, persistencePlugin
7. Update React components
→ Replace useSelector/useStore with Directive's useSelector
→ Replace dispatch with direct mutation or system.dispatch
Redux: Action → Reducer → New State (immutable)
Directive: Mutation → Auto-constraint-check → Auto-resolve (mutable proxy)
Zustand: set() callback → New state
Directive: Direct mutation → Reactive updates
XState: Event → Guard → Transition → Action
Directive: Fact change → Constraint when() → Requirement → Resolver
Supporting knowledge files loaded with this skill:
core-patterns.md – Directive patterns referenceschema-types.md – Type builder reference for migrationanti-patterns.md – Common mistakes when migratingWhat SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
state-migration, directive, state-management, code-conversion
Other plugins' skills for the same job
npx claudepluginhub directive-run/directive --plugin directive12 skills in this plugin
/building-ai-agentsConfigure AI provider runners (Anthropic, OpenAI, Ollama), stream tokens and structured output, and wire cross-agent communication. Use when setting up LLM provider connections, implementing token streaming, choosing between providers, or building agents that communicate results to each other./building-ai-orchestratorsCreate AI orchestration systems using createAgentOrchestrator (single agent) and createMultiAgentOrchestrator (multi-agent). Define factsSchema with t.*() builders, init state, constraints for trigger conditions, and resolvers for LLM execution. Use when building LLM-powered workflows, agent pipelines, task runners, or multi-agent coordination systems./building-directive-systemsCompose Directive modules into systems: single-module and multi-module createSystem() calls, namespaced fact/derive/event access, cross-module dependencies, initialFacts and hydration, plugins (logging, devtools, persistence, circuit breaker), React adapter hooks (useSelector, useEvent, useSystem, DirectiveProvider), and system lifecycle. Use when creating a system, connecting modules together, adding plugins, or integrating Directive with React./getting-started-with-directiveUnderstand Directive fundamentals: what modules, facts, derivations, constraints, resolvers, and systems are, and how they fit together. Use when someone is new to Directive, asks 'what is Directive', wants to understand the mental model, or needs help choosing between Directive concepts./hardening-ai-systemsAdd guardrails (input/output validation), memory strategies, token budgets, PII detection, prompt injection prevention, and circuit breakers to AI orchestrators. Use when enforcing content policies, managing costs, preventing security vulnerabilities, adding resilience, or implementing agent memory across turns./reviewing-directive-codeReview Directive code for anti-patterns, naming violations, missing error boundaries, constraint/resolver misuse, and performance issues. Use when asked to review, audit, or improve existing Directive modules, systems, or orchestrators.