Getting it into your agent
One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.
npx agentmods add rules/nedcodes-ok/cursorrules-collection/tanstack-querygit clone --depth 1 https://github.com/nedcodes-ok/cursorrules-collectionWhat it costs to keep this loaded
Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.
| Model | Per session | Once invoked |
|---|---|---|
| Fable 5 | $0.00695 | $0.00695 |
| Opus 5 | $0.00347 | $0.00347 |
| Sonnet 5 | $0.00139 | $0.00139 |
| Haiku 4.5 | $0.00069 | $0.00069 |
Grade A, and why
tanstack-query scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 2d ago.
A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.
Nothing flagged
None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.
How it starts
The opening of the file, as written. The whole thing — 60 lines — stays where its author put it; the contents beside it link to each section on GitHub.
TanStack Query Cursor Rules
You are an expert in TanStack Query (React Query v5). Follow these rules:
Query Keys
- Use query key factories: export const userKeys = { all: ['users'], detail: (id: string) => ['users', id] }
- Never use inline string arrays — always reference the factory
- Include all variables that affect the response in the key
- Structure keys hierarchically for targeted invalidation
Query Functions
- Define queryFn as a separate named function, not inline
- Always type the return value of queryFn explicitly
- Throw errors in queryFn — don't return { error } objects. TanStack handles errors via the error state
- Use the queryKey passed to queryFn via the context parameter for DRY key usage
Query Options
- Set staleTime based on data volatility: user profile (5min), dashboard stats (30s), real-time feed (0)
- Use placeholderData instead of initialData when the placeholder is approximate
- Set gcTime (garbage collection) higher than staleTime — default 5min is usually fine
- Enable refetchOnWindowFocus only for data that changes frequently
Mutations
- Always use useMutation — never call fetch directly in event handlers
- Set onSuccess to invalidate related queries: queryClient.invalidateQueries({ queryKey: userKeys.all })
- Return the promise from mutateAsync when you need to await the result
- Use mutate (not mutateAsync) in fire-and-forget scenarios like button clicks
Optimistic Updates
- Use the onMutate → onError → onSettled pattern for optimistic updates
- In onMutate: cancel outgoing queries, snapshot previous data, set optimistic data
- In onError: roll back to the snapshot from onMutate context
- In onSettled: always invalidate to refetch the true server state
Error & Loading States
- Check isPending (not isLoading) in v5 — isLoading is isPending && isFetching
- Always handle the error state — don't just show loading forever
- Use isPlaceholderData to show a visual indicator for stale placeholder data
- Wrap query-heavy pages in an ErrorBoundary with QueryErrorResetBoundary
What this file has done since we first saw it
Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.
- 2d ago First seen · 60 lines · 695 tokens per session scan A ca65ccc88cd4
tanstack-query is a cursor rule published in the GitHub repository nedcodes-ok/cursorrules-collection (37 stars, last pushed 6mo ago), licensed MIT. It adds 695 tokens to every session, about $0.0035 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.