/scaffolding:state-managementfrom scaffolding
Provides client state management standards for local-vs-global decisions, store structure, selectors, and re-render performance. Triggers when creating stores or managing global state. Uses Zustand for examples.
Ships in scaffolding. 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.
None: SKILL.md is the whole skill.
Client state management standards and best practices. The universal guidance (local-vs-global decisions, store structure, selectors, performance) applies to any store library; the concrete code examples use Zustand.
| Category | Solution | Use When |
|---|---|---|
| Local UI | useState | Single component, simple state |
| Shared UI | Zustand store | Multiple components need same data |
| Server data | React Query / SWR | API data with caching needs |
| Form state | useState / form library | Form inputs, validation |
| URL state | useSearchParams | Filter/sort params, shareable URLs |
| Element | Requirement |
|---|---|
| Interface | Define typed state + actions interface |
| State | Group related state together |
| Actions | Define all mutations as functions |
| Naming | use[Domain]Store convention |
| Principle | Description |
|---|---|
| Single responsibility | One store per domain (projects, UI, settings) |
| Flat structure | Avoid deeply nested state |
| Immutable updates | Always return new objects |
| Colocated actions | Keep actions inside store definition |
| Rule | Reason |
|---|---|
| Select minimal data | Reduces re-renders |
Use shallow for objects | Prevents unnecessary updates |
| Memoize derived data | Use useMemo for computed values |
| Avoid selecting entire store | Causes re-render on any change |
| Pattern | Use Case |
|---|---|
| Single value | (state) => state.count |
| Multiple values | (state) => ({ a: state.a, b: state.b }), shallow |
| Derived value | useMemo outside store |
| Middleware | Purpose | When to Use |
|---|---|---|
persist | LocalStorage persistence | User preferences, settings |
devtools | Redux DevTools integration | Development debugging |
immer | Immutable updates | Complex nested state |
subscribeWithSelector | Granular subscriptions | Performance optimization |
src/stores/
├── index.ts # Re-exports all stores
├── projectStore.ts # Domain-specific store
├── uiStore.ts # UI state (modals, panels)
└── settingsStore.ts # User preferences
| Store Type | Contains |
|---|---|
| Domain store | Business entities, selections |
| UI store | Modal states, panel visibility, loading |
| Settings store | User preferences, persisted config |
shallow equality for object selectionssubscribeWithSelector for side effectsshallow| Anti-Pattern | Problem | Solution |
|---|---|---|
| Giant store | Hard to maintain, performance issues | Split by domain |
| Computed in store | Stale data, extra complexity | Use useMemo |
| Prop drilling | Bypasses store benefits | Use store directly |
| Store in useState | Loses reactivity | Use store hook |
| No TypeScript | Runtime errors | Define interfaces |
| Scenario | Recommended Solution |
|---|---|
| Form input state | useState |
| Modal open/close | useState or UI store |
| Selected item (shared) | Domain store |
| User preferences | Persisted store |
| API response data | Store + service function |
| Computed/derived data | useMemo from store values |
| Global loading state | UI store |
Illustrative — these are one team's concrete Zustand conventions shown as an example. Substitute your store library's equivalents (Redux Toolkit, Jotai, Pinia, signals, etc.). The decision matrix and selector/performance guidance above are the reusable, library-agnostic part.
<your-stores-module>/)| Store | Persist | Purpose |
|---|---|---|
workspaceStore.ts | Yes (scaffolding-workspaces) | Projects/workspaces, active selection |
taskStore.ts | No | Task CRUD, SSE updates, agent statuses |
authStore.ts | Yes (auth-storage) | GitHub OAuth state, user profile |
Every store defines type XxxState and type XxxActions, then exports the combined type:
type WorkspaceState = {
workspaces: Workspace[];
activeWorkspace: Workspace | null;
};
type WorkspaceActions = {
addWorkspace: (pathOrWorkspace: string | Workspace) => void;
removeWorkspace: (path: string) => Promise<void>;
setActiveWorkspace: (path: string) => void;
loadFromApi: () => Promise<void>;
};
export type WorkspaceStore = WorkspaceState & WorkspaceActions;
partializePersisted stores use partialize to exclude actions and transient state from storage:
export const useWorkspaceStore = create<WorkspaceStore>()(
persist(
(set, get) => ({ /* state + actions */ }),
{
name: 'scaffolding-workspaces',
partialize: (state) => ({
workspaces: state.workspaces,
activeWorkspace: state.activeWorkspace,
}),
}
)
);
useShallow (<your-hooks-module>/)Stores are consumed through hook wrappers that use useShallow to prevent re-renders:
import { useWorkspaceStore } from '../stores/workspaceStore';
import { useShallow } from 'zustand/shallow';
export function useWorkspace() {
return useWorkspaceStore(
useShallow((state) => ({
workspaces: state.workspaces,
activeWorkspace: state.activeWorkspace,
addWorkspace: state.addWorkspace,
// ... selected fields only
}))
);
}
loadFromApi)Stores hydrate from localStorage first, then enrich from API:
persist middleware loads cached state from localStorage on mountloadFromApi() fetches from backend, merges fields (id, github_url, role) into existing entriesNon-persisted stores receive real-time updates from Server-Sent Events:
addTask(task) - deduplicates before prepending to listupdateTask(task) - replaces full task object in list and currentTaskupdateTaskPartial(id, updates) - merges partial fields from SSE completion eventsupdateAgentStatus(taskId, status) - tracks per-agent progress within a taskStores use extractErrorMessage(err, fallbackMsg) utility and store errors in state:
catch (err) {
const message = extractErrorMessage(err, 'Failed to fetch tasks');
set({ error: message, isLoading: false });
}
For expected errors (e.g., 409 conflict on cancel), check AxiosError status before setting error state.
What SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub komluk/scaffolding --plugin scaffolding39 skills in this plugin
/agent-commsSendMessage recipient validation and worktreePath safety (CWE-59). TRIGGER when: validating a SendMessage `to:` recipient against the agent whitelist, or a worktreePath from another agent before acting on it. SKIP: routing topology (agent Comms Protocol); git ops (use git-operations); worktree recovery (use worktree-management)./agent-memoryRepo-local file memory under .scaffolding/ (shared/agent/conversation tiers). TRIGGER when: reading or writing .scaffolding/ memory files, or choosing which file tier an insight belongs in. SKIP: vector memory / MCP search and store (use semantic-memory-mcp); distilling conversations (use distill)./api-designRESTful API design standards: resource naming, HTTP methods, status codes, pagination, versioning. TRIGGER when: designing new API endpoints, defining error response shapes, or adding pagination/filtering. SKIP: implementing FastAPI route code (use python-patterns); error-handling internals (use error-handling)./context-engineeringOptimize Claude Code context-window usage for accuracy and cost. TRIGGER when: hitting context limits, structuring prompts for an agent, or trimming what gets injected into a task. SKIP: persisting knowledge across sessions (use agent-memory); semantic recall tuning (use semantic-memory-mcp)./database-optimizationSchema design, index strategy, migration safety, and query analysis. TRIGGER when: designing tables or indexes, writing a migration, or diagnosing a slow query. SKIP: writing ORM model code (use python-patterns); generic backend patterns (use python-patterns)./distillKnowledge distillation: candidate extraction, confidence scoring, tier routing. Invoked by /learn and the memory-ingest Stop hook, not loaded proactively by agents. TRIGGER when: /learn or the Stop hook asks to distill, or scoring a candidate. SKIP: file memory writes (use agent-memory); vector store (use semantic-memory-mcp).Other plugins' skills for the same job