Git Hooks Architecture
Learn how Qodewk executes non-blocking background Git hooks in under 5ms.
Qodewk's autonomous telemetry engine relies on lightweight Git hooks (post-commit and post-rewrite) to capture file mutations and agent footprints without adding latency to developer workflows.
Core Invariant:
Git hooks must never block standard developer commits. Qodewk hooks spawn detached background processes and exit with code 0 in under 5ms.
How It Works
When you run qodewk hook install, Qodewk writes hook scripts into .git/hooks/post-commit and .git/hooks/post-rewrite:
qodewk hook installDetached Process Execution
The hook invokes Qodewk detached from standard input/output streams:
#!/bin/sh
# --- BEGIN QODEWK HOOK ---
if command -v qodewk >/dev/null 2>&1; then
(qodewk record-event &) >/dev/null 2>&1
elif command -v npx >/dev/null 2>&1; then
(npx --yes qodewk record-event &) >/dev/null 2>&1
fi
# --- END QODEWK HOOK ---Because execution is wrapped in ( ... & ) >/dev/null 2>&1, the Git process completes instantly while Qodewk asynchronously:
- Gathers diff metrics (
git diff-tree --numstat --summary). - Harvesters open agent sessions (Claude Code, Cursor, Codex, Windsurf, Aider, Antigravity).
- Computes dual-engine cost heuristics.
- Stores the event in
~/.qodewk/state.dband writes Git notes torefs/notes/qodewk.
Coexistence with Husky & Lefthook
Many repositories use hook management tools such as Husky or Lefthook.
Qodewk respects existing hooks. It never overwrites your pre-existing scripts; instead, it injects bounded blocks delimited by:
# --- BEGIN QODEWK HOOK ---
...
# --- END QODEWK HOOK ---Uninstalling Hooks
To remove Qodewk hooks cleanly:
qodewk hook uninstallOnly the bounded block is removed, leaving your existing Husky or custom scripts untouched.