You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
docs: update Claude Code hooks section with enrichment pattern and Windows notes
- Add PreToolUse enrichment hook example (codegraph deps → additionalContext)
- Document Windows backslash normalization caveat
- List all hook files with descriptions
- Update parallel session hooks to mention branch name validation
Copy file name to clipboardExpand all lines: docs/recommended-practices.md
+26-4Lines changed: 26 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -188,12 +188,24 @@ Use `--kind function` to cut noise. Use `--file <pattern>` to scope.
188
188
189
189
### Claude Code hooks
190
190
191
-
You can configure [Claude Code hooks](https://docs.anthropic.com/en/docs/claude-code/hooks) to automatically rebuild the graph after file edits:
191
+
You can configure [Claude Code hooks](https://docs.anthropic.com/en/docs/claude-code/hooks) to give Claude automatic dependency context and keep the graph fresh as it edits files:
@@ -210,16 +222,26 @@ You can configure [Claude Code hooks](https://docs.anthropic.com/en/docs/claude-
210
222
}
211
223
```
212
224
213
-
This ensures the graph stays fresh as the AI agent modifies files. Incremental builds are automatic — only changed files are re-parsed.
225
+
**Enrichment hook** (PreToolUse on Read/Grep): when Claude reads a file, the hook runs `codegraph deps` and injects import/export context into the conversation via `additionalContext`. This means Claude sees "this file imports X, Y and is imported by Z" without having to be told.
226
+
227
+
**Graph update hook** (PostToolUse on Edit/Write): keeps the graph incrementally updated after each file edit. Only changed files are re-parsed.
228
+
229
+
> **Windows note:** If your hooks use bash scripts, normalize backslashes inside `node -e` rather than bash (`${VAR//\\//}` fails on Git Bash). See this repo's `.claude/hooks/enrich-context.sh` for the pattern.
230
+
231
+
See this repo's `.claude/hooks/` directory for working implementations:
-`track-edits.sh` — logs edited files for commit validation
214
236
215
237
#### Parallel session safety hooks
216
238
217
239
When multiple AI agents work on the same repo concurrently, add hooks to prevent cross-session interference:
218
240
219
241
-**Edit tracker** (PostToolUse on Edit|Write): log every file path touched to `.claude/session-edits.log`
220
-
-**Git guard** (PreToolUse on Bash): block `git add .`, `git reset`, `git restore`, `git clean`, `git stash`, and validate that `git commit` only includes files from the session edit log
242
+
-**Git guard** (PreToolUse on Bash): block `git add .`, `git reset`, `git restore`, `git clean`, `git stash`; validate that `git commit` only includes files from the session edit log; validate branch names match conventional prefixes
221
243
222
-
See this repo's `.claude/hooks/track-edits.sh` and `guard-git.sh` for a working implementation. Pair with the `/worktree` command so each session gets an isolated copy of the repo.
244
+
Pair with the `/worktree` command so each session gets an isolated copy of the repo.
0 commit comments