← All posts
·10 min read

Git Hooks for AI Prompt Capture: A Technical Deep Dive

How Qmmit uses post-commit and pre-push git hooks to automatically capture AI prompts, match them to commits, and sync to your profile.

git hookstechnicalarchitectureautomation

Git hooks are scripts that run automatically at specific points in the git workflow. Qmmit uses two hooks — post-commit and pre-push — to create a seamless prompt tracking experience with zero workflow changes.

Post-Commit Hook: Capture

The post-commit hook fires immediately after every git commit. It does three things: reads the commit SHA and metadata, scans AI tool session files for recent prompts, and matches prompts to the commit using a weighted scoring algorithm.

The scanning process reads session files from all detected AI tools. For Cursor, it queries the SQLite database. For Claude Code, it reads JSONL files. For Copilot, it reads chatSessions. Each scanner filters by project path (only prompts from this repo) and timestamp window (only prompts since the previous commit).

The Matching Algorithm

Matching prompts to commits uses five weighted signals: Temporal Proximity (35%) checks if the prompt was written between the previous commit and this one. File Overlap (30%) checks if files referenced in the prompt match files changed in the commit. Keyword Match (20%) looks for prompt words in the commit message or diff. Code Similarity (10%) checks if AI-generated code appears in the diff. Session Continuity (5%) gives a bonus if the prompt is in the same session as a previously matched prompt.

Confidence thresholds: 80%+ is auto-matched (HIGH), 50-79% is MEDIUM (developer confirms), below 50% goes to a review queue. The algorithm is configurable — you can adjust weights in .qmmit/config.json.

Pre-Push Hook: Sync

The pre-push hook fires when you run git push. It collects all unsynced prompts, runs a secret scanner to auto-redact API keys and passwords, and sends the data to the Qmmit API. The sync is rate-limited to 60 requests per hour and 100 prompts per sync.

Both hooks always exit 0 — they never block git operations. If the hook fails for any reason, git continues normally. This is critical for developer trust.

Prepare-Commit-Msg Hook: Trailer

Qmmit also installs a prepare-commit-msg hook that adds a trailer to your commit messages showing how many AI prompts were captured. This is optional and purely informational.

Coexistence with Other Hooks

If you use husky, lefthook, or other hook managers, Qmmit appends to existing hooks rather than replacing them. It detects existing hook content and adds its script at the end.

Implementation Details

On macOS and Linux, hooks call the qmmit binary directly. On Windows, hooks use the full binary path because git hooks run in sh.exe which may not have the user PATH. The binary path is resolved at install time and written into the hook script.

Start tracking your AI prompts

One command. Zero workflow changes. Works with 7 AI tools.

curl -fsSL https://qmmit.dev/install.sh | bash