Skip to content

Add Claude Code hooks for automatic CodeGraph sync#22

Merged
colbymchenry merged 1 commit into
mainfrom
claude-hooks
Feb 10, 2026
Merged

Add Claude Code hooks for automatic CodeGraph sync#22
colbymchenry merged 1 commit into
mainfrom
claude-hooks

Conversation

@colbymchenry

@colbymchenry colbymchenry commented Feb 10, 2026

Copy link
Copy Markdown
Owner

Summary

  • Added codegraph mark-dirty and codegraph sync-if-dirty CLI commands for dirty-marker based sync
  • Added hooks config writing to the installer (writeHooks, hasHooks in config-writer)
  • Installer now writes PostToolUse + Stop hooks to settings.json automatically
  • Added .dirty to .codegraph/.gitignore template

How it works

When Claude edits files during a session, hooks keep the CodeGraph index fresh:

  1. PostToolUse(Edit|Write)codegraph mark-dirty (async) — writes timestamp to .codegraph/.dirty
  2. Stopcodegraph sync-if-dirty (sync) — if .dirty exists, removes it and runs cg.sync()

This batches all edits in a single Claude response into one sync, right before the next user turn.

Edge cases handled

Case Behavior
.codegraph/ doesn't exist Both commands exit silently (code 0)
Project not initialized (no DB) sync-if-dirty exits after removing marker
Rapid concurrent PostToolUse hooks All overwrite same .dirty file — safe
Edit during sync Marker deleted before sync, new edit re-creates it
codegraph not on PATH Local installs use npx @colbymchenry/codegraph

Files changed

  • src/bin/codegraph.ts — two new CLI commands
  • src/installer/config-writer.tsgetHooksConfig(), writeHooks(), hasHooks()
  • src/installer/index.ts — hooks step added to installer flow
  • src/directory.ts.dirty added to gitignore template

Test plan

  • npm run build compiles cleanly
  • codegraph mark-dirty exits silently when no .codegraph/ exists
  • codegraph sync-if-dirty exits silently when no .codegraph/ exists
  • hasHooks() correctly detects presence/absence of hooks

Resolves #2

🤖 Generated with Claude Code

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>
@colbymchenry colbymchenry merged commit c034c50 into main Feb 10, 2026
@colbymchenry colbymchenry deleted the claude-hooks branch February 10, 2026 22:47
jorgerobles pushed a commit to jorgerobles/codegraph that referenced this pull request Jun 1, 2026
Add Claude Code hooks for automatic CodeGraph sync
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

git-hook potential issue when codegraph is not installed globally

1 participant