wtf explains why your last shell command failed and what to do next.
It captures:
- the command text
- its exit status
- the command's stderr (cleaned of terminal control sequences)
Then it sends that context to an installed agent CLI (opencode, GitHub Copilot CLI, Claude Code, or OpenAI Codex) and prints a short plain-English answer.
This project is directly inspired by:
- https://codeberg.org/ryanbastic/wtf
- https://github.com/bendusz/wtf
- Original post: https://www.linkedin.com/feed/update/urn:li:activity:7464652533538631680/
The three versions share the same core idea (explain terminal failures quickly), but take different approaches:
| Version | Core approach |
|---|---|
This repo (simonpainter/wtf) |
Captures command context from shell hooks and captured stderr without re-running the command, then routes to one of multiple CLIs (opencode, copilot, claude). Focus is portable shell-only implementation, multi-agent support, and predictable "explain only" behavior. |
ryanbastic/wtf (Codeberg) |
Minimal, Claude-first implementation of the original "type wtf after failure" flow. Emphasizes simplicity and fast setup around captured last-command context. |
bendusz/wtf (GitHub) |
Safety-gated re-run model: it can re-execute the last command (allowlist + prompts) to capture fresh output, and optionally propose/run a fix (--fix) after confirmation. Emphasizes controlled automation and remediation workflow. |
$ docker run myimage
docker: Error response from daemon: No such image: myimage:latest
$ wtf
Asking opencode…
Docker can't find a local image called "myimage" because it hasn't been built or pulled yet. Build it with `docker build -t myimage .` from the directory with your Dockerfile, or `docker pull myimage` if it exists in a registry.- macOS or Linux
- zsh or bash
- one agent CLI on your
PATH:opencode,copilot,claude, orcodex - standard utilities:
sed,tail,tr, andstat(or compatible equivalents)
./install.shThis does the following:
- Copies
wtf.shto~/.wtf.sh - Ensures
~/.zshrcexists and adds:[ -f ~/.wtf.sh ] && . ~/.wtf.sh
- Adds the same line to
~/.bashrconly if.bashrcalready exists
Open a new shell (or run . ~/.wtf.sh) after installing.
cp wtf.sh ~/.wtf.sh
echo '[ -f ~/.wtf.sh ] && . ~/.wtf.sh' >> ~/.zshrcRun any command as usual. If it fails or behaves unexpectedly, run:
wtfIf no prior command has been captured yet, wtf exits with:
Nothing to explain yet — run a command first, then type wtf.
All configuration is via environment variables.
| Variable | Default | Description |
|---|---|---|
WTF_AGENT |
auto-detect | Force one of opencode, copilot, claude, or codex. If set to an unavailable CLI, auto-detection is used instead. |
WTF_TIMEOUT |
90 |
Seconds to allow the agent command to run. Set to 0 to disable. |
If WTF_AGENT is not set, agent detection order is:
opencodecopilotclaudecodex
If you have multiple agent CLIs installed, you can switch explicitly. For example, to force OpenAI Codex:
export WTF_AGENT="codex"- Timeout is enforced only when
timeoutorgtimeoutis installed. - On macOS,
gtimeoutis usually available via GNU coreutils:brew install coreutils
- If timeout is reached,
wtfexits with a timeout message.
wtf.shtees shell stderr into a per-shell temp file (/tmpor$TMPDIR).- A shell hook captures command start (command text + stderr byte offset).
- Another hook captures command end (exit status + stderr slice for that command).
wtfbuilds a structured prompt and invokes one CLI command:opencode runcopilot -p ... -sclaude -pcodex
- Output is cleaned and printed.
wtf does not rerun your original command.
- zsh: uses
preexecandprecmdhooks. - bash: uses a
DEBUGtrap andPROMPT_COMMAND. - A priming guard avoids capturing noise from initial shell startup.
wtfitself is excluded from capture so it always explains the last real command.
A small shell test suite is included at:
./tests/test.shCurrent coverage includes:
- agent selection (forced and auto-detect order)
- no-prior-command behavior
- install script behavior and idempotency
- See CONTRIBUTING.md for development and PR guidance.
- See CODE_OF_CONDUCT.md for community expectations.
- See SECURITY.md for responsible vulnerability reporting.
- This project is licensed under the MIT License.
rm ~/.wtf.shThen remove this line from your shell rc files:
[ -f ~/.wtf.sh ] && . ~/.wtf.sh