Work in Progress

Know why code exists,
not just what it does.

git-why is an open protocol for storing reasoning traces alongside your source code. It preserves the conversations and decisions that shaped every line.

View on GitHub Read the RFC How it works

The problem

AI-assisted development creates two artifacts. Only one survives.

What git keeps

$ git blame src/auth.py
a3f1c9d2 Pierre  line 42:  @retry(max=3, backoff="expo")
a3f1c9d2 Pierre  line 43:  def refresh_token(self):

$ git log --oneline -1
a3f1c9d2 Add retry to auth refresh

What git-why preserves

$ git why show src/auth.py

## Add retry with exponential backoff

Reasoning: Considered circuit breaker
(too heavy), fixed delay (thundering
herd risk), and exponential backoff
with jitter (chosen).

Prompt: "Add retry logic when the
auth token refresh fails"

Built for real teams

Designed around the constraints that matter in practice.

🔍

Zero-config reading

Traces are plain Markdown files in .why/. Read them with cat, browse on GitHub, or use the CLI.

🔧

Tool-agnostic

Works with Claude Code, Cursor, Copilot, Aider, or manual annotations. The protocol is the product.

📊

Clean diffs

Append-only, prepend-newest format means git diff output is always readable and reviewable.

🔒

Privacy-first

Never captures API keys, tokens, file contents, or command output. Exclusion patterns via .whyignore.

🔁

Merge-friendly

Uses git's union merge strategy. Independent entries from different authors combine without conflicts.

Automatic capture

Pre-commit hook detects AI sessions and writes traces automatically. No workflow changes needed.

One team, any tool

Everyone on the team picks their own AI coding assistant. git-why captures reasoning from all of them into the same shared format.

The provider plugin system auto-detects which tool is active and extracts reasoning traces transparently. No configuration, no coordination — each developer uses what they prefer, and the .why/ files stay consistent.

Claude Code
provider included
Codex
provider included
Manual
built-in
+ Build yours
5 functions, 1 file
same repo, same week, different tools
Alice claude-code .why/src/auth.py.md — auto-captured
Bob cursor .why/src/api.py.md — auto-captured
Carol human .why/src/db.py.md — git why capture -m "..."

Every entry records which tool produced it via the tool attribute. Readers don't need to know or care — traces from all tools look the same and work with the same git why show, blame, search commands.

Adding a provider is a single shell script with 5 functions. Copy the template, implement session detection and parsing, submit a PR. The contribution guide walks through every step.

How it works

Three concepts: a directory, a format, and a hook.

1

Mirror your source tree

The .why/ directory mirrors your project structure. Each source file gets a corresponding .why/path/to/file.md containing its reasoning traces.

project structure
repo/
  src/
    auth.py
    utils.py
  .why/
    .gitattributes       # merge=union
    .whyignore            # exclude patterns
    _sessions/            # full transcripts
    src/
      auth.py.md         # traces for auth.py
      utils.py.md        # traces for utils.py
2

Structured trace entries

Each entry captures the prompt, the reasoning behind the decision, and a summary of changes. Entries are prepended so the most recent context is always first.

.why/src/auth.py.md
<!-- why:entry session="a21f..." date="2026-04-11"
     tool="claude-code" -->

## 2026-04-11 — Add retry with exponential backoff

### Prompt
> Add retry logic when the auth token refresh fails.
> The IDP is flaky under load.

### Reasoning
Current refresh_token() calls the IDP once and raises
on failure. Three options considered:
- Circuit breaker — too heavy for a single call
- Fixed delay retry — thundering herd risk
- Exponential backoff + jitter — chosen

### Changes
- line 5:  added @retry import
- lines 42-58:  wrapped with @retry(max=3)

<!-- /why:entry -->
3

Capture happens at commit time

A pre-commit hook detects your AI session, extracts reasoning for each staged file, and writes .why entries automatically. No extra steps in your workflow.

$ git why init
Created .why/ directory
Installed pre-commit hook
Ready.

$ git commit -m "Add retry to auth"
[git-why] Capturing reasoning for 1 file...
[git-why] Wrote .why/src/auth.py.md
[main a3f1c9d] Add retry to auth
 2 files changed, 28 insertions(+)

$ git why show src/auth.py
━━━ 2026-04-11 — Add retry with exponential backoff ━━━
Considered circuit breaker (too heavy), fixed delay
(thundering herd), exponential backoff with jitter (chosen).

The new dev workflow

git-why adds one invisible step to your existing workflow. Everything else stays the same.

Before git-why

1

Write code with AI

Chat with your AI tool, iterate on the implementation, explore tradeoffs together.

2

Commit & push

Stage your changes, write a short commit message, push to the remote.

3

Context is lost

The conversation, rejected alternatives, and reasoning behind decisions disappear when the session ends.

4

Teammate asks "why?"

Someone reads your code in a review or months later. The commit message says what, never why. They guess, or they ping you.

With git-why

1

Write code with AI same

Nothing changes. Use Claude Code, Cursor, Copilot, Aider — whatever you prefer.

2

Commit & push same

Same workflow. The pre-commit hook silently captures reasoning from your AI session and stages .why files alongside your code.

3

Context travels with the code new

Reasoning traces are committed, pushed, and versioned just like source code. They survive across sessions, machines, and team members.

4

Teammate runs git why show new

They see the original prompt, the alternatives considered, and why this approach was chosen — instantly, without asking anyone.

CLI commands

A git subcommand that feels native.

git why init

Set up .why/, install the pre-commit hook, create .whyignore

git why show <file>

Display reasoning traces for a file, formatted and color-coded

git why blame <file>

Enhanced git blame with inline links to reasoning traces

git why log

Annotated commit log showing which commits have reasoning attached

git why search <query>

Full-text search across all .why files in the repository

git why capture

Manually capture reasoning from the current AI session or a message

git why status

Show configuration, trace count, active session, and installed providers

Design principles

Every decision in the protocol traces back to one of these.

Protocol first

The .why format is the product. The CLI is just one implementation. Any tool can read and write conforming files.

Append-only

New entries never rewrite old ones. History accumulates in the file, deeper history lives in git log.

Greppable

No databases, no binary formats. Plain text that works with cat, grep, and your favorite editor.

Invisible to readers

Zero config to read traces. Writers opt in once with git why init. Skip anytime with GIT_WHY_SKIP=1.

Status

git-why is under active development. The RFC and reference CLI are available now.

Draft
RFC status
v0.1.0
Reference CLI
Bash
Implementation

Installation instructions and detailed documentation coming soon.