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