DEV Community

Syed Anas Mohiuddin
Syed Anas Mohiuddin

Posted on

ai-fix: when a command fails, one word fixes it

I kept alt-tabbing to ChatGPT, pasting the error, reading the fix, coming back to the terminal. Same 5 errors. 50 times a year.

So I built ai-fix.

Demo

$ python app.py
ModuleNotFoundError: No module named 'uvicorn'

$ ai-fix
✗ Failed: No module named 'uvicorn'
Fix (high confidence): uvicorn is not installed.
  → pip install uvicorn
Apply fix? [Y/n]: y
✓ Fixed! Command succeeded.
Enter fullscreen mode Exit fullscreen mode

Install

pip install ai-fix
export ANTHROPIC_API_KEY=sk-ant-...
Enter fullscreen mode Exit fullscreen mode

That's it. Now just type ai-fix after any failed command.

How it works

  1. Reads your last command from zsh/bash/fish history
  2. Re-runs it to capture the full error
  3. Sends error + context (OS, Python/Node version, project files present) to Claude Haiku
  4. Gets back exact fix commands — no prose, no explanation to decode
  5. Applies them, re-runs your original command to confirm

What it fixes

  • ModuleNotFoundErrorpip install
  • Permission denied → chmod +x
  • Port already in use → lsof -ti:PORT | xargs kill -9
  • Git push rejected → git pull --rebase
  • Docker not running → open -a Docker
  • npm/cargo/go build failures

Cost

~$0.0003 per fix (Claude Haiku). You'd need 3,000 fixes to spend $1.

Falls back to GPT-4o-mini if you have OPENAI_API_KEY instead.

Also works as a prefix

ai-fix npm run build   # runs it, fixes it if it fails
ai-fix -y python app.py  # skip confirmation
ai-fix --dry-run cargo build  # see fix without applying
Enter fullscreen mode Exit fullscreen mode

GitHub: https://github.com/anasmohiuddinsyed-bit/ai-fix

MIT license. Would love feedback on the confidence scoring.

Top comments (0)