Skip to main content

Tells you what to be afraid of before you touch a file.

Project description

WhyCode

Tells you what to be afraid of before touching a file.

git blame answers "who". git log answers "what". WhyCode answers the question your senior engineer asks before any change:

"Should I be careful here?"

It mines what your repository already remembers — reverts, hotfixes, incident-tagged commits, ghost authors, tightly coupled files, long silences, verbatim warnings from past authors — and condenses them into a single Risk Card. Then it hands that card to you, your CI, or the AI that's about to edit the code.

Who is this for?

WhyCode is most valuable in moments when the wrong edit hurts. If you recognise yourself in any of these, it'll pay rent:

  • Solo dev returning to a 3-month-old side projectwhycode why <file> to remember why the weird bit is weird before the AI "fixes" it.
  • Senior engineer joining an unfamiliar codebasewhycode scan to map the load-bearing walls; whycode why before each first edit.
  • AI-paired developer — install the MCP server and your editor's assistant can read invariants and incident history before it refactors.
  • Tech lead reviewing PRswhycode diff ranks the PR's files by risk so attention goes to the scary changes first.
  • CI / pre-commit gatingwhycode diff --fail-on history blocks the build when high-risk files change without explanation.
  • SRE doing a 3am hotfixwhycode why <file> --brief for a one-line "what should I be afraid of?" sanity check.
  • Junior dev wanting to ship without breaking thingswhycode scan shows where to step lightly.

What WhyCode is not for: replacing git blame, telling you what changed, or suggesting fixes. It tells you the why and the risk. You decide what to do.

Install

pip install whycode-cli

The PyPI distribution is whycode-cli (the bare name whycode was already taken by an unrelated project); the installed command is still whycode.

From source, if you want to track main:

pip install git+https://github.com/fangshuor/WhyCode.git

Requires Python 3.11+.

60-second tour

cd /path/to/your/repo

whycode init                        # one-command setup: CI workflow + pre-commit gate
whycode highlights                  # first-run treasure map: top decisions + incidents
whycode why src/some/file.py        # the Risk Card for one file
whycode why src/some/file.py -b     # one-line summary (for triage / scripts)
whycode why src/some/file.py --at <sha>     # risk as of a past commit
whycode why src/some/file.py --mute <kind>  # local "this signal is wrong, hide it" feedback
whycode diff                        # rank everything you changed vs origin/main
whycode diff --staged               # ditto, for files staged for commit
whycode diff --fail-on history      # CI gate: exit 1 if any file is ≥ READ HISTORY FIRST
whycode show <sha>                  # classification + per-file risk for one commit
whycode timeline src/some/file.py   # risk score evolution across the file's history
whycode honest src/some/file.py     # every invariant line, verbatim, untruncated
whycode scan --top 10               # the riskiest files in the whole repo
whycode mcp -v                      # MCP server with tool-call logging

That's it. No config file, no daemon, no account, no upload.

What a Risk Card looks like

╭─  READ HISTORY FIRST  score 57/100 ──────────────────────────────╮
│ src/payment/refund.py   (24 commits)                             │
│ Latest: hotfix: idempotency token regression                     │
│         a3f4b2c1   Mei Chen   2025-09-14                         │
╰──────────────────────────────────────────────────────────────────╯
   HIGH    3 reverts touched this file
           9d2e7a1 reverts c5b81fe; bbf441c reverts 4d29ab0; …

   MED     2 incident-flagged changes in history
           2 commits matched incident keywords (latest 12 days ago:
           'hotfix: idempotency token regression').
           evidence: a3f4b2c, 7e22a04

   MED     2 invariants stated by past authors
             > Do not switch to async — v1 clients break.  (4d29ab0)
             > Important: keep the legacy header in place. (c5b81fe)

  → git show 9d2e7a1   to read the most relevant commit in full

Score interpretation:

Score Band What to do
75–100 HANDLE WITH CARE Stop. Read the linked commits first.
50–74 READ HISTORY FIRST At least skim the top signal.
25–49 WORTH A LOOK One thing might bite you. Glance.
0–24 NO FLAGS Quiet history — but read the diff anyway.

