---
title: "How to give AI coding agents context about recent changes · Cork"
description: "Give Claude Code, Codex and Cursor context about recent changes: good commit messages, SessionStart and prompt hooks that inject git history, and live updates."
canonical: "https://corkcli.com/blog/give-ai-coding-agents-context-recent-changes"
last_updated: "2026-10-03"
published: "2026-10-03"
author: "Kevin Vera"
---

# How to give AI coding agents context about recent changes

Give Claude Code, Codex and Cursor context about recent changes: good commit messages, SessionStart and prompt hooks that inject git history, and live updates.

By Kevin Vera · October 3, 2026 · [Guides](https://corkcli.com/blog/c/guides) · 5 min read

AI coding agents do not know what changed in your repo since they last looked: each session starts with a fresh context window. To give them context about recent changes, write commit messages an agent can use, inject a short summary of recent history at session start with a hook (for example the last few commits and the files they touched), add context scoped to the current prompt with a prompt hook, and keep durable decisions in the instruction file. For changes that happen while the agent is working, such as a teammate's rename five minutes ago, you need something that pushes updates into the session as they happen.

## What "recent changes" an agent actually needs

Not all history is useful. An agent about to edit `billing/invoice.py` needs:

- the current signatures of the functions it will call (not last week's),
- who calls the function it is about to change,
- what changed in those files recently and why,
- whether anyone is changing them right now.

It does not need the full `git log` of the repo. Dumping too much history wastes tokens on every request, because the whole conversation is sent again with each turn.

## Step 1: make commit history agent-readable

Agents can run `git log` and `git show` themselves, so the cheapest improvement is better commits. A message like "Rename `charge()` to `charge_card()`; callers in api/ updated, web/ still pending" is something an agent can act on. "wip" is not. Ask your agents to write commit messages in that form by adding a line to `AGENTS.md` or `CLAUDE.md`.

## Step 2: inject recent history at session start

Claude Code's `SessionStart` hook adds whatever your command prints to stdout to Claude's context. The official hooks guide shows exactly this pattern and suggests `git log --oneline -5` as dynamic output. In `.claude/settings.json`:

```json
{
  "hooks": {
    "SessionStart": [
      {
        "matcher": "startup|resume",
        "hooks": [
          {
            "type": "command",
            "command": "git log --oneline -10 && git diff --stat HEAD~5"
          }
        ]
      }
    ]
  }
}
```

The `SessionStart` input includes a `source` of `startup`, `resume`, `clear`, `compact` or `fork`, so you can use a `compact` matcher to re-inject context after the conversation is compacted, which is when details tend to get lost.

Codex supports the same idea: its hooks include `SessionStart` and `UserPromptSubmit`, configured in `~/.codex/hooks.json`, `<repo>/.codex/hooks.json` or `config.toml`. Cursor's hooks include `sessionStart` and `beforeSubmitPrompt` in `.cursor/hooks.json`.

Keep the output short. Ten one-line commits cost little; a full diff of the last week costs a lot on every turn that follows.

## Step 3: add context per prompt, scoped to what is being asked

Session-start context is the same for every task. A `UserPromptSubmit` hook in Claude Code runs on each prompt and can return `additionalContext`:

```json
{
  "hookSpecificOutput": {
    "hookEventName": "UserPromptSubmit",
    "additionalContext": "Recent changes to billing/: charge() renamed to charge_card() in a3f91c2."
  }
}
```

The hook receives the prompt text on stdin, so a script can pick the files the prompt mentions and print only their recent history (`git log --oneline -5 -- billing/`). Plain text on stdout also works and is added to context.

## Step 4: keep durable decisions in the instruction file

Some recent changes are decisions, not diffs: "we moved from REST to tRPC in `api/`", "do not use the old `Money` class". Those belong in `AGENTS.md` or `CLAUDE.md`, which load every session. Claude Code also keeps an auto memory per repository (shared across worktrees), loaded at session start up to the first 200 lines or 25KB. Prune both regularly so old decisions do not outlive the code.

## Step 5: handle changes that happen mid-session

Everything above is a snapshot taken when the session or prompt starts. If a teammate's agent renames `charge_card()` twenty minutes into your agent's task, your agent will not know until a test fails or the merge breaks. Options:

- Re-run the hook manually by starting a new prompt that asks the agent to check `git fetch && git log HEAD..origin/main`.
- Use short tasks so sessions start fresh more often.
- Use a [coordination layer](https://corkcli.com/blog/coordination-layer-ai-coding-agents) that pushes teammates' changes into each agent's next step.

## How Cork helps

Hooks and instruction files give agents a picture of the past. Cork adds the present. Cork is the coordination layer for [multiplayer coding agents](https://corkcli.com/blog/multiplayer-coding-agents): it keeps Claude Code, Codex and Cursor agents, on one machine or across a team's machines, from overwriting each other on one codebase, and hands each agent what the others already learned.

For recent-change context specifically:

- **Briefing**: when an agent starts or gets a prompt, it is handed the exact signatures, callers and recent changes of the code it is about to touch, so it searches less. This is Step 2 and Step 3 above, done for you and scoped to the code in question.
- **Live awareness**: when another agent changes code yours depends on (a rename, a new signature), your agent hears it on its next step. That is the mid-session gap in Step 5.
- **remember and recall**: durable notes anchored to specific code, available to every agent, through Cork's MCP tools.
- **recap**: what happened and what it cost, as an MCP tool.

Cork's hooks in Claude Code, Codex and Cursor do this with no extra model calls. Install:

```bash
curl -fsSL https://corkcli.com/install.sh | sh
```

## Frequently asked questions

### Do AI coding agents remember changes from previous sessions?

Only what is written down. Instruction files and Claude Code's auto memory persist; the conversation itself does not. Everything else the agent must rediscover from the repo.

### How do I make Claude Code aware of the latest git commits?

Add a `SessionStart` hook that prints `git log --oneline -10`. Claude Code adds the hook's stdout to the session's context.

### How do I tell an agent that a teammate changed a function?

Snapshots at session start miss it. Either start a new prompt that tells the agent to fetch and read the new commits, or use a tool that delivers teammates' changes to the agent while it works.

### Will injecting git history increase token usage?

Yes, on every following turn, because the context is resent. Inject a few lines scoped to the files in question, not full diffs.

## Sources

- <https://code.claude.com/docs/en/hooks>
- <https://code.claude.com/docs/en/hooks-guide>
- <https://code.claude.com/docs/en/memory>
- <https://code.claude.com/docs/en/costs>
- <https://learn.chatgpt.com/docs/hooks.md>
- <https://cursor.com/docs/hooks>

## Related reading

- [Pre-commit checks for code written by AI agents](https://corkcli.com/blog/pre-commit-checks-ai-generated-code): Pre-commit checks for AI-written code: git hooks, the pre-commit framework, secret scanning, and agent hooks in Claude Code, Codex and Cursor.
- [Why AI agents re-read the same files, and how to stop it](https://corkcli.com/blog/why-ai-agents-reread-same-files): Why Claude Code, Codex and Cursor agents keep re-reading the same files, and how to stop it: specific prompts, lean context, symbol lookups and briefings.
- [Codex hooks and Cursor hooks: how to use them for team coordination](https://corkcli.com/blog/codex-cursor-hooks-team-coordination): How Codex and Cursor hooks work as of October 2026, where the config lives, how to block or brief an agent, and how to use hooks to coordinate a team's agents.
- [MCP servers for coordinating coding agents: what they are and how to use one](https://corkcli.com/blog/mcp-servers-coordinating-coding-agents): What an MCP server for coordinating coding agents does, how it differs from hooks, and how to connect one to Claude Code, Codex, Cursor and Gemini CLI.

[All articles](https://corkcli.com/blog.md) · [Cork in Markdown](https://corkcli.com/index.md) · [llms.txt](https://corkcli.com/llms.txt)

This page in HTML: https://corkcli.com/blog/give-ai-coding-agents-context-recent-changes
