For my hobby projects, I usually have an AI generated context file that captures what the project does and how it’s structured. This helps me (or an agent) get up to speed quickly. The problem starts once I make a lot of progress into the project, I end up forgetting about the context file, and it becomes outdated pretty fast.

So instead of trying to be more disciplined about documentation, I decided to automate the problem away.

A git hook that keeps the context updated

context-generator-hook works as a post-commit hook, that reviews the git diff and auto updates the context file. Choosing a post-commit over pre-commit is intentional: I didn’t want the hook blocking my commit and I can review the AI-generated output before pushing it.

Every time I commit code, the hook:

  1. Grabs the git diff from the latest commit
  2. Small changes like typo fixes, formatting or non-essential file updates are skipped
  3. For small, but meaningful changes, it sends the diff to an LLM to patch the context file
  4. For large diffs (above a diff line threshold), it regenerates the entire context file from scratch

I’m currently using the free API keys from Gemini to run this, and the smaller 2.5-flash model works well for this use-case. The model is interchangeable on the tool.

This allows me to have a technical overview of my codebase that updates automatically on commits. Whenever I come back to a project after a few months, there is an accurate summary in the context file.

Setting up the git hook

Source Code: Github

Install: uv tool install git+https://github.com/thameenas/context-generator-hook.git

Generate an initial context from your existing codebase: ctxgen init

Install the Git hook: ctxgen install-hook