DEV Community

Cover image for How I Automated My AI Coding Assistant's Memory Using Git Hooks and n8n
Blaze
Blaze

Posted on

How I Automated My AI Coding Assistant's Memory Using Git Hooks and n8n

I kept running into the same problem: every time I opened a new chat in Cursor, I'd have to re-explain the same architecture decisions, conventions, and gotchas about my codebase. The AI could see my code, but it had no idea why things were built a certain way.

So I automated it.

The idea

Every time you commit code, a small script watches for it, sends the diff to an AI, and asks a simple question: does this commit reveal anything durable worth remembering? If yes, it gets added to a living context file. If it's just a typo fix or formatting change, nothing happens.

How it works

1. A git post-commit hook fires automatically after every commit. It grabs the diff and the current context file, and sends both to a webhook.

2. An n8n workflow receives it, and passes the diff to an AI model (I used Groq's Llama 3.3, mainly for cost and speed) with a system prompt like:

"Given the EXISTING context file and a NEW COMMIT, add any new durable, reusable knowledge this commit reveals. Do not duplicate existing info. If nothing durable, return the file unchanged."

3. The AI's response gets written back to a CONTEXT.md file in the repo, and also copied into Cursor's rules folder (.cursor/rules/) so it auto-loads in every chat without manually tagging it.

The result

Same question, asked before and after a commit that explained a design decision:

Before: generic textbook answer about the concept in general.

After: specific answer referencing the actual reasoning from the commit.

Things that were harder than expected

A few real gotchas from building this:

  • Windows services often run under a different environment than your normal user account, which broke basic things like PATH resolution for git
  • Cloud sync folders (OneDrive, etc.) can silently interfere with file writes
  • Passing large AI-generated content through command-line arguments hits length limits fast, better to write files directly from code
  • n8n's binary data storage mode isn't always a plain base64 string depending on configuration, worth checking before assuming a simple decode will work

Try it yourself

The whole setup is just a git hook + an n8n workflow, both plain files you can inspect and modify. I packaged a ready-to-import version with a setup guide if you'd rather skip the build:

Happy to answer questions about the node setup, the webhook design, or anything else in the comments.

Top comments (0)