@@ -118,15 +118,17 @@ Set up these hooks for this project:
118118| Hook | Command | Purpose |
119119| ------| ---------| ---------|
120120| ` afterFileEdit ` | ` npx oxfmt <file> ` | Auto-format files after AI edits |
121+ | ` afterFileEdit ` | ` .cursor/hooks/yarn-install.sh ` | Run ` yarn install ` when ` package.json ` changes to keep ` yarn.lock ` in sync |
121122| ` stop ` | `yarn build && yarn lint && yarn type-check && (yarn audit || true)` | Build, verify code, and check security when agent finishes. Note: ` yarn audit ` returns non-zero on vulnerabilities, so `|| true` makes it informational only |
122123
123124### Why Use Hooks
124125
125126- ** Consistent formatting** — Every file follows the same style
127+ - ** Keep lockfile in sync** — ` yarn install ` runs automatically when ` package.json ` changes, preventing stale ` yarn.lock ` files
126128- ** Catch build errors** — ` yarn build ` catches compilation errors that would break production
127129- ** Catch issues early** — Lint and type errors are caught before commit/CI
128130- ** Security awareness** — ` yarn audit ` flags known vulnerabilities in dependencies
129- - ** Less manual work** — No need to run ` yarn build ` , ` yarn lint ` , ` yarn type-check ` , ` yarn audit ` manually
131+ - ** Less manual work** — No need to run ` yarn install ` , ` yarn build` , ` yarn lint ` , ` yarn type-check ` , ` yarn audit ` manually
130132
131133### Example Hook Scripts
132134
@@ -158,6 +160,28 @@ echo "=== yarn audit ===" && (yarn audit || true) # || true makes audit informa
158160exit 0
159161```
160162
163+ ** Yarn install hook** (runs when ` package.json ` is edited):
164+ ``` bash
165+ #! /bin/bash
166+ # Run yarn install when package.json is changed
167+ # Hook receives JSON via stdin with file_path
168+
169+ input=$( cat)
170+ file_path=$( echo " $input " | grep -o ' "file_path"[[:space:]]*:[[:space:]]*"[^"]*"' | sed ' s/.*:.*"\([^"]*\)"/\1/' )
171+
172+ if [ -z " $file_path " ]; then
173+ exit 0
174+ fi
175+
176+ if [ " $file_path " = " package.json" ]; then
177+ cd " $( dirname " $0 " ) /../.." || exit 0
178+ echo " package.json changed - running yarn install to update yarn.lock..."
179+ yarn install
180+ fi
181+
182+ exit 0
183+ ```
184+
161185Consult your AI tool's documentation for how to configure hooks (e.g., ` hooks.json ` for Cursor/Claude Code).
162186
163187## Recommended MCP Servers
0 commit comments