safe-action-tanstack-query — Claude Code skill: setup
Connects next-safe-action mutations to TanStack Query with typed error handling, cache updates, and invalidation. Use it when React Query already handles your client data.
npx skills add next-safe-action/skills --skill safe-action-tanstack-query -a claude-codeWhat safe-action-tanstack-query does
This skill explains how mutationOptions() fits into useMutation. It maps the safe action result into TanStack Query’s mutation model: returned server or validation failures become ActionMutationError, while successful results arrive as mutation data. The guide also covers isActionMutationError, hasServerError, and hasValidationErrors.
It describes cache-based optimistic changes with onMutate, query invalidation through queryClient.invalidateQueries(), retry backoff, DevTools, and paused mutation persistence. The integration requires @next-safe-action/adapter-tanstack-query and @tanstack/react-query.
There is a firm boundary: wrapped actions must be stateless .action() functions that return errors instead of throwing them. stateAction, throwValidationErrors: true, and throwServerError: true do not fit this adapter. It handles mutations, not data fetching queries.
What it helps with
- connect a safe action to
useMutation - map server and validation failures to typed errors
- invalidate the client query cache after a write
- apply an optimistic cache update with
onMutate - configure retries and paused mutation persistence
Example prompts for the agent
- Connect
createUsertouseMutationwithmutationOptions()and handle its returned data. - Show how to distinguish
serverErrorfromvalidationErrorswithActionMutationErrorand the type guards. - Add an optimistic cache update in
onMutate, then invalidate the related queries withqueryClient.invalidateQueries().
How to install safe-action-tanstack-query
1Skills CLI (Vercel)
npx skills add next-safe-action/skills --skill safe-action-tanstack-query -a claude-code2Manually: put the files in place
~/.claude/skills/safe-action-tanstack-query/SKILL.mdCopy the whole skill folder; for one project use .claude/skills/safe-action-tanstack-query/
1Skills CLI (Vercel)
npx skills add next-safe-action/skills --skill safe-action-tanstack-query -a codex2Manually: put the files in place
.agents/skills/safe-action-tanstack-query/SKILL.mdFor all projects use ~/.agents/skills/
1Skills CLI (Vercel)
npx skills add next-safe-action/skills --skill safe-action-tanstack-query -a cursor2Manually: put the files in place
.cursor/skills/safe-action-tanstack-query/SKILL.mdCursor also reads .agents/skills/ and .claude/skills/
1GitHub CLI
gh skill install next-safe-action/skills safe-action-tanstack-query2Manually: put the files in place
.github/skills/safe-action-tanstack-query/SKILL.md1Skills CLI (Vercel)
npx skills add next-safe-action/skills --skill safe-action-tanstack-query -a gemini-cli2Platform CLI
gemini skills install https://github.com/next-safe-action/skills --path skills/safe-action-tanstack-queryManually: put the files in place
.devin/skills/safe-action-tanstack-query/SKILL.mdThe legacy .windsurf/skills/ path still works
Skills CLI (Vercel)
npx skills add next-safe-action/skills --skill safe-action-tanstack-query -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-tanstack-query
How do I install safe-action-tanstack-query in Claude Code?
Run npx skills add next-safe-action/skills --skill safe-action-tanstack-query -a claude-code, then check ~/.claude/skills/safe-action-tanstack-query/SKILL.md.
What does safe-action-tanstack-query do?
It documents an adapter for using next-safe-action with TanStack Query mutations. The skill covers result errors, typed guards, cache updates, and query invalidation.
Which actions can the adapter wrap?
Use stateless .action() functions that return errors in their result. Stateful actions and actions configured with throwValidationErrors: true or throwServerError: true are incompatible.