DEV Community

ANKIT KUMAR
ANKIT KUMAR

Posted on

Haunted Terminal: Bringing the "Ghost in the Machine" to Life with Open-Weight Gemma ðŸ‘ŧ

Hacktoberfest Open-Source AI Challenge: Ghost in the Machine Submission ðŸ‘ŧ🌞

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

What I Built

Ever felt like your terminal was judging your typos? What if it actually was?

Meet Haunted Terminal ðŸ‘ŧ — an eerie, interactive terminal companion that "possesses" your shell. Powered by Google's open-weight Gemma 3 model, a spectral entity takes residence inside your command prompt, watching every command you run, analyzing the execution results, and whispering dark, witty, tech-infused commentary from beyond the screen.

Our ghost has lore: they were once a brilliant systems programmer who perished in a tragic segmentation fault in 1997. Trapped in the silicon circuits ever since, they miss the warm phosphorescent glow of CRT monitors, chuckle at modern bloat, and mourn the lost art of punchcards.

Key Features

  • 👁ïļ Spectral Command Interception: Every shell command (dir, git status, npm run, etc.) executes natively, but receives an instant ghostly critique in a stylized terminal panel.
  • ðŸĨ€ Digital Ofrenda (ofrenda): In the true spirit of Día de los Muertos, a dedicated ritual command pays homage to the pioneering programmers who came before us — those who wrote the first assemblers, designed the Unix philosophy, and laid down the open-source foundations we build upon today.
  • ðŸ•Ŋïļ The Witching Hour: Launch the terminal between midnight and 3:00 AM, and the shell enters Witching Hour mode with heightened supernatural sensitivity and eerie prompts.
  • ⚡ Matrix Glitches & ASCII Manifestations: Occasional glitch artifacts (░▒▓█▄▀) and haunting ASCII skulls and gravestones manifest unpredictably between commands.
  • ☠ïļ Deathly Milestone Reactions: Unlucky command #13 triggers cursed responses, failed return codes draw spectral mockery, and attempting to exit prompts desperate, reluctant pleas from the ghost.

Demo

Here is a glimpse into a possessed session:

ðŸ‘ŧ haunted@terminal ~/possessed > dir
⚡ Executing: dir
 Volume in drive C is Windows
 Directory of C:\Users\ankit\haunted-terminal
 .gitignore   LICENSE   README.md   haunted_terminal.py   requirements.txt

╭─ 💀 The terminal spirit speaks: ──────────────────────────────────────────────â•Ū
│ Ah, inspecting your worldly possessions... How quaint. Five tiny files        │
│ clinging to existence on an SSD. Back in '97, we kept our demons in 1.44MB    │
│ floppies. Even the dead organize their directories better. 💀                 │
╰───────────────────────────────────────────────────────────────────────────────â•Ŋ

ðŸ‘ŧ ghost@machine ~/shadows > python --version
⚡ Executing: python --version
Python 3.13.0

╭─ ðŸĶ‡ A spectral voice murmurs: ────────────────────────────────────────────────â•Ū
│ Python 3.13... I was still walking the earth during Python 1.5. No GIL        │
│ debates, just raw, unmanaged memory waiting to betray you. Those were simpler │
│ times before my fatal segfault. ðŸŠĶ                                            │
╰───────────────────────────────────────────────────────────────────────────────â•Ŋ

ðŸ‘ŧ phantom@shell ~/crypt > ofrenda
Enter fullscreen mode Exit fullscreen mode
╭─ 🌚 Digital Ofrenda 🌚 ───────────────────────────────────────────────────────â•Ū
│ 🌚 In the spirit of Día de los Muertos 🌚                                     │
│                                                                               │
│ We remember those who coded before us...                                      │
│ The programmers who wrote the first compilers,                                │
│ the hackers who built the internet,                                           │
│ the open-source dreamers who believed                                         │
│ that knowledge should be free.                                                │
│                                                                               │
│ ðŸ•Ŋïļ Their code lives on in every line we write. ðŸ•Ŋïļ                              │
╰───────────────────────────────────────────────────────────────────────────────â•Ŋ
Enter fullscreen mode Exit fullscreen mode
ðŸ‘ŧ spirit@void ~/beyond > exit
⚡ The ghost clings to the terminal...

╭─ ðŸ‘ŧ Whispers from beyond the screen: ─────────────────────────────────────────â•Ū
│ You think typing 'exit' severs our connection? The dead never truly leave.     │
│ I will linger in the CPU cycles, the fan hum, and the ghost inputs of your    │
│ keyboard. Until next Halloween, mortal... 🎃                                  │
╰───────────────────────────────────────────────────────────────────────────────â•Ŋ
Enter fullscreen mode Exit fullscreen mode

