Skip to main content
skill CX Codex

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.

Install into Claude Code · Skills CLI (Vercel) All methods and platforms ↓
npx skills add next-safe-action/skills --skill safe-action-tanstack-query -a claude-code
Open on GitHub

What 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 createUser to useMutation with mutationOptions() and handle its returned data.
  • Show how to distinguish serverError from validationErrors with ActionMutationError and the type guards.
  • Add an optimistic cache update in onMutate, then invalidate the related queries with queryClient.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-code

2Manually: put the files in place

~/.claude/skills/safe-action-tanstack-query/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/safe-action-tanstack-query/

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.

Similar skills

All skills for Frontend and UI →

From the same set9

Project sponsors

Companies that keep this analytics open
Gold sponsor

Impressions, clicks and code copies — open statistics. We keep the numbers public for the same reason NeBlask itself is public. Become a sponsor