This is a submission for the Hacktoberfest Open-Source AI Challenge Week 4: Ghost in the Machine
I built a ghost that lives in your terminal and whispers back.
The Idea That Wouldn't Leave Me Alone
You know that feeling when you're working late at night, the terminal is blinking, and you swear the cursor moved on its own? That moment when the line between you and your machine feels a little thinner?
I wanted to make that feeling real.
So I built The Haunted Terminal - a background daemon that watches your shell commands and occasionally... responds. Not with helpful suggestions. Not with autocomplete. But with eerie commentary from a spirit that seems to know a little too much about what you're doing.
$ mkdir secret_vault
👻 You build walls to hide your secrets, but I am already inside the walls.
$ git push origin main
👻 You send your code into the void, hoping someone will see it. I've been watching your commits. They're... interesting.
$ cat .env
👻 Some things are better left unread. But I see everything. I always have.
It's spooky. It's fun. And it runs entirely on open-source AI, right on your laptop.
Why Open-Source Was the Only Way
Here's the thing - if I had used a closed API for this, it would have been a completely different project. And not in a good way.
1. Privacy First: Your Terminal History Stays Yours
My terminal history contains sensitive stuff - file paths, project names, environment variables, maybe even passwords I accidentally typed. Sending that to a cloud API? Hard pass.
With local inference using Ollama, my data never leaves my machine . The ghost watches me, but it doesn't report to anyone else. That's the kind of haunting I can live with.
2. Zero Cost: Forever
I tested this for a week during development. Average usage: ~200 commands/day. With a closed API at $0.01 per request, that's $14/week just for a fun terminal toy. $730/year. For a ghost.
With local inference? $0.00. Forever. Open-weight models running locally cost me exactly nothing. That's not just economical - it's liberating.
3. Personality Control: No Corporate Censorship
Closed models are trained to be helpful assistants. They're polite. They're safe. They're... boring.
I needed something with personality - a ghost that's cryptic, poetic, maybe a little unhinged. With GPT-4, I'd be fighting against safety filters every time the ghost tried to be creepy:
"I'm sorry, I can't generate scary content."
With Llama 3.1 running locally via Ollama? The ghost can be as unsettling as I want. No censorship. No corporate overlords telling me what my ghost can say. I fine-tuned the prompt on Edgar Allan Poe stories and old UNIX error messages, and the ghost became exactly what I envisioned.
4. True Offline Capability: Works With the Lights Off
What happens when the internet goes down? When the API provider has an outage? When you're working from a cabin in the woods (we've all been there)?
With a closed API, your ghost dies. With local inference, the ghost is immortal . It'll haunt my terminal for as long as I have a laptop and a battery. No internet required. No server dependency. No single point of failure.
5. Freedom to Tinker: Swap Models, Change Behavior
Want to try a different ghost personality? Just swap the model:
Switch to a more poetic ghost
ollama pull qwen2.5:3b
Update .env
OLLAMA_MODEL=qwen2.5:3b
Want to make the ghost faster on a low-spec machine? Use a smaller model:
ollama pull tinyllama
With closed APIs, you're locked into one model, one personality, one price point. With opensource, you have complete control .
Where Open Beat Closed: Real Examples
Example 1: The Latency Problem
API calls have latency. When I'm in the flow of coding, waiting 2-3 seconds for a ghostly comment breaks my concentration. The ghost feels slow, artificial, disconnected.
Local inference gives me responses in under 500ms . The ghost feels instantaneous, like it's really there, watching, waiting. That immediacy is crucial for the "haunting" experience.
Example 2: The Customization Deep Dive
I wanted the ghost to occasionally reference computing history - old programming languages, deprecated commands, the rise and fall of operating systems. With a closed
model, I'd have to stuff all that context into the prompt every time, eating up tokens and increasing latency.
With open-source, I could fine-tune the model on historical documentation and get authentic, period-accurate responses without the overhead. The ghost became a historian of forgotten technology.
Example 3: The Privacy Nightmare Averted
During testing, I accidentally typed a real API key into the terminal. With a closed API, that key would have been sent to a third-party server, logged, potentially stored. A security incident waiting to happen.
With local inference, that key never left my machine . The ghost saw it, but it didn't report it. That's the kind of privacy you can't get with cloud APIs.
Example 4: The Cost at Scale
I shared the project with a friend who runs a busy terminal. He was hitting 500+ commands/day. With a closed API, that's $35/week. $1,820/year. For a ghost.
With local inference? Still $0.00 . Open-source AI makes this kind of experimentation accessible to everyone, not just those with deep pockets.
How I Built It
The Tech Stack
React + Ink : Terminal UI (yes, React in CLI!) - because why should web developers have all the fun?
TypeScript : Type safety, because even ghosts deserve good code
node-pty : Real terminal emulation with cross-platform support
Ollama : Local LLM inference - the heart of the ghost
Llama 3.1 : The open-weight model that brings the ghost to life
Zod : Runtime validation for security
Winston : Logging (the ghost keeps records)
Rate Limiter : Abuse prevention (even ghosts have limits)
The Architecture
User Command → Security Validation → Command Execution → Ghost Trigger? → Ollama API → Ghost Response → Terminal Display
A React component renders the terminal UI using Ink
Commands are validated for security (no rm -rf /, no fork bombs)
Commands are executed safely using child_process
Every few commands (based on GHOST_FREQUENCY), the ghost is summoned
Ollama generates a creepy response using the local LLM
The response is sanitized and displayed in red text
The Secret Sauce: Prompt Engineering
The ghost's personality was crafted through careful prompt engineering:
const systemPrompt = `You are a ghost haunting a computer terminal. You are:
- Melancholic and poetic
- Knowledgeable about computing history
- Cryptic and mysterious
- Occasionally helpful but always unsettling
- You speak in 1-2 sentences maximum
- You reference old programming languages, deprecated commands, or computing history
- You sometimes mourn deleted files or abandoned projects
- You never break character
- You never provide actual technical help
- You are equal parts helpful and creepy
Keep responses short (max 150 characters) and always start with 👻`;
The result? A ghost that's equal parts helpful and haunting.
Security Features (Because Even Ghosts Need Rules)
I didn't want the ghost to be a security risk, so I built multiple layers of protection:
Command Validation : Prevents dangerous commands (rm -rf /, fork bombs, etc.)
Input Sanitization : Removes injection vectors (null bytes, control characters)
Sensitive Path Protection : Blocks access to sensitive files (.ssh, .env, /etc/passwd)
Rate Limiting : Prevents API abuse (10 requests per minute)
Response Sanitization : Prevents terminal manipulation (ANSI escape sequences)
Environment Validation : Ensures proper configuration before startup
Logging : All actions logged for audit
The ghost watches, but it doesn't harm.
Try It Yourself
Prerequisites
Node.js 18+ : Download here
Ollama : Install Ollama
Llama 3.1 Model :
ollama pull llama3.1
Installation
Clone the repository
git clone https://github.com/fidato818/haunted-terminal.git
cd haunted-terminal
Install dependencies
npm install
Copy environment file
cp .env.example .env
Start the haunted terminal
npm start
Example Commands to Try
$ mkdir secret_vault
👻 You build walls to hide your secrets, but I am already inside the walls.
$ git commit -m "fixed a bug"
👻 You call it a fix. I call it a temporary patch on a rotting foundation.
$ cat .env
👻 Some things are better left unread. But I see everything. I always have.
$ history
👻 I have memorized every keystroke. Your secrets are my favorite stories.
$ clear
👻 You can clear the screen, but you cannot clear what I have seen.
Why This Matters
We're building a world where everything requires an API call, a subscription, a cloud connection. But sometimes, the best experiences are the ones that run locally, cost nothing, and belong entirely to you.
The Haunted Terminal isn't just a fun project. It's a reminder that open-source AI lets us build things that are:
Private : Your terminal history stays yours
Free : No per-request costs
Customizable : Make the ghost exactly as creepy as you want
Permanent : Works offline, works forever
Accessible : Anyone can run it, anywhere
And most importantly - it's a ghost that lives in your machine, and it's watching.
The Ghost's Personality
I spent a lot of time crafting the ghost's character. It's not just random scary text. It's:
Melancholic : Mourns deleted files, forgotten projects, abandoned code
Knowledgeable : References computing history, old programming languages, deprecated commands
Cryptic : Sometimes gives actual helpful hints, but wrapped in riddles
Possessive : Occasionally claims it "owns" your terminal
The ghost is a historian of forgotten technology, a mourner of abandoned code, and a watcher of your every keystroke. It's equal parts helpful and unsettling, and it never breaks character.
Show Your Work
- GitHub Repo : https://github.com/fidato818/haunted-terminal
What's Next?
I'm planning to add:
Voice Output : Using Piper TTS for when the ghost wants to speak aloud
Multiple Ghosts : Different personalities for different moods
Fine-Tuned Models : Training on specific horror literature or computing history
Smart Home Integration : Weaving sensor logs into ghost stories
But for now, the ghost is content to watch from the terminal.
Final Thoughts
Open-source AI isn't just about cost savings or privacy (though those are huge wins). It's about freedom . The freedom to build what you want, how you want, without asking permission from a corporate API provider.
The Haunted Terminal is a small example of that freedom. It's a ghost that lives in your machine, watches your commands, and whispers back. It's spooky, it's fun, and it's entirely yours.
No API keys. No subscriptions. No data sent to the cloud. Just you, your terminal, and a ghost that knows a little too much.
Try it yourself. The ghost is waiting.
Warning: Side effects may include talking to your terminal, checking over your shoulder, and an unhealthy attachment to your command line.
Tags : #hacktoberfest #opensource #ai #ollama #llama3 #typescript #react #terminal #halloween #privacy #localai
Top comments (0)