DEV Community

Wellington Filipe
Wellington Filipe

Posted on

I taught a local LLM to be lazy on my behalf (sloth-alias)

Hacktoberfest Open-Source AI Challenge Week 3: Slow and Steady Submission 🦥

This is my submission for the Hacktoberfest Open-Source AI Challenge: Week 3 (Slow and Steady).

What I built

sloth-alias reads a shell history file, finds the commands and command sequences you keep retyping, and turns them into aliases. A local open-weight model (any Ollama model, default gemma3:4b) does one job: it names each shortcut and describes it in a few words.

$ python3 sloth_alias.py sample_history.txt     # gemma3:4b via Ollama
  deploy    x3   saves   228 keystrokes  <- git push origin main && docker compose up -d --build && ...
  commit    x4   saves   196 keystrokes  <- git add -A && git commit -m wip && git push origin main
  commit2   x4   saves   152 keystrokes  <- git status && git add -A && git commit -m wip
Total lazy payoff: 576 keystrokes (~2.9 min at 40 wpm).
Enter fullscreen mode Exit fullscreen mode

Single file, Python standard library only, zero dependencies.

The sloth rules (design decisions)

  1. The model names, it never writes. The alias body is always assembled from your commands joined with &&. The model returns only {"name", "why"}. A prompt-injected or hallucinating model can't smuggle a command into your shell.
  2. Nothing installs itself. Output goes to sloth-aliases.sh. You read it, then you source it.
  3. No implicit history access. You pass the file explicitly. Your history never leaves your machine.
  4. Names are validated: regex check, no shell keywords, and no collision with anything already on your PATH.
  5. Degrades gracefully: model down, bad JSON, or a name that breaks the length rule (my first prompt got statusaddcommit back from a 4B model) falls back to deterministic initials. A one-shot example in the prompt fixed most of it. --no-llm works fully offline.

Why open matters here

Shell history is some of the most sensitive text on a developer machine: hostnames, paths, tokens pasted by accident. This is exactly the data you should not ship to a hosted API. With an open-weight model on localhost, the history stays on disk, it costs nothing per run, and I can swap models with one flag (--model).

The lazy payoff

On the bundled 26-line sample history, it finds 576 keystrokes of savings, about 3 minutes of typing, in one run. That sample is synthetic; on a real history the repeats compound.

Code

https://github.com/Tinhomagri/sloth-alias

What I'd do next

Overlap handling between sequences (right now status && add && commit and add && commit && push can both be suggested, as the commit2 name above shows), and a --explain mode that lets the model flag dangerous aliases such as ones containing rm -rf.

Top comments (0)