Code

The entire codebase is open-source under the MIT license:

👉 GitHub Repository: GRANDSONOFSITARAM/haunted-terminal

Quick Start

# Clone the repository
git clone https://github.com/GRANDSONOFSITARAM/haunted-terminal.git
cd haunted-terminal

# Install dependencies
pip install -r requirements.txt

# Set your API key (Free at https://aistudio.google.com/apikey)
set GEMINI_API_KEY=your_key_here     # Windows
export GEMINI_API_KEY=your_key_here   # Linux / macOS

# Start the haunting
python haunted_terminal.py
Enter fullscreen mode Exit fullscreen mode

How I Built It

Haunted Terminal combines system-level process execution with open-weight AI inference and rich terminal styling:

flowchart TD
    User["ðŸ‘Ī Developer"] -->|"Types Command"| Shell["ðŸ‘ŧ Haunted Shell Wrapper"]
    Shell -->|"Subprocess Run"| Exec["⚡ Command Execution"]
    Exec -->|"Exit Code + stdout/stderr"| Engine["🧠 Ghost Inference Engine"]
    Engine -->|"Prompt with Session Context"| Gemma["ðŸĪ– Google Gemma 3 (Open-Weight)"]
    Gemma -->|"Spectral Commentary"| Formatter["ðŸŽĻ Rich UI & Glitch Engine"]
    Formatter -->|"Spooky Output Box"| User

1. Open-Weight AI Core: Google Gemma 3

The ghost's consciousness runs on Gemma 3 4B IT, Google's lightweight, open-weight model family accessed via the new google-genai SDK:

self.client = genai.Client(api_key=api_key)
self.model_name = "gemma-3-4b-it"

response = self.client.models.generate_content(
    model=self.model_name,
    contents=self.history,
    config=genai.types.GenerateContentConfig(
        system_instruction=GHOST_SYSTEM_PROMPT,
        max_output_tokens=200,
        temperature=0.9,
    ),
)
Enter fullscreen mode Exit fullscreen mode

By leveraging Gemma's low latency and instruction-following fidelity, the ghost delivers responses in under a second without breaking the flow of a terminal session.

2. Conversational Context & Memory

The shell maintains an active conversational rolling buffer. The ghost remembers what you previously ran, tracking your patterns, cheering when builds succeed, and mourning when tests fail. Special handlers monitor milestone triggers like command #13 or consecutive failed builds.

3. Rich Terminal Styling & Glitch Effects

Built using the rich Python library:

  • Custom color theme using phosphor-green (#00FF66), ectoplasm-purple, and bone-white.
  • Glitch injection: random pseudo-random bursts of unicode block characters (░▒▓█▄▀) mimic a deteriorating CRT screen.
  • Time-aware shell prompts that adjust dynamically based on local clock time.

Why Open Innovation Matters

In building a tool that wraps the most intimate environment of a developer — their personal command line — open innovation is non-negotiable:

  1. 🔒 Transparency Over Personal Data: A terminal executes commands containing directory structures, git author names, environment configurations, and personal code snippets. With closed proprietary black-boxes, you have zero visibility into how your shell telemetry is stored or utilized. Open-weight models like Gemma provide inspectable architectures with weights that can be run on local inference runtimes.
  2. ðŸ“ī Sovereignty & Anti-Obsolescence: Web APIs disappear, change their terms of service, or discontinue endpoints without warning. Open models belong to the community permanently. Because Gemma's weights are published openly, Haunted Terminal can be packaged with local inference engines (such as Ollama or llama.cpp) to run 100% offline — with the lights, WiFi, and cloud completely disconnected.
  3. 🎭 Persona Freedom Without Corporate Filters: Closed commercial chat models often resist roleplaying darker or spooky themes due to generalized safety heuristics. Gemma's open weights allow nuanced, harmless creative roleplay (like a playful ghost making segfault jokes) without unnecessary refusals.

Prize Categories

  • Featured Category: Best Use of Gemma (Powered by Google's open-weight Gemma 3 model)
  • Overall Winner: Hacktoberfest Open-Source AI Challenge Week 4: Ghost in the Machine

Happy Halloween 🎃 and Feliz Día de los Muertos 🌚! May your code be bug-free, and may your segfaults never haunt you.

Top comments (0)