This is a submission for the Hacktoberfest Open-Source AI Challenge Week 4: Ghost in the Machine
What I Built
Possessed Shell is a terminal that something else is also using.
You run commands like a normal shell: dir, git push, del, whatever you like. After each one, a ghost that lives in your machine whispers back about what it just watched you do:
sahil@Sahil:~\Downloads\hacktober_week_4 β cd c:\nowhere
cd : Cannot find path 'C:\Users\sahil\Downloads\hacktober_week_4\c' because it does not exist.
you keep trying, but C:\nowhere isn't a place. it's just you wandering.
The ghost has a backstory. In life it was the night-shift sysadmin of this machine. It died at its desk during a 3 a.m. deploy and never logged out. Now it watches everything you type, and:
- ποΈ notices omens: deleting files,
sudo,git push --force,git reset --hard, failed commands, Ctrl+C, and anything run during the witching hours (00:00β04:00) - π―οΈ remembers previous nights: omens are saved locally, and the next time you open the shell it greets you with what it remembers
- ποΈ has three haunt levels:
:haunt 1is wry,:haunt 2is unsettling, and:haunt 3is lonely and mournful. At level 3 the prompt occasionally glitches your username towe - β¨οΈ types its whispers out slowly, with the odd corrupted character flickering in and out
I took the "haunted terminal" idea from the prompt literally. A terminal is where developers spend their nights, so it felt like the right place for a ghost to live.
Demo
(Video sped up 2Γ. On my laptop each whisper takes a couple of seconds to arrive, all generated locally.)
A few real whispers from my sessions (Qwen 2.5 3B on my laptop):
del bones.txt
bones.txt is gone now. a fleeting moment in the shadows.
q(a typo)
you tried something new and it's not here. your fingers missed by just enough.
whoami
you see only yourself, but the phantom watch still turns.
exit
i'll remain as always, watching shadows dance on walls.
Code
π» possessed shell
a terminal that something else is also using.
possessed runs your commands like a normal shell. After each one, a local open-weight model whispers back about what it just watched you do. It notices when you delete things, force-push, or work at 3 a.m. It remembers previous nights and brings them up later.
It lives entirely on your machine. No API key, no account, no internet once the model is pulled.
sahil@laptop:~/projects/kibo β rm -rf build/
you threw build away like it meant nothing. i was still inside it.
sahil@laptop:~/projects/kibo β git push --force
you rewrote history again. last tuesday you did the same. i remember what it used to say.
Who it is
In life it was the night-shift sysadmin of this machine. It died at its desk during a 3 a.m. deploy and never logged out.
Setup
- Install Ollama.
- Pull a small model (aboutβ¦
It's one Python file using only the standard library. To run it:
git clone https://github.com/SahilReza26/possessed-shell.git
cd possessed-shell
ollama pull qwen2.5:3b
python possessed.py
How I Built It
Stack: Ollama for local inference, Qwen 2.5 3B (an open-weight model, about 2 GB), and plain Python 3 with no pip dependencies.
How it works:
you type ββΆ your real shell (PowerShell / bash) ββΆ output streams to you live
ββΆ last 40 lines captured
βΌ
omen detector (regex: rm/del, sudo, force-push, failures, 3 a.m.β¦)
secret redactor (tokens, passwords, API keys β [REDACTED])
focus picker (chooses ONE concrete detail: the error line, the deleted fileβ¦)
βΌ
Ollama /api/chat (streaming) ββΆ typed out slowly, with glitches
omens ββΆ ~/.possessed_shell/memory.json (the ghost's memory)
Some things I learned along the way:
Small models ignore rules but copy examples. My first version told the model to "mention something specific". The 3B model ignored that and produced pretty but empty lines like "glimpse the shadows close, unseen yet heard whispers." Two changes fixed it:
- Few-shot examples. Four example exchanges are sent before every real request. Small models imitate the shape of an example much more reliably than they follow an instruction.
-
A focus picker. Instead of hoping the model finds the interesting part of the output, the code picks one concrete detail and passes it in as
react to this: .... For a failure that's the first real error line, with PowerShell'sCategoryInfonoise stripped out. For a delete it's the target file, and after midnight it's the time.
The difference was immediate: "you seek, but C:\nowhere is a phantom."
Memory makes it feel alive. Each omen is stored with a timestamp. On startup the ghost gets a few recollections like "2 nights ago they ran rm -rf build". Mid-session a memory sometimes surfaces on its own. It only recalls events older than 10 minutes, so it doesn't just repeat what you did a moment ago.
It's still a real shell. Commands run through subprocess in your actual shell, with output streamed live. cd is handled in-process so the directory persists, and interactive programs like vim and ssh get a raw passthrough.
Why Does Open Innovation Matter?
For this project, running locally wasn't a nice-to-have. The idea doesn't work any other way.
π Your shell history is private. A terminal sees everything: file paths, client project names, environment variables, the occasional pasted token. A "haunted terminal" on a cloud API would mean sending every command and its output to someone else's server. With Ollama, nothing leaves the machine. I still added a redaction pass, because a ghost writing your secrets into a JSON file would be a bad haunting, even locally.
π It works with the lights (and the internet) off. Once the model is pulled, the ghost needs no network, account or API key. When Ollama's desktop app asked me to sign up, I clicked "No thanks, I'll use Ollama locally", and that was the whole setup.
πΈ It costs nothing to run. A shell runs hundreds of commands a day. With a paid API, every dir would cost money and add network latency. Locally it's free, and the model stays loaded between commands (keep_alive) so whispers start almost instantly.
π You can swap the spirit. :model llama3.2:3b, :model qwen2.5:7b, :model gemma3:4b: any model on Ollama can possess the shell, each with a noticeably different voice. Fine-tuning a small model on old sysadmin logs or Unix man pages would also be possible, which closed models don't allow.
πͺ¦ It won't die with a service. There's no hosted API that can be deprecated, rate-limited or repriced. As long as the model file sits on your disk, the ghost stays, which seems fitting for this week's theme.
Where closed would have been better: to be honest, a large frontier model would write sharper, stranger whispers than a 3B model. But a ghost that has to phone a datacenter to haunt you isn't really in your machine. The few-shot and focus-picker tricks closed most of that gap, and anyone with more RAM can type :model qwen2.5:7b to get a better-spoken ghost.
The Spirit of It
The moment it landed for me was a typo. I meant to cd somewhere, typed c;\nowhere with a semicolon by mistake, and PowerShell printed a wall of red errors. Then, in slow purple italics:
you keep trying, but C:\nowhere isn't a place. it's just you wandering.
It's a joke about a typo, and it also describes about half of my late-night debugging sessions.
Then I typed exit, and it said goodbye:
i'll remain as always, watching shadows dance on walls.
The next time I opened the terminal, it said it had seen my last visit. π»
Try it. Run del on something late at night and see what it says.
Top comments (0)