Skip to content

commandGit and releases

Why Changed

Explains why a file or function looks the way it does by tracing its commits, blame and linked issues, with evidence.

npx workspacetemplates add why-changed --tool claude-code

Writes 1 file to .claude/commands/

.claude/commands/why-changed.md14 lines · 1.2 KBFile
---
description: Explains why a file or function looks the way it does by tracing its commits, blame and linked issues, with evidence.
argument-hint: "<file>, <file:line> or <function name>"
---

Explain why this code looks the way it does: $ARGUMENTS

1. Resolve the target to a file and line range. If a function name is given, find its definition first.
2. Use `git blame -w -C -L <range> <file>` to list the commits behind those lines, ignoring whitespace and moved code.
3. For each distinct commit, run `git show <hash>` and read the message, body and diff. Then follow renames with `git log --follow -p -- <file>` when the trail ends at a move.
4. Collect references: issue or PR numbers (#123, JIRA-45) in messages. If the gh CLI is available and authenticated, read them with `gh pr view` or `gh issue view`. Never guess at links you cannot open.
5. Look at nearby tests and comments added in the same commits; they often state the intent.

Answer in this shape: **Short answer** (two sentences), **Timeline** (date, commit, author, what changed and why), **Evidence** (quotes from messages or tickets), **Confidence** (high, medium, low) and **Safe to change?** with the conditions. Make no edits.

What it does

Odd-looking code usually has a reason that lives in an old commit or ticket. This command follows the history of the exact lines you ask about and tells the story: who changed them, when, and what problem the change solved.

It separates what the history proves from what it only suggests, so you know whether removing a strange workaround is safe.

Example

you › /why-changed src/billing/round.ts:22

agent › Short answer: the extra Math.floor exists because invoices must match the bank rounding.
Timeline: 2024-03-02 c81f0aa "Fix 1 cent mismatch (#412)".
Confidence: high. Safe to change only if the bank export is updated too.

Questions

What if the history was squashed?
It reports the squash, reads the pull request text if it can, and lowers its confidence rating.
Does it need network access?
Only for linked tickets through gh. Without it, it works from local git alone and says so.
  • Branch Cleanup

    CommandGit and releases

    Free
  • Changelog Entry

    CommandGit and releases

    Free
  • Cherry Pick Fix

    CommandGit and releases

    Free
  • Commit Message

    CommandGit and releases

    Free