setup-connect-query
Setup Connect Query
What This Sets Up
PostToolUse hook on Edit/Write catching data-fetching anti-patterns across the ConnectRPC + TanStack Query + Protobuf stack:
- Ban raw
useQuery/useMutationfrom@tanstack/react-querywhen file uses ConnectRPC — must use Connect Query (exception: files importing from@connectrpc/connectdirectly foruseTransport/callUnaryMethodpattern) - Ban
invalidateQueries()with no args — must specify query key - Warn on
axiosimports — prefer ConnectRPC transport - Warn on
fetch()calls — prefer ConnectRPC transport - Protobuf v2 only: Ban
new Message()construction — usecreate(Schema) - Protobuf v2 only: Ban
PlainMessage/PartialMessage— useMessageShape/MessageInitShape - Protobuf v2 only: Ban manual object literals with
$typeName— usecreate(Schema)for type-safe construction
Escape hatch: // allow-direct-query: [reason] for legitimate REST endpoints.
Steps
1. Detect protobuf version
Check package.json for @bufbuild/protobuf version:
^1.x→ install v1 variant (skips protobuf v2 checks)^2.x→ install v2 variant (includes protobuf v2 checks)
2. Create hook script
Copy scripts/connect-query-check.sh and scripts/_hook-lib.sh into .claude/hooks/. Make executable.
3. Configure hook in .claude/settings.json
Add to hooks config: PostToolUse (matcher: Edit|Write): .claude/hooks/connect-query-check.sh
4. Verify
- Hook blocks
useQueryfrom@tanstack/react-queryin files with ConnectRPC imports - Hook allows
useQueryfrom@tanstack/react-queryin files without ConnectRPC imports - Hook blocks
invalidateQueries()with no args - Hook warns on
axiosimports - Hook respects
// allow-direct-query:escape hatch - (v2 only) Hook blocks
new MessageRequest()protobuf construction - (v2 only) Hook blocks
PlainMessage<T>usage - (v2 only) Hook blocks manual object literals with
$typeName - Hook allows raw
useQuery/useMutationwhen file imports from@connectrpc/connect
5. Commit
Stage and commit: Add Connect Query and protobuf enforcement hook
More from malinskibeniamin/skills
setup-react-rules
Enforce React/TS/security rules via PostToolUse hooks — bans raw HTML, TS escape hatches, XSS vectors, barrel imports, missing passive listeners. Use when enforcing React patterns or component library standards.
9setup-react-compiler
Install React Compiler with rsbuild and enforce compiler-friendly patterns via PostToolUse hooks. Flags manual memoization, derived state, useRef cache. Use when setting up React Compiler or post-compiler patterns.
9setup-biome
Install Biome linter with Ultracite preset, create biome.jsonc config, and configure Claude Code Stop hook for auto-fix before finishing. Use when setting up linting, formatting, Biome, Ultracite, or code quality enforcement.
9setup-quality-gate
Add quality:gate package.json script for fast local/CI quality checks (biome + tsgo + related tests), GitHub Actions workflow, and Stop hook for type checking. Use when setting up quality gates, CI pipelines, or pre-push validation.
9work-automation-kit
Install planning and project management skills — PRD creation, implementation planning, issue breakdown, bug triage, code review. Use when setting up project planning workflows or creating PRDs.
8setup-zustand
Enforce zustand best practices via PostToolUse hooks — double-parens create, useShallow selectors, persist middleware. Use when setting up zustand enforcement or preventing re-render issues.
8