Give your AI agents git memory

two step framework to give Claude Code, Cursor & Copilot the context they're missing

Before you jump in, here’s something you’ll love.
I’ve put together a curated list of MCP servers and MCP registries to support your development workflows. When you subscribe to the newsletter, you’ll get instant access to this resource in your welcome email.

Bonus: I’m also working on a collection of free educational resources for building AI agents at every skill level. Coming soon for subscribers. Stay tuned!

Whats the problem?

Our agents excel at pattern matching against their training data. However, they struggle with project specific context that isn't immediately visible in your current file or your current staged changes.

Common issues we observe
- Suggesting deprecated patterns
- Missing architectural constraints
- Generating code that contradicts recent refactoring decisions
- Lack of awareness about why certain implementations exist

These agents see your code as it exists now, not as it evolved.

How to solve it?

The answer is using commit history as context.

There are many papers published that are using commit history in LLM workflows leading to major gains in accuracy, code quality and bug resolution in large codebases. You can read them below.

How to implement in our daily workflows?

Step 1: Start with better commit messages

# Instead of:
git commit -m "fix bug"

# Write:
git commit -m "fix: resolve null pointer in payment processor

Handles edge case when processing refunds for deleted products.
Addresses production incident from 2024-01-15."

Step 2: Automated context for agents

To ensure AI coding agents provide relevant, project specific suggestions and avoid hallucinating changes or missing nuances, it’s crucial for them to have deep context from recent development activity on the branch. This means:

Automatically fetch branch commit history: Before making suggestions or implementing a ticket, the agent should access all commits specific to the feature or ticket branch rather than just the latest state. This delivers insight into the intent behind recent changes, incremental fixes and why the codebase looks the way it does.

Summarize changed files and diffs: For each commit in the branch, the agent should extract
- Commit message summary (including ticket/issue ID if available)
- List of files changed and brief diff summary.

Build branch timeline: By walking the branch history, the agent can form a timeline that reveals how the implementation evolved, what decisions were made in order and which tickets are related.

Inject history into LLM prompts: The agent should programmatically append this branch commit history and file diffs to its prompt. This creates a “memory-aware” context window for Ai agents.

Trigger Based on Implementation Context: Agents should be taught to always fetch and parse commit history when:
- The branch is not main/master
- The latest commits correspond to tickets/issues

Instructions for your claudeCode/copilot/cursor agent

Whenever you generate code, refactor files, or assist in debugging for this repository, always:

1. Fetch Full Commit History for Feature Branches
   - Run: `git log main..HEAD --oneline --name-status`
   - If on the main/master branch, use: `git log --oneline --name-status`
   - For deep context, use: `git log --stat` or `git log -p` to get diffs when necessary.

2. Summarize Commit Messages and Changed Files
   - For each recent commit, write a short summary that includes the commit message, ticket/issue ID, affected files, and brief diff summaries (if possible).
   - Highlight architectural changes, refactors, and bug fixes.

3. Build and Reference a Branch Timeline
   - Assemble a chronological timeline showing how the feature or ticket’s implementation evolved.
   - Note the order of key decisions, related tickets/issues, and incremental fixes.

4. Inject Commit History Context into All Prompts
   - Always append the above summaries, diffs and timeline to the agent’s context/prompt before suggesting code, debugging, or explaining implementations.
   - Reference relevant architectural changes, previous bug fixes, and refactorings from the branch history in all code completions and explanations.

5. Trigger History Fetch Automatically
   - Automatically fetch, parse, and inject commit history when:
     - The branch isn’t main/master
     - You are working on a ticket branch (with an issue ID)
     - Recent changes relate to bug fixes, architectural changes, or refactoring
   - If context appears lacking, re-fetch and summarize more history.

You can use the above as your Claude Code subagent or add it to the project rules in Cursor or Copilot

This instruction will make sure your agents always add the right context for every ticket implementation, reducing hallucinations and increasing code output quality.

If you’re not a subscriber, here’s what you missed this month

Subscribe to get access to such posts every week in your email.

👀 Whats shipping (shipped) this week?

So far it looks like GPT-5 barely outpaces Opus 4.1 from the SWE benchmarks. But I’m gathering more sentiments around the agentic capabilities for both GPT-5 and Opus 4.1 in the coming weeks. Will keep you guys posted.

📖 Worth the scroll

🤓 Case Studies

📰 Recommended newsletters

Techpresso gives you a daily rundown of what's happening in tech and read by 300,000+ professionals.

The Deep View The go to daily newsletter for 250k+ founders and knowledge workers who want to stay up to date with artificial intelligence..

📱 Stay connected: Follow me on LinkedIn and Twitter/X for daily AI tool breakdowns and quick wins

Do you like this edition?

Login or Subscribe to participate in polls.

Thanks for reading
- Sanket