why
Explains command-line errors in plain language and suggests safe diagnostics.
why is a high-performance command-line utility written in pure Go. It answers the question every developer and system administrator asks: "Why did this command or service fail, what does it mean, and what safe check should I run next?"
why functions as an entirely local, deterministic knowledge base. It does not phone home, requires zero network connectivity, and contains no AI or cloud dependencies—delivering instant, reliable, hallucination-free explanations.
Key Features
- 100% Local & Offline: All 19 diagnostic domains (79+ core error rules) are embedded directly into a single static binary. Zero network calls, zero telemetry, zero AI.
- Log File & Stream Inspection (
why log): Scan application logs, system logs, or piped journalctl streams. Automatically aggregates distinct error patterns, reports frequencies, highlights line numbers, and provides consolidated diagnostic steps. - Deterministic Multi-Stage Matching: Evaluates canonical errors, captures dynamic variables via regex (files, ports, hostnames, usernames), resolves error codes (HTTP, Linux errno, exit codes, compiler codes), and falls back to fuzzy matching for typos.
- Safety-First Diagnostics: Only non-destructive inspection steps are suggested by default. Potentially dangerous actions are explicitly flagged.
whynever automatically executes commands. - Confidence Separation: Strictly delineates output into
CONFIRMED FROM INPUT,LIKELY CAUSE,POSSIBLE CAUSES, andNEXT DIAGNOSTIC STEP—no guesses masquerading as facts. - Pipe & Stdin Friendly: Pipe standard error or terminal logs directly into
why(command 2>&1 | why). - Structured JSON: Ready for scripting and pipeline automation (
why "connection refused" --jsonorwhy log app.log --json). - Extensible Configuration: Add internal team or proprietary error rules without recompilation using custom YAML rule directories.
- Agentic MCP Server: Built-in Model Context Protocol server (
why mcp) with tools, resources, prompts, and logging. Thewhy_diagnosetool drives an iterative coding loop — AI assistants like Claude Desktop, Cursor, and VS Code can diagnose errors, analyze code, run checks, and iterate to a fix. Still fully local, zero network.
Installation
macOS (Homebrew)
brew install m5rcel-vibecodes/tap/why
macOS (.pkg Installer)
Download why_X.Y.Z_darwin_arm64.pkg (Apple Silicon) or why_X.Y.Z_darwin_amd64.pkg (Intel) from Releases and double-click to install.
Debian / Ubuntu (.deb)
# Download from GitHub Releases
curl -LO https://github.com/m5rcel-vibecodes/why/releases/latest/download/why_2.0.0_linux_amd64.deb
sudo dpkg -i why_2.0.0_linux_amd64.deb
Fedora / RHEL (.rpm)
curl -LO https://github.com/m5rcel-vibecodes/why/releases/latest/download/why_2.0.0_linux_amd64.rpm
sudo rpm -i why_2.0.0_linux_amd64.rpm
Alpine Linux (.apk)
curl -LO https://github.com/m5rcel-vibecodes/why/releases/latest/download/why_2.0.0_linux_amd64.apk
sudo apk add --allow-untrusted why_2.0.0_linux_amd64.apk
Windows (.msi Installer)
Download why_X.Y.Z_windows_amd64.msi from Releases and run the installer. It adds why to your system PATH automatically.
Windows (.zip)
Download why_X.Y.Z_windows_amd64.zip from Releases, extract, and add the directory to your PATH.
Go Install
go install github.com/m5rcel-vibecodes/why/cmd/why@latest
go install github.com/m5rcel-vibecodes/why/cmd/why-mcp@latest
From Source
git clone https://github.com/m5rcel-vibecodes/why.git
cd why
make install
# Installs why and why-mcp to /usr/local/bin/
Pre-built Tarballs
Static binaries with CGO_ENABLED=0 are available as .tar.gz (Linux/macOS) and .zip (Windows) for all supported platforms from Releases. SHA-256 checksums are provided.
Usage
1. Direct Error Lookup
Explain an error directly:
why "permission denied"
why "connection refused"
why "command not found"
why "Host key verification failed"
why "CrashLoopBackOff"
Quoting is optional for quick lookups:
why git push rejected
why 404
why EACCES
why exit code 137
why error CS0246
2. Piping from Commands (stdin)
Capture and explain stderr in real time:
# Git push failure
git push origin main 2>&1 | why
# Docker startup issues
docker run -p 80:80 nginx 2>&1 | why
# Package manager lock errors
sudo apt update 2>&1 | why
Log Inspection (why log)
Inspect server, application, or system logs to identify, count, and explain all errors present in the file or stream:
# Scan a local log file
why log /var/log/nginx/error.log
why log app.log
# Stream and inspect logs from journalctl or docker
journalctl -u postgresql -n 200 | why log -
docker logs my-app 2>&1 | why log -
# Machine-readable JSON summary of all log errors
why log app.log --json
Example Log Inspection Output
$ why log /var/log/app.log
LOG INSPECTION REPORT
Source: /var/log/app.log
Summary:
• Scanned: 1,420 lines
• Total errors detected: 14 occurrences
• Distinct error types: 3
ERRORS DETECTED (ORDERED BY FREQUENCY):
[1] 10x connection refused (Networking)
Lines: 12, 18, 25, 40, 52, 60, 77, 89, 94, 105
Sample: dial tcp 127.0.0.1:5432: connect: connection refused
Likely Cause: No service is actively listening on the destination port, or a local host firewall actively rejected the packet.
Suggested Checks:
• nc -zv 127.0.0.1 5432
• sudo ss -tulpn | grep :5432
• ping -c 3 127.0.0.1
Caution: Binding a service to 0.0.0.0 exposes it to all available network interfaces including the public internet.
[2] 3x no space left on device (Linux)
Lines: 210, 214, 220
Sample: WARN disk write failed: no space left on device
Likely Cause: The target partition is 100% full, or all available inode numbers on the filesystem have been exhausted.
Suggested Checks:
• df -h
• df -i
• lsof +L1
Caution: Do not run rm -rf / or blindly delete files in /usr, /lib, or /boot.
[3] 1x 502 Bad Gateway (HTTP)
Lines: 432
Sample: [error] 1242#0: *8 connect() failed (111: Connection refused) while connecting to upstream
Likely Cause: The backend upstream application process crashed or is not running.
Suggested Checks:
• sudo tail -n 30 /var/log/nginx/error.log
• systemctl status <backend-service>
MCP Server (why mcp) — Agentic
why includes a built-in Model Context Protocol (MCP) server, allowing AI assistants like Claude Desktop, Cursor, VS Code Copilot, and other MCP-compatible clients to query the why knowledge base directly.
The MCP server runs over stdio (no network required) and is fully agentic — it exposes tools, resources, prompts, and logging to drive an iterative diagnose → gather evidence → refine → fix coding loop.
Capabilities
| Capability | What it provides |
|---|---|
| Tools | 4 tools including why_diagnose — a multi-step agentic diagnostic engine |
| Resources | Browsable knowledge base: categories, individual rules, diagnostic guides |
| Prompts | 4 workflow templates that guide AI assistants through diagnostic loops |
| Logging | Structured progress notifications during multi-step operations |
Tools
| Tool | Description |
|---|---|
why_explain |
Explain an error message or code. Returns the same structured diagnostic output as the CLI. |
why_inspect_log |
Scan log content for known error patterns and return an aggregated report. |
why_list_categories |
List all available knowledge base categories and their rule counts. |
why_diagnose |
Agentic diagnostic loop. Combines KB lookup + code context analysis + evidence correlation. Returns structured next_actions that drive iterative diagnosis. Call repeatedly with previous_diagnostics to refine. |
The Agentic Coding Loop
The why_diagnose tool creates an iterative diagnosis-fix cycle:
AI encounters error → calls why_diagnose(error, code_context)
↓
KB lookup + code analysis + action plan
↓
AI executes suggested diagnostic commands
↓
AI calls why_diagnose(error, previous_diagnostics=[...])
↓
Refined diagnosis with evidence correlation
↓
AI applies suggested fix → verifies → done
Each response includes structured _meta.why_diagnosis with:
findings— confirmed facts, code issues, correlated evidencenext_actions— what the AI should do next (run_command,read_file,apply_fix,call_why_diagnose)suggested_fix— description, command, and code hintssession_id— for tracking state across loop iterations
Resources (Browsable KB)
| Resource URI | Description |
|---|---|
why://categories |
Overview of all 19 domains with rule counts |
why://category/{name} |
All rules in a specific domain (e.g. why://category/linux) |
why://rule/{id} |
Full details of a single rule (e.g. why://rule/linux-permission-denied) |
why://guides/diagnostic-checklist |
Universal diagnostic checklist |
Prompts (Workflow Templates)
| Prompt | Description |
|---|---|
diagnose-error |
Full agentic diagnostic workflow with iterative loop guidance |
triage-log |
Log triage: scan, prioritize by severity, suggest remediation order |
explain-for-beginner |
ELI5-style explanation with no jargon |
security-audit |
Security-focused analysis: misconfigurations, credential exposure, hardening |
Starting the MCP Server
# Via subcommand
why mcp
# Alternative alias
why serve-mcp
# Via dedicated binary
why-mcp
Configuration Examples
Claude Desktop
Add to ~/Library/Application Support/Claude/claude_desktop_config.json (macOS) or %APPDATA%\Claude\claude_desktop_config.json (Windows):
{
"mcpServers": {
"why": {
"command": "why",
"args": ["mcp"]
}
}
}
Cursor
Add to .cursor/mcp.json in your project root or ~/.cursor/mcp.json globally:
{
"mcpServers": {
"why": {
"command": "why",
"args": ["mcp"]
}
}
}
VS Code (GitHub Copilot)
Add to .vscode/mcp.json in your workspace:
{
"servers": {
"why": {
"type": "stdio",
"command": "why",
"args": ["mcp"]
}
}
}
Using an Absolute Path
If why is not in your PATH, use the absolute path to the binary:
{
"mcpServers": {
"why": {
"command": "/usr/local/bin/why",
"args": ["mcp"]
}
}
}
Tool Schemas
why_diagnose (agentic)
{
"name": "why_diagnose",
"inputSchema": {
"type": "object",
"properties": {
"error": { "type": "string", "description": "Error message or code to diagnose" },
"code_context": { "type": "string", "description": "Relevant source code" },
"file_path": { "type": "string", "description": "Path to the file" },
"language": { "type": "string", "description": "Programming language (auto-detected if omitted)" },
"previous_diagnostics": { "type": "string", "description": "JSON array of diagnostic command outputs from prior loop iterations" },
"session_id": { "type": "string", "description": "Session ID to continue an existing diagnosis" }
},
"required": ["error"]
}
}
why_explain
{
"name": "why_explain",
"inputSchema": {
"type": "object",
"properties": {
"error": { "type": "string", "description": "Error message or code to explain" },
"format": { "type": "string", "description": "'text' or 'json'" }
},
"required": ["error"]
}
}
why_inspect_log
{
"name": "why_inspect_log",
"inputSchema": {
"type": "object",
"properties": {
"log_content": { "type": "string", "description": "Raw log text to inspect" },
"file_path": { "type": "string", "description": "Path to a log file" },
"format": { "type": "string", "description": "'text' or 'json'" }
}
}
}
why_list_categories
{
"name": "why_list_categories",
"inputSchema": { "type": "object", "properties": {} }
}
Example Error Output
Linux Permission Error with Parameter Extraction
$ why "bash: /var/log/nginx/access.log: Permission denied"
WHY DID THIS HAPPEN?
Error:
permission denied (Linux)
Usually means:
The process does not have sufficient permission to access the requested resource.
CONFIRMED FROM INPUT:
• Target resource: /var/log/nginx/access.log
• Operating system access check failed (EACCES / code 13)
LIKELY CAUSE:
The current user or process lacks read, write, or execute mode bits or ownership for the target path.
POSSIBLE CAUSES:
• Incorrect ownership (file or directory owned by root or another user)
• Incorrect file permissions (mode bits lack r/w/x for user or group)
• Filesystem restrictions (mounted read-only, noexec, or nosuid)
• Parent directory lacks execute (+x) permission for directory traversal
• Security policies (SELinux denying context, AppArmor profile restrictions)
CHECK / NEXT DIAGNOSTIC STEP:
ls -ld /var/log/nginx/access.log
Inspect file ownership and permission bits
id
Check your current user UID and assigned groups
namei -l /var/log/nginx/access.log
Trace permissions on every parent directory leading to the target
POTENTIAL SOLUTIONS:
• Grant execution or read/write permissions to the current user or group
chmod u+rx /var/log/nginx/access.log
• Change ownership if you own or manage the file
chown $USER:$USER /var/log/nginx/access.log
WARNING:
Do not blindly use sudo before determining the actual cause.
Never run chmod 777 or recursive chown -R on system directories.
Knowledge Database Coverage
why embeds rules across 19 core systems domains:
| Domain | Example Covered Errors |
|---|---|
| Linux | permission denied, command not found, no space left on device, read-only file system, device or resource busy, broken pipe, killed / oom, bad interpreter: No such file or directory, fork: retry: Resource temporarily unavailable |
| SSH | Host key verification failed, Permission denied (publickey), Permissions are too open (unprotected private key), Connection timed out |
| Git | non-fast-forward push rejected, merge conflict, remote permission denied, refusing to merge unrelated histories, local changes would be overwritten, RPC failed; HTTP 413, index.lock exists, not a git repository |
| Docker | cannot connect to the Docker daemon, port is already allocated, container exited code 137 (OOM), pull access denied |
| Kubernetes | CrashLoopBackOff, ImagePullBackOff / ErrImagePull, OOMKilled (pod limit exceeded) |
| Databases | PostgreSQL (password authentication failed, remaining connection slots reserved), MySQL (Access denied (1045), Cannot connect through socket (2002)), Redis (OOM command not allowed maxmemory) |
| systemd | Unit not found, status=203/EXEC, status=1/FAILURE, unit is masked, Start request repeated too quickly |
| OpenRC | service does not exist, service has crashed, status: crashed |
| Networking | connection refused (ECONNREFUSED), connection timed out (ETIMEDOUT), address already in use (EADDRINUSE), connection reset by peer |
| DNS | NXDOMAIN, SERVFAIL, temporary failure in name resolution (EAI_AGAIN), could not resolve host |
| HTTP | 400 Bad Request, 401 Unauthorized, 403 Forbidden, 404 Not Found, 429 Too Many Requests, 500 Internal Server Error, 502 Bad Gateway, 504 Gateway Timeout |
| TLS / SSL | certificate has expired, certificate signed by unknown authority, hostname mismatch |
| Package Managers | apt (dpkg lock), pacman (database lock), pip (externally-managed-environment), npm (ERESOLVE peer conflict) |
| Node.js | ERR_MODULE_NOT_FOUND, JavaScript heap out of memory, ERR_REQUIRE_ESM |
| Python | ModuleNotFoundError, IndentationError, RecursionError |
| Go | nil pointer dereference, all goroutines are asleep (deadlock), updates to go.mod needed, imported and not used |
| Rust | error[E0382] use of moved value, error[E0502] cannot borrow as mutable |
| Java / JVM | ClassNotFoundException / NoClassDefFoundError, OutOfMemoryError: Java heap space, UnsupportedClassVersionError |
| .NET | CS0246 type or namespace not found, System.NullReferenceException, MSB4019 imported project not found |
Custom Rules (Extensibility)
You can extend why with internal team or proprietary error rules without re-compiling.
Place YAML files into ~/.config/why/rules.d/*.yaml:
rules:
- id: internal-db-auth-failed
error: internal db authentication failure
category: Internal Database
meaning: The application failed to authenticate against the internal cluster.
exact_matches:
- "internal db auth failed"
patterns:
- '(?i)failed to authenticate user "(?P<user>[^"]+)" against cluster (?P<cluster>\S+)'
likely_cause: The database token expired or the role has not been provisioned in Vault.
possible_causes:
- Expired Vault lease token
- Database user credential rotated
diagnostic_steps:
- command: "vault token lookup"
description: "Check current Vault authentication status and remaining lease duration"
potential_solutions:
- description: "Renew database credentials using Vault"
command: "vault login"
warnings:
- "Never log plaintext database connection strings containing passwords."
Configuration
Configuration file location: ~/.config/why/config.yaml
# Directory containing custom rules
rules_dir: "~/.config/why/rules.d"
# Color mode: auto, always, never
color: "auto"
# Output JSON by default (default: false)
json: false
Environment Variables
| Variable | Description |
|---|---|
WHY_RULES_DIR |
Directory containing custom rule .yaml files |
WHY_COLOR |
Color mode (auto, always, never) |
WHY_JSON |
If set to 1 or true, outputs JSON format |
NO_COLOR |
Disables ANSI color escapes per no-color.org |
Contributing
- Fork and clone the repository.
- Ensure you have Go 1.22+ installed.
- Run test suite:
make test make lint - Submit a pull request.
License
MIT License. See LICENSE for details.