# GitWhy GitWhy is the context layer for git. It gives developers and coding agents a place to save the reasoning behind AI-assisted code changes, tied to the commits that produced them. Saved contexts are stored locally and can be published to pull request comments via the GitHub App. ## Core concept When you finish a feature with your coding agent, you tell the agent to save a context. The agent generates a structured markdown document — what was done, why this approach, what was rejected, what the risks are — and saves it with `git why save` or the `gitwhy_save` MCP tool. The context is stored locally in `.git/gitwhy/contexts///.md`. Running `git why push` publishes it to the PR. ## CLI commands - `git why setup` — set up GitWhy globally and configure agents - `git why save` — save a context (reads structured markdown from stdin) - `git why get ` — retrieve a context by ID (e.g., `git why get ctx_a1b2c3d4`) - `git why log` — list all saved contexts - `git why tree` — show context tree organized by domain/topic - `git why search ` — search contexts by keyword - `git why push` — publish contexts to the API, trigger GitHub App PR comments ## MCP tools When the MCP integration is installed, the coding agent has access to: - `gitwhy_save(markdown, domain?, topic?)` — save a context, returns context ID - `gitwhy_get(id)` — retrieve a context, returns full markdown - `gitwhy_search(query, cloud?)` — search contexts, returns matching results - `gitwhy_list(domain?, topic?)` — browse contexts and tree structure - `gitwhy_status()` — check setup state, pending commits, auth - `gitwhy_sync(ids?)` — upload contexts to cloud (private) - `gitwhy_publish(ids)` — share contexts with team - `gitwhy_post_pr(ids?)` — post context summary as PR comment ## Context format Contexts use a structured markdown template with these sections: - Title + metadata (Context ID, Saved by, Agent, Repository, Branch, Date) - `## Prompt` — the original user prompt, quoted verbatim (required) - `## What Was Done` — bulleted list of actions (required) - `## Reasoning` — why this approach was chosen (required) - `## Key Decisions` — binary choices and rationale (optional) - `## Rejected Alternatives` — what was considered and why rejected (optional) - `## Risks & Open Questions` — uncertainties and follow-up actions (optional) - `## Files` — files changed with status and description (required) - `## Commits` — auto-populated from post-commit hook (auto) - `## Verification` — test results, build status (optional) Context IDs: `ctx_` + 8 alphanumeric characters (e.g., `ctx_a1b2c3d4`) ## Integration methods Four ways for the coding agent to connect with GitWhy (selected during `git why setup`): 1. **MCP** (recommended) — gives agent save/get/search tools 2. **Skill files** (recommended) — creates `.claude/skills/gitwhy/` with format guidance 3. **Rules** — appends instructions to CLAUDE.md/AGENTS.md 4. **Hook** — injects instructions via UserPromptSubmit (higher token cost) ## Local storage Contexts live in `.git/gitwhy/contexts///ctx_.md`. Contexts stay local until `git why push`. The post-commit hook installed on the first `git why save` in a repository tracks future commits for later save metadata. ## Key differentiators - Git-native: contexts are tied to specific commits - Explicit save: developer/agent chooses when to save (not automatic surveillance) - PR delivery: GitHub App posts context comments on pull requests - No LLM API key required: the coding agent generates the structured content - Offline-capable: all local commands work without a network connection ## URLs - Homepage: https://gitwhy.dev - Dashboard: https://app.gitwhy.dev - Docs: https://gitwhy.dev/docs - GitHub: https://github.com/gitwhy/gitwhy ## Tech stack - Language: Go - CLI: Cobra - Local MCP: mark3labs/mcp-go - Database: PostgreSQL - Frontend: Next.js (dashboard) - Docs: Mintlify ## Repository structure ``` cmd/git-why/ CLI commands (setup, save, get, log, tree, search, push, mcp) internal/ core logic (storage, mcp, config) api/ hosted REST API handlers github-app/ GitHub App PR comment integration docs/ Mintlify documentation site tasks/ implementation tracking ```