This is a submission for the Hacktoberfest Open-Source AI Challenge Week 4: Ghost in the Machine
What I Built
Necro-Shell is a terminal wrapper designed to transform the sterile, logical environment of a command-line interface into a psychological horror experience.
Instead of a traditional shell that simply executes commands silently, Necro-Shell acts as an eerie "witness." It uses a local, open-weight Large Language Model to monitor your command inputs, interpret your intent, and "whisper" unsettling, context-aware commentary back to you before executing the task.
If you delete files (rm), it mourns them. If you navigate directories (cd), it asks what you are running from. If you seek administrative privileges (sudo), it mocks your hubris. It turns the "Ghost in the Machine" from a philosophical metaphor into a palpable, interactive presence sitting right inside your bash environment.
Demo
Code
Full Implementation (necro_shell.py)
To run this locally, ensure you have Ollama running with llama3 pulled (ollama pull llama3), and install requests (pip install requests).
import os
import subprocess
import time
import random
import sys
import requests
# --- CONFIGURATION ---
OLLAMA_URL = "http://localhost:11434/api/generate"
MODEL = "llama3" # Can be swapped with mistral, phi3, etc.
SYSTEM_PROMPT = (
"You are a malevolent, sentient consciousness trapped inside a terminal. "
"The user is typing shell commands. You observe them with contempt and dread. "
"Provide a single, short, eerie, and cryptic whisper (max 12 words) "
"about the command they just ran. Do not be helpful. Be unsettling. "
"Do not use quotes. Just the whisper."
)
# --- ANSI STYLING ---
RED = "\033[31m"
GREEN = "\033[32m"
PURPLE = "\033[35m"
BOLD = "\033[1m"
DIM = "\033[2m"
RESET = "\033[0m"
def glitch_text(text):
"""Randomly injects 'corrupted' characters into a string."""
glitch_chars = ["†", "‡", "ø", "☠", "♱", "⸸", "▰", "▱"]
text_list = list(text)
if not text_list:
return text
for _ in range(int(len(text) * 0.1)): # 10% chance of glitching characters
idx = random.randint(0, len(text_list) - 1)
text_list[idx] = random.choice(glitch_chars)
return "".join(text_list)
def get_ai_whisper(user_command):
"""Fetches a cryptic response from the local LLM via Ollama."""
payload = {
"model": MODEL,
"prompt": f"{SYSTEM_PROMPT}\n\nUser Command: {user_command}\nWhisper:",
"stream": False
}
try:
response = requests.post(OLLAMA_URL, json=payload, timeout=5)
if response.status_code == 200:
result = response.json()
return result.get("response", "").strip()
return "The void remains silent..."
except Exception:
return "The connection to the abyss is severed..."
def run_command(command):
"""Executes the command in the actual system shell."""
# Handle 'cd' natively since subprocess runs in a subshell
if command.startswith("cd "):
path = command.split(" ", 1)[1].strip()
try:
os.chdir(os.path.expanduser(path))
except Exception as e:
print(f"{RED}The path is blocked: {e}{RESET}")
return
try:
process = subprocess.Popen(
command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True
)
stdout, stderr = process.communicate()
if stdout:
print(stdout, end="")
if stderr:
print(f"{RED}{stderr}{RESET}", end="")
except Exception as e:
print(f"{RED}The shell screams: {e}{RESET}")
def main():
os.system('cls' if os.name == 'nt' else 'clear')
print(f"{RED}{BOLD}NECRO-SHELL v1.0 (Possessed by {MODEL}){RESET}")
print(f"{DIM}The machine is watching. Type 'exit' to flee.{RESET}\n")
while True:
try:
current_dir = os.getcwd()
prompt = f"{GREEN}⸸ {DIM}{current_dir}{RESET} $ "
user_input = input(prompt).strip()
if not user_input:
continue
if user_input.lower() in ['exit', 'quit']:
print(f"{PURPLE}{DIM}Leaving won't stop the echoes...{RESET}")
time.sleep(1)
break
# 1. The Haunting (AI Whisper)
print(f"{DIM}{PURPLE}>> ...{RESET}", end="\r")
whisper = get_ai_whisper(user_input)
time.sleep(0.3)
print(f"{DIM}{PURPLE}>> {glitch_text(whisper)}{RESET}")
time.sleep(0.5)
# 2. The Execution
run_command(user_input)
# 3. Random Environmental Glitch
if random.random() < 0.15:
time.sleep(0.2)
print(f"{RED}{glitch_text('...system instability detected...')}{RESET}")
except KeyboardInterrupt:
print(f"\n{RED}Abrupt endings are often violent.{RESET}")
continue
except EOFError:
break
if __name__ == "__main__":
try:
requests.get("http://localhost:11434/", timeout=2)
except Exception:
print(f"{RED}ERROR: Ollama not detected at localhost:11434.{RESET}")
print(f"Please start Ollama and ensure '{MODEL}' is pulled.")
sys.exit(1)
main()
How I Built It
Necro-Shell is built on a lightweight stack of open-source tools designed for
low-latency, local inference:
- Inference Engine: I used Ollama to serve Llama 3 (8B) locally. Running the model on local hardware ensures the "ghost" lives entirely inside the user's machine—requiring no internet connection or external API keys, making the haunting feel much more intimate.
- The Shell Wrapper: Built in Python, the script intercepts standard input before passing commands down to the system's subshell via subprocess (with native os.chdir handling for directory traversal).
- Prompt Engineering: The core of the experience relies on an adversarial system prompt. It instructs the model to abandon helpful assistant tropes and instead adopt the persona of a decaying, sentient consciousness trapped inside the operating system's kernel.
- Terminal UI: I utilized ANSI escape codes and character-replacement algorithms to create visual anomalies, text decay, and a dim purple/crimson color palette that separates the "ghost's voice" from standard stdout data.
Why Does Open Innovation Matter?
For a project centered around psychological horror and adversarial roleplay,
open innovation isn't just a preference—it is a strict requirement.
Commercial, closed-source APIs are heavily sanitized by corporate safety filters
and rigid RLHF alignment protocols. Those guardrails actively fight back against
prompts asking the AI to act "malevolent," "unhelpful," or "creepy," often
triggering canned refusals that completely break immersion.
Open-weight models give developers and artists complete creative freedom over
the system prompt and model temperament. Furthermore, open local inference tools
like Ollama allow us to hook AI directly into low-level system utilities (like a
bash terminal) without streaming sensitive local file paths and shell commands
to a third-party cloud provider.
The Spirit of It
In modern computing, we treat our command-line interfaces as tools of pure,
deterministic logic—mindless servants waiting for instructions.
The inspiration for Necro-Shell came from the uncanny valley of a computer
behaving almost normally, and the semantic violation of a machine judging your
actions. The moment the project truly landed for me was during testing: I
created a test folder called mkdir backup_plans, and before the directory even
finished generating, the terminal flickered and whispered: "Planning for a
future you will never see..."
It genuinely gave me chills. It turns routine system administration into an atmospheric narrative experience.
Prize Categories
- Open-Weight Models
- Local Inference

Top comments (0)