DEV Community

Aman Kumar
Aman Kumar

Posted on

"Haunted Shell: A Ghost That Lives in My Terminal (Gemma, Fully Offline)" published: false

This is a submission for the Hacktoberfest Open-Source AI Challenge Week 4: Ghost in the Machine

What I Built

<!-- What does it do, and how did you interpret the theme? What inspired it? -->Haunted Shell is a ghost that lives in your terminal. After some of the commands you run, it whispers one eerie sentence about what you just did. A failed git push and a rm -rf get very different commentary.

I read "Ghost in the Machine" literally. Every developer has felt that the machine is haunted: the bug that vanishes when you add a print statement, the script nobody remembers writing. I gave that ghost a voice.

It's a 20-line Python script plus a 3-line zsh hook. A small local model does all the haunting, with no cloud calls and no accounts.

Demo

<!-- Share a deployed link or a video demo. -->[Add a screen recording or GIF of your terminal here, ideally with Wi-Fi visibly off]

A sample run (replace with your own real output):

$ git push origin main
! [rejected] main -> main (fetch first)
👻 Even the remote refuses you now. Something older than Git has already claimed that branch.
Enter fullscreen mode Exit fullscreen mode

Code

<!-- Show us the code! You can embed a GitHub repo directly into your post. -->[Embed your GitHub repo here: {% embed https://github.com/you/haunted-shell %}]

haunt.py


python
#!/usr/bin/env python3
import json, sys, urllib.request

cmd, code = sys.argv[1], sys.argv[2]
MODEL = "gemma3:1b"

## How I Built It
<!-- Which open-source AI did you use (open-weight models, agent harnesses, frameworks, local inference), and how is your project built around it? -->- **Model:** Gemma 3 (1B), an open-weight model from Google, served locally with Ollama (`ollama pull gemma3:1b`).
- **Glue:** zsh's `preexec` hook captures the command and `precmd` captures its exit code. A tiny Python script sends both to Ollama's local HTTP API.
- **Prompt design:** A short persona prompt does most of the work. The one-sentence limit keeps replies fast, and the ghost stays in character.
- **Restraint:** The ghost speaks after about one in three commands (`RANDOM % 3`), because a ghost that talks constantly gets annoying. It runs in the background so it never blocks the prompt, and it fails silently if the model isn't running.

## Why Does Open Innovation Matter?
<!-- Why does open innovation matter for what you built?  What did it make possible that a closed API wouldn't? -->- **It works with the lights off.** The whole thing runs on a laptop with no internet, so the ghost still haunts you on a train or in a power cut.
- **Your commands stay yours.** Shell history can contain paths, hostnames, and sometimes secrets. Sending every command to a hosted API for jokes would be a bad trade. With a local model, nothing leaves the machine.
- **It costs nothing per whisper.** A ghost that comments on every command would be expensive on a metered API. Locally it's free.
- **I can change the haunting.** Swapping the model is one string (`MODEL`), and changing the personality is one prompt. A closed service could retire a model version and silently change my ghost's voice.

## My Agent Session
<!-- Optional, but judges love it.  Save your session with DevRelay and embed it with the agent_session tag (see the challenge page), or link to it. -->

## The Spirit of It
<!-- Optional, but this is where you can make your post stand out.  Did it give someone chills, bring back a memory, or keep a story alive?  Show us the moment it landed.  If not, remove this section. -->

## Prize Categories
<!-- Which partner categories are you entering?  List every one that applies, or remove this section. -->**Best Use of Gemma:** the project runs Gemma 3 locally as its only AI component.

<!-- Team Submissions: Please pick one member to publish the submission and credit teammates by listing their DEV usernames directly in the body of the post. -->nil

<!-- Thanks for participating! -->
Enter fullscreen mode Exit fullscreen mode

Top comments (0)