safe-action-hooks — Claude Code skill for next-safe-action hooks
A skill that tells your agent which next-safe-action hook fits a form or optimistic UI, and how to wire it to the server action.
npx skills add next-safe-action/skills --skill safe-action-hooks -a claude-codeWhat safe-action-hooks does
The skill covers four hooks from next-safe-action/hooks: useAction, useOptimisticAction, useStateAction and useOptimisticStateAction. You pick by action kind first — .action() goes with the first two, .stateAction() with the other two. Each hook comes with a client component example: the "use client" directive, onSuccess and onError callbacks, a disabled button driven by isPending.
Queued writes get their own section. useOptimisticStateAction takes currentState and updateFn, then holds each dispatch until the previous one settles. The server sees the last confirmed state as prevResult. That matters for drag-to-reorder lists, Kanban boards, or any place where someone moves an item twice before the first save lands.
A few things will break it. currentState has to be a stable reference, because it is compared by identity. With <form action={formAction}> the server action must be a .stateAction(), and the input schema has to parse FormData — zod-form-data is the example given. The action also has to revalidate the state the page renders, otherwise the optimistic result drifts from what the page shows.
Install with npx skills add and the flag for your platform.
What it helps with
- pick the right hook for an action kind
- make a checkbox toggle feel instant
- queue repeated reorders of a list item
- build a form on
<form action={formAction}>that parsesFormData - surface a validation error next to its field
Example prompts for the agent
- Pick the right next-safe-action hook for a feedback form
- Build a drag-to-reorder list with useOptimisticStateAction
- Why does my useOptimisticStateAction miss the previous state?
How to install safe-action-hooks
1Skills CLI (Vercel)
npx skills add next-safe-action/skills --skill safe-action-hooks -a claude-code2Manually: put the files in place
~/.claude/skills/safe-action-hooks/SKILL.mdCopy the whole skill folder; for one project use .claude/skills/safe-action-hooks/
1Skills CLI (Vercel)
npx skills add next-safe-action/skills --skill safe-action-hooks -a codex2Manually: put the files in place
.agents/skills/safe-action-hooks/SKILL.mdFor all projects use ~/.agents/skills/
1Skills CLI (Vercel)
npx skills add next-safe-action/skills --skill safe-action-hooks -a cursor2Manually: put the files in place
.cursor/skills/safe-action-hooks/SKILL.mdCursor also reads .agents/skills/ and .claude/skills/
1GitHub CLI
gh skill install next-safe-action/skills safe-action-hooks2Manually: put the files in place
.github/skills/safe-action-hooks/SKILL.md1Skills CLI (Vercel)
npx skills add next-safe-action/skills --skill safe-action-hooks -a gemini-cli2Platform CLI
gemini skills install https://github.com/next-safe-action/skills --path skills/safe-action-hooksManually: put the files in place
.devin/skills/safe-action-hooks/SKILL.mdThe legacy .windsurf/skills/ path still works
Skills CLI (Vercel)
npx skills add next-safe-action/skills --skill safe-action-hooks -a opencodeClaude.ai
Zip the folder and upload it in Settings → Capabilities → Skills
Step by step, with commands for each platform: How to install skills in Claude Code: five ways
Questions about safe-action-hooks
How do I install safe-action-hooks in Claude?
Run npx skills add next-safe-action/skills --skill safe-action-hooks -a claude-code. The skill lands at ~/.claude/skills/safe-action-hooks/SKILL.md.
What does safe-action-hooks do?
It tells your agent which next-safe-action hook to use and how to connect it to a server action. It documents useAction, useOptimisticAction, useStateAction and useOptimisticStateAction.
How is useOptimisticAction different from useOptimisticStateAction?
The first suits changes that replace state outright. The second handles accumulating edits: dispatches are queued and each one folds over the confirmed state.