get_why
Architectural-decision archaeology. Search decisions in natural language, anchor them to a file path, or pull the global decision-health dashboard. Falls back to git archaeology when no recorded decisions exist.
The decision intelligence layer in one tool. get_why answers
"why is this code shaped this way?", pulling from the architectural
decision records, the wiki, and (when nothing's recorded) the git
history itself. Four modes: NL search, path-anchored, target-aware,
and a no-arg health dashboard.
When to call
- Before architectural changes: check whether existing decisions govern what you're about to touch.
- During design reviews: pull the health dashboard to find stale decisions and ungoverned hotspots.
- On code with no recorded decisions: the git-archaeology fallback reconstructs the origin story from significant commits.
- Onboarding: call with no args for a tour of the codebase's recorded reasoning.
Parameters
| Parameter | Type | Description |
|---|---|---|
query | string | Natural-language question, a file/module path, or omit entirely for the health dashboard. |
targets | string[] | File paths to anchor the search; boosts decisions affecting them. |
repo | string | Repository alias. Pass "all" to search decisions across the whole workspace. |
Returns
The shape depends on which mode the call landed in.
Mode 1: Search (query is a question)
mode: "search",querydecisions: up to 8 merged hits (keyword + semantic, deduped)related_documentation: top 3 wiki pages mentioning the querytarget_context: (iftargetsprovided) per-target governing decisions, origin story, and git archaeology fallbackcode_rationale: (iftargetsprovided and no decisions matched) rationale comments mined live from the targets' sourceepisodes: dated facts recorded about the query (or the targets, when given), when any are bound
Mode 2: Path (query is a file path)
mode: "path",pathdecisions: governing decisions, best-first (active before proposed before deprecated/superseded), capped at 8.decisions_totalappears when more than 8 matchedorigin_story: when and why the file was created, by whom, recent change patterns. The top-ranked decision also carries astill_truesentence when git evidence can speak to whether it still holdsalignment: how well the file aligns with its governing decisions, scored over every matching record, not just the capped 8git_archaeology,code_rationale: fallback when no decisions govern the file.git_archaeologyreconstructs from git history;code_rationalemines rationale comments live from the source and appears whenever that mining finds something, independent of whatgit_archaeologyturned upepisodes: dated facts recorded about this file, when any are bound. Additive, not a fallback: present alongside governing decisions tootruncated,dropped_decisions: only if the response would have exceeded the transport budget; dropped content is recoverable via the_meta.omittedmarker like any other tool
Mode 3: Health dashboard (no query)
mode: "health"summary: human-readable countscounts: structured countsstale_decisions: decisions older than the files they governproposed_awaiting_review:status="proposed"recordsungoverned_hotspots: high-churn files with no decisionsconflicts: decisions that disagree over the same files
Mode 4: Workspace search (repo="all")
mode: "search",workspace: truedecisions: merged results across repos (capped at 15)
Example
get_why() # health dashboard
get_why("why is auth using JWT?") # search
get_why("src/auth/service.py") # path mode
get_why("why was caching added?", targets=["src/cache/service.py"])
get_why("redis integration", repo="all") # workspace searchThings worth knowing
- Path detection: natural language wins first. A query ending in
?, starting with a question word ("why", "how", ...), or reading as a sentence (4+ words including a question word) always routes to search (Mode 1). Otherwise, a query containing/or\or ending in a recognized code extension routes to path mode (Mode 2). - Natural-language scoring weights field matches:
title3.0×,decision/rationale2.0×,context1.5×, the decision's ownaffected_files1.5×,consequences/tags/evidence_file1.0×.targetsfiles contribute+5.0for an exact match,+3.0for a module-level match. - Git-archaeology fallback runs when no decisions exist for a file:
(1) significant commits from the file itself, (2) cross-file
references in other files' commits, (3) live
git log --followandgit log --grep(10-second timeout). - Staleness score is the fraction of a decision's
affected_fileswhoselast_commit_atis later than the decision'screated_at(a file named but untracked by git counts as changed too). It's the share of the decision's files that moved after the decision was recorded, not an age comparison against an "unchanged decision." - Workspace mode (
repo="all") uses keyword search across all repos' decisions, capped at 15 merged results. Full per-repo semantic federation is path-mode only.
Decisions are linked to graph nodes, so when the agent edits a file
get_why will surface the decisions that govern it without you having
to ask. This is what keeps the why in the codebase when the original
author leaves.
get_change_risk
Pre-merge defect risk for a whole commit or diff range, scored from the shape of the live diff, plus the tests that actually cover the changed lines and whether those files have been bug-fixed before.
get_dead_code
Tiered refactor plan for unused code. High/medium/low confidence findings with per-directory rollups, ownership hotspots, and safe-to-delete impact estimates. Pure graph + SQL, no LLM calls.