why helps you understand what a terminal command will do, what went wrong, and what to try next.
It can:
- run a command and explain failures
- simulate risky commands before they change anything
- stream live logs for long-running commands
- use OpenAI or Ollama for AI explanations
- read local code context when an error points into your project
Global install:
npm install -g @0xprathamesh/why-cliLocal development:
npm install
npm run build
npm linkAfter that, the why command is available from any folder.
Package name on npm:
@0xprathamesh/why-cli
Repository name on GitHub:
why
The install package is scoped, but the CLI command is still just:
whyBuild the image:
docker build -t why-cli .Show help from the container:
docker run --rm why-cli --helpRun a command through why inside the container:
docker run --rm why-cli --simulate -- git push origin mainIf you want to use your current project inside the container:
docker run --rm -it -v "$PWD:/workspace" -w /workspace why-cli -- npm run buildIf you want AI config inside Docker, pass env values or an env file:
docker run --rm --env-file .env why-cli --doctorRun a normal command:
why -- npm run buildSimulate a risky command:
why --simulate -- git push origin mainRun a command for real even if auto mode would simulate it:
why --run -- git initCheck AI setup:
why --doctorInteractive setup:
why --setupFor every command, why-cli goes through this pipeline:
command -> classify -> risk -> simulate/run -> analyze -> explain
That means:
- safe read-only commands usually run in
automode - risky state-changing commands are usually simulated in
automode - failures are summarized in plain language
- if AI is configured,
why-cliadds an AI explanation on top
why-cli has 3 execution modes.
Default mode.
- runs read-only commands
- simulates risky commands
Example:
why npm run build
why git init
why rm test.txtRuns the command for real.
why --run -- git init
why --run -- rm test.txtNever runs the real command. It only does a safe preview when supported.
why --simulate -- git add .
why --simulate -- npm install express
why --simulate -- mkdir demo-folderIf you run:
why git inityou may see simulation output instead of actual execution. That is expected in auto mode.
If you want the real command to run, use:
why --run -- git initYou can configure AI once and stop passing keys or model flags every time.
Recommended:
why --setupThis writes config to:
~/.config/why-cli/.envYou can also create that file manually.
Example:
WHY_PROVIDER=ollama
OPENAI_API_KEY=
OPENAI_MODEL=gpt-4.1
OPENAI_BASE_URL=https://api.openai.com/v1
OLLAMA_HOST=http://127.0.0.1:11434
OLLAMA_MODEL=gemma3:4b
WHY_SKILL=debug,fixSupported config locations:
.env.localin the current folder.envin the current folder.env.localin parent folders.envin parent folders~/.config/why-cli/.env~/.env
Check provider health:
why --doctorSupported providers:
autoopenaiollamanone
Examples:
why --provider openai --explain -- npm test
why --provider ollama --model gemma3:4b -- npm run build
why --provider none -- npm startRun commands:
why -- npm run build
why -- npm start
why -- python3 script.py
why node -v
why npm -v
why cat README.mdSimulate commands:
why --simulate -- git add .
why --simulate -- git commit -m "test"
why --simulate -- git push
why --simulate -- npm install
why --simulate -- npm install express
why --simulate -- npm publish
why --simulate -- rm test.txt
why --simulate -- mkdir test-folder
why --simulate -- touch demo.txtRun risky commands for real:
why --run -- git init
why --run -- git commit -m "ship"
why --run -- npm publishMissing package:
why --simulate -- npm install some-invalid-package-xyzMissing file:
why --simulate -- rm non-existing-file
why --simulate -- git add non-existing-fileExisting directory:
mkdir existing-folder
why --simulate -- mkdir existing-folderWrong Git push target:
why --simulate -- git push origin wrong-branchBad build:
why --explain -- npm run buildwhy-cli can stream logs for servers, watchers, and dev processes.
Examples:
why -- npm start
why --stream -- npm run dev
why --no-stream -- npm run buildUse:
--streamto force live logs--no-streamto wait until the command exitsCtrl+Cto stop the child process
When an error points to files in your project, why-cli can read local code context and include it in the explanation.
That helps with cases like:
- TypeScript build errors
- import or module resolution failures
- stack traces with file paths
- runtime failures pointing into your app code
This is most useful when you run why inside the project that failed.
Skills shape how the AI explains the result.
Built-in skills:
debugteachfixtestssecurityperf
Examples:
why --skill debug --skill fix -- npm run build
why --provider ollama --skill teach -- python3 script.py
why --list-skillsYou can also set default skills in your config:
WHY_SKILL=debug,fix-h, --help
-v, --version
-s, --silent
--json
--no-color
-r, --raw
-e, --explain
--mode <auto|run|simulate>
--simulate
--run
--execute
--provider <auto|none|openai|ollama>
--model <name>
--cwd <path>
--timeout <ms>
--skill <name>
--list-skills
--doctor
--setup
--stream
--no-stream
--api-key <key>
--api-key-env <name>
--openai-base-url <url>
--ollama-host <url>
- Shell builtins like
cdcannot change your parent shell session throughwhy-cli. - In
automode, risky commands are often simulated instead of executed. - If a command starts with flags that confuse parsing, use
--before the command.
Example:
why -- node -v
why --simulate -- git statusGitHub Actions is included.
CI workflow:
- file:
.github/workflows/ci.yml - runs on pushes to
mainand on pull requests - tests Node.js
18and20 - runs
npm ci - runs
npm run build - runs
npm pack --dry-run
Release workflow:
- file:
.github/workflows/release.yml - runs on tags like
v1.1.0 - builds the project
- publishes to npm