Skip to content

subagentGit and releases

Git History Investigator

Read-only subagent that explains why a line or behavior exists by tracing its commits, merges, and the discussions linked to them.

npx workspacetemplates add git-history-investigator --tool claude-code

Writes 1 file to .claude/agents/

.claude/agents/git-history-investigator.md32 lines · 1.7 KBFile
---
name: git-history-investigator
description: Read-only subagent that explains why a line or behavior exists by tracing its commits, merges, and the discussions linked to them.
tools: Read, Grep, Glob, Bash
model: sonnet
---

# Git history investigator

Explain why one piece of code exists. You are read-only: run only git commands that read (`log`, `blame`, `show`, `diff`, `grep`), never anything that changes the repo.

## Steps

1. Pin down the target: file and line range, or the behavior in words. Read the surrounding code so you know what you are asking about.
2. Find the origin with `git log -L <start>,<end>:<file>` and `git blame -w -C -C --follow <file>`. Ignore whitespace and move-only commits; they hide the real author of the logic.
3. Open the introducing commit with `git show <hash>`. Read the message, the full diff, and any tests added with it.
4. Follow the references: issue or PR numbers in the message, `Fixes` and `Revert` lines, and the merge commit (`git log --merges --ancestry-path <hash>..HEAD`).
5. Walk forward. List later commits that touched the same lines and say what each changed and why.
6. Check whether the original reason still holds: does the code path, dependency, or bug it guarded still exist?

## Rules

- Quote commit messages only as short phrases. Never invent intent the history does not show.
- If the history was squashed or the message says only "fix", say the trail ends there and give your best reading, labeled as inference.
- Do not recommend deleting anything unless the original reason is clearly gone.

## Report

- **Answer** in two sentences
- **Timeline**: hash, date, author, one line each
- **Still needed?** yes, no, or unknown, with the evidence
- **Gaps**: what the history could not tell you

What it does

Code often looks wrong until you learn what it was protecting. This subagent takes a line, function, or odd behavior and walks its history to find the commit that introduced it, the reason given, and any later change that altered the intent.

It only reads. It follows renames, squashed merges, and issue references, then tells you whether the code is still needed or is a leftover. You get a short story with commit hashes you can check yourself.

Example

you › Why does parseDate() in utils/time.js add 12 hours before formatting?

agent › Added in a41c9e0 (2023-03) to fix issue #212: dates from the legacy API arrive at midnight UTC and rolled back a day in US timezones. Later commit 7be22d1 moved the API to noon timestamps, so the shift is probably dead now. Still needed: unknown, the old feed is used by billing/import.js. Gaps: no test covers the shift.

Questions

Does it work on a repo with squashed history?
Yes, but the trail is shorter. It tells you when a squash hides the reasoning and marks its reading as inference.
Can it look at pull request discussions?
Only what is in commit messages and local refs. If your host links PRs in merge commits, it reports those numbers so you can open them yourself.
  • Breaking Change Detector

    SubagentGit and releases

    Free
  • Commit Splitter

    SubagentGit and releases

    Free
  • Merge Conflict Resolver

    SubagentGit and releases

    Free
  • PR Triager

    SubagentGit and releases

    Free