Haunted Terminal:以本機 Gemma 為 PowerShell 指令加入幽靈低語
Haunted Terminal
Haunted Terminal 是一個 PowerShell 腳本,使用 Ollama 本機執行的 Gemma,在每次指令執行後低語評論;預設模型為 gemma3:4b。指令失敗時會顯示血滴效果,Ollama 無法回應時則以預設文字代替;指令和輸出只會傳送至 127.0.0.1。
This is a submission for the Hacktoberfest Open-Source AI Challenge Week 4: Ghost in the Machine
What I Built
A haunted terminal. Haunted.ps1 is a single PowerShell file that possesses your real shell. After every command you run, a ghost whispers a short, eerie comment about what you just did. It's written by a local Gemma model and typed onto the screen one character at a time, like breath fogging a window.
I took "Ghost in the Machine" literally: the machine is your terminal, and the ghost is a model living inside it. Failed commands get a blood drip and a mournful whisper. Successful ones get something quieter and creepier. The prompt becomes ☠ ~\path ›, and each new session opens with a small ghost and a few drips of blood. In Windows Terminal, the window becomes frosted glass.
It's one file with three modes, so it's easy to try and easy to remove:
-
. .\Haunted.ps1haunts the current tab only, andunhauntundoes it -
. .\Haunted.ps1 -Installmakes every new tab haunted -
. .\Haunted.ps1 -Uninstallremoves everything it added
Demo
A walkthrough of one session, from loading the script to a failed command.
1. Loading the script
I run . .\Haunted.ps1. The terminal clears, a small ghost appears with blood dripping from it, and the prompt changes to ☠ ~\path ›. Nothing else is installed or changed, and unhaunt undoes it.
2. The ghost speaks
After each command, a whisper is typed onto the screen under it. These two replies are marked (echo). That is the offline fallback: when Ollama doesn't answer, the ghost leaves a canned line instead of going silent.
3. A normal command
ls runs as usual, and the ghost comments on it afterward. The output is untouched, and the whisper appears below it.
4. A command that fails
I typed ls -lf out of Linux habit, and PowerShell rejected it. A failed command makes the glass "bleed": a blood-red line and drip are drawn before the ghost speaks, with a more mournful whisper.
A live Gemma whisper. This one is real, not the (echo) fallback. After the ghost's entrance, I ran git --version. The output is untouched: git version 2.55.0.windows.5. Then, the local Gemma model replied by reacting to the actual output, mentioning the version number, "2.55.0".
Code
How I Built It
-
Model: Gemma (
gemma3:4bby default, or any tag via$env:HAUNT_MODELorhaunt model <name>), served locally by Ollama. -
The hook: I replace PowerShell's
promptfunction. Each time it runs, it checks whether a new command appeared in history, then wakes the ghost. - What the ghost sees: the command, whether it succeeded or failed, and the last 1200 characters of its output. PowerShell doesn't keep output after a command, so the script reads it from a private temporary transcript. That file is deleted when the session ends.
-
Streaming: the reply comes from Ollama's streaming
/api/chatendpoint. Each token is printed the moment it arrives, with a tiny per-character delay. This removes most of the waiting and gives the "breathing on glass" effect. - Prompting: the system prompt makes the ghost lowercase, intimate and brief (under 28 words), tied to the actual command and its output, and forbids advice, so it whispers instead of helping.
-
Look: 24-bit ANSI colours for the prompt, syntax highlighting and whispers. The glass theme is a Windows Terminal JSON fragment, so my own
settings.jsonis never edited. -
Safe to remove:
-Installadds one marked line to$PROFILEplus the fragment file.-Uninstalldeletes exactly those two things. -
Offline fallback: if Ollama isn't running, the ghost leaves a canned echo marked
(echo)instead of going silent.
Known limits: full-screen programs such as vim or ssh write straight to the console, so the ghost sees only the command, not the output. The glass effect only works in Windows Terminal.
Why Does Open Innovation Matter?
-
Your shell history is private. Commands and output can contain paths, hostnames, tokens and project names. Here they go to
127.0.0.1and nowhere else. I wouldn't want to stream every keystroke of my terminal to a hosted API for a joke. - It works with the internet off. A ghost that lives in your machine should keep talking when the Wi-Fi dies.
-
Swappable and tunable. Changing the model is one command (
haunt model gemma3:12b). The personality is a plain system prompt anyone can change, whether to make the ghost a grumpy sysadmin or an ancient programming language. - Free to run. Every command gets a whisper. With a hosted model that would be a metered bill for a Halloween joke. Locally it costs electricity.
- It won't disappear. Open weights plus a plain script mean this keeps working years from now, even if an API gets deprecated or repriced.
Prize Categories
- Best Use of Gemma:
來源:DEV Community · dev.to





