Add Claude Code hooks for automatic CodeGraph sync#22
Merged
Conversation
PostToolUse(Edit|Write) marks the project dirty via .codegraph/.dirty, and Stop syncs only if dirty — batching all edits into one sync per Claude response. The installer now writes these hooks to settings.json. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
jorgerobles
pushed a commit
to jorgerobles/codegraph
that referenced
this pull request
Jun 1, 2026
Add Claude Code hooks for automatic CodeGraph sync
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
codegraph mark-dirtyandcodegraph sync-if-dirtyCLI commands for dirty-marker based syncwriteHooks,hasHooksin config-writer)settings.jsonautomatically.dirtyto.codegraph/.gitignoretemplateHow it works
When Claude edits files during a session, hooks keep the CodeGraph index fresh:
codegraph mark-dirty(async) — writes timestamp to.codegraph/.dirtycodegraph sync-if-dirty(sync) — if.dirtyexists, removes it and runscg.sync()This batches all edits in a single Claude response into one sync, right before the next user turn.
Edge cases handled
.codegraph/doesn't existsync-if-dirtyexits after removing marker.dirtyfile — safecodegraphnot on PATHnpx @colbymchenry/codegraphFiles changed
src/bin/codegraph.ts— two new CLI commandssrc/installer/config-writer.ts—getHooksConfig(),writeHooks(),hasHooks()src/installer/index.ts— hooks step added to installer flowsrc/directory.ts—.dirtyadded to gitignore templateTest plan
npm run buildcompiles cleanlycodegraph mark-dirtyexits silently when no.codegraph/existscodegraph sync-if-dirtyexits silently when no.codegraph/existshasHooks()correctly detects presence/absence of hooksResolves #2
🤖 Generated with Claude Code