The killer use case: hand it to your AI editor

WhyCode is also an MCP server. Configure it in any MCP-aware editor or assistant, and the host LLM can pull a Risk Card before it edits any file.

{
  "mcpServers": {
    "whycode": { "command": "whycode", "args": ["mcp"] }
  }
}

Drop that snippet into your editor's MCP configuration file (location varies by editor — check your editor's MCP docs). Then in any chat:

"Refactor the refund flow."

A well-configured assistant will call get_risk_profile("src/payment/refund.py") first and read the warnings before it changes a line. Run whycode mcp -v during development to log every tool call to stderr so you can verify the integration is actually live.

Tools exposed:

  • get_risk_profile(path) — full Risk Card.
  • get_file_decisions(path, limit=5) — only the decision-flavoured signals (reverts, incidents, ghost keepers, invariant quotes).

Wire it into git, CI, and your editor

WhyCode is most useful when it shows up automatically in the moments you'd otherwise forget to look. The fast path:

whycode init

That installs two things:

  • .git/hooks/pre-commit — runs whycode diff --staged --fail-on handle before every commit. HANDLE WITH CARE files can't be touched without an explicit git commit --no-verify.
  • .github/workflows/whycode.yml — a GitHub Action that prints a risk-ranked table for every PR. Advisory by default (never blocks merging); append --fail-on history (or handle / look) to the diff line to turn it into a hard gate.

Tune the thresholds inside those two files for your repo. Re-run with whycode init --force to overwrite.

MCP server — see the next section.

Architecture (three layers, by design)

Layer What Network? API key?
1 Deterministic git facts (log, diffstat, revert pairs, author activity) no no
2 Heuristic signals (reverts, incidents, silence, ghost keeper, coupling, invariants, churn, newborn) no no
3 LLM polish (optional, opt-in, never on by default) yes yes

Layer 1 + Layer 2 produce the Risk Card you saw above. No model calls, no data leaving your machine. Layer 3 is reserved for natural-language summarisation of decisions and is strictly opt-in.

What this is NOT

  • ❌ Not a SaaS. No accounts, no cloud, no telemetry.
  • ❌ Not a code review bot. WhyCode reports — never prescribes.
  • ❌ Not a "what changed" tool. Plenty of those exist already.
  • ❌ Not language-specific. We read git history, not your AST.
  • ❌ Not a replacement for git blame. It's the briefing your senior would give you before you opened blame.

Developing

git clone https://github.com/fangshuor/WhyCode.git
cd WhyCode
pip install -e '.[dev,mcp]'
ruff check . && mypy src/whycode/ && pytest -q

See ENGINEERING.md for the engineering charter — the durable rules this repo is built under.

License

MIT. © 2026 Kevin.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

whycode_cli-0.2.4.tar.gz (45.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

whycode_cli-0.2.4-py3-none-any.whl (36.9 kB view details)

Uploaded Python 3

File details

Details for the file whycode_cli-0.2.4.tar.gz.

File metadata

  • Download URL: whycode_cli-0.2.4.tar.gz
  • Upload date:
  • Size: 45.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for whycode_cli-0.2.4.tar.gz
Algorithm Hash digest
SHA256 bdd25649bcc466a2b4b84b9333acac06bd74330ff7fcd3802dceee9647ec21ea
MD5 1839e7f1bdac3143b1d2f9f946ddb790
BLAKE2b-256 cff42f72cc7093e328a9cb01741b87352b9f00ed20334e448f9ee9017fb416c5

See more details on using hashes here.

File details

Details for the file whycode_cli-0.2.4-py3-none-any.whl.

File metadata

  • Download URL: whycode_cli-0.2.4-py3-none-any.whl
  • Upload date:
  • Size: 36.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for whycode_cli-0.2.4-py3-none-any.whl
Algorithm Hash digest
SHA256 feaa96e7a1b79912170928187ac642354c34906ed09629f5c458a6cfadf803c7
MD5 4595cc16076296c2f26c28bfc3c18ec1
BLAKE2b-256 48e80750e3efe100ed5a830ef19b3d378c160b18c7269315037a1a5985de5e9c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page