Skip to content

MattX23/wtf-terminal

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

⚡ wtf

A zsh plugin that explains the last failed terminal command using Claude AI.

wtf demo

$ npm install
npm error code ENOENT
npm error syscall open
npm error path /Users/you/package.json

$ wtf

  ⚡ wtf  npm install  (exit 1)

  There's no package.json in the current directory, so npm has nothing to
  install. Either navigate to your project root with cd, or run npm init
  to create a new package.

Install

One-liner:

curl -fsSL https://raw.githubusercontent.com/MattX23/wtf-terminal/main/install.sh | sh
source ~/.zshrc

Or clone:

git clone https://github.com/MattX23/wtf-terminal.git
cd wtf-terminal && sh install.sh
source ~/.zshrc

Or manually — add to your ~/.zshrc:

source "/path/to/wtf-terminal/wtf.zsh"

Setup

wtf needs a way to reach Claude. It checks in this order:

Option 1 — Anthropic API key (any Claude plan)

export ANTHROPIC_API_KEY="sk-ant-..."

Add that line to your ~/.zshrc to make it permanent. Get a key at console.anthropic.com.

Uses claude-haiku-4-5 with streaming, so responses appear immediately.

Option 2 — Claude Code CLI (Pro subscription, no API key needed)

npm install -g @anthropic-ai/claude-code
claude   # log in once

If ANTHROPIC_API_KEY is not set and claude is in your PATH, wtf routes through the Claude Code CLI automatically.

If neither is available, wtf prints a setup guide instead of an error.


Usage

Run any command. If it fails, type wtf:

git push origin my-branch
wtf

Aliases:

why          # same as wtf
wtf why      # also works

Flags:

wtf --verbose   # includes recent history, working directory, and OS info
wtf --help      # show usage

How it works

wtf hooks into zsh using preexec and precmd:

  1. preexec — fires before every command. Records the command string and redirects stderr through tee so output still appears in your terminal and gets saved to a temp file.

  2. precmd — fires after every command. Captures the exit code and restores stderr.

  3. wtf — reads the saved command, exit code, and stderr. Builds a prompt and sends it to Claude. Streams the response directly to your terminal.

capture failed command + stderr
             ↓
        build prompt
             ↓
  _wtf_send_to_claude()    ← only this differs by transport
             ↓
   format and print response

Everything is contained in a single .zsh file with no dependencies beyond curl and standard macOS developer tooling.


Requirements

  • zsh 5.3+ — anonymous fd syntax ({fd}>&2) used for stderr capture requires 5.3 or later. macOS ships with 5.9; check yours with zsh --version.
  • macOS or Linux
  • curl — for the API key transport path
  • Claude Code CLI (claude) — only needed for the Pro/no-key path

Contributing

git clone https://github.com/MattX23/wtf-terminal.git
cd wtf-terminal

Run the tests (no API key required — all tests use mocked transports):

zsh tests/run.zsh

Output is TAP-compatible. All 47 tests should pass.

Regenerate the demo gif (requires vhs):

vhs demo.tape

The recording uses demo_env.zsh — a scripted simulation of wtf's output — so no API key is needed to regenerate it either.


Companion tools

wtf is part of a small collection of zsh terminal tools:

  • cmdwatch — notices repeated mistyped commands and offers to create aliases for them

Both tools share the same ⚡ personality and hook pattern, and can be sourced together in your .zshrc.


License

MIT — see LICENSE.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages