AI writes a lot of our code now, and much of it slips past us. When you come back to it later, you can't tell why it is there or what it is connected to.
Why Code tells you, in plain words.
How it works
Git history. It finds the commits that last changed the code (git blame), along with their messages, the other files changed in the same commit, and the diff.
Claude Code sessions (optional, off by default). If the code was written by Claude Code, it finds the prompt you gave and what Claude said right before writing it. That is usually the real "why".
A plain-words summary. It sends that evidence to Claude, which explains why the code exists, what it connects to, and anything to watch out for.
Where you see it
Hover over any line to see the commit behind it, with an Explain why link.
"Why?" above functions and classes (CodeLens) explains the whole block.
Why Code panel in the Explorer sidebar shows the full explanation, the original request and the commits.
Right-click → Why Code: Explain Why This Code Exists works on any selection.
AI setup
Why Code works without any AI and shows git history only. For plain-words explanations, it uses the first of these it finds:
Claude Code CLI. If claude is installed, it is used automatically. If VS Code can't find it, set whyCode.claudeCli.path to its full path (run which claude in a terminal).
Your Anthropic API key. Run Why Code: Set Anthropic API Key. The key is kept in VS Code's secret storage. You pay for your own usage.
Privacy
Session reading is off by default. Turn it on with whyCode.claudeSessions.enabled.
Session logs are read on your machine. Only the matched prompt, the code, and its git history are sent to the AI you set up.
Nothing is sent anywhere when whyCode.ai.provider is off.
Settings
Setting
Default
What it does
whyCode.ai.provider
auto
auto, claudeCli, apiKey or off
whyCode.ai.model
claude-opus-5-5
Model used with your API key
whyCode.claudeCli.path
claude
Path to the Claude Code CLI
whyCode.claudeSessions.enabled
false
Read local Claude Code sessions
whyCode.hover.enabled
true
Show the hover
whyCode.codeLens.enabled
true
Show "Why?" above functions
Development
npm install
npm run build # bundle to dist/
npm run typecheck
npm run package # build a .vsix
Press F5 in VS Code to open an Extension Development Host with the extension loaded.