DEV Community

Sumeet Umbalkar
Sumeet Umbalkar

Posted on

Ghost Terminal: Zero-Latency Local AI Shell Possession

👻 Ghost Terminal (Shell Auto-Possessor)

GitHub Repository: github.com/sumeet57/ghostterminal


What I Built

Ghost Terminal is an offline, zero-latency CLI tool that runs locally on your machine, "possessing" standard terminal sessions. Whenever a command is executed—whether a successful file check, a failed build, or a force push—a lightweight open-weight LLM intercepts the execution context to inject eerie, thematic terminal commentary directly into standard output.


How It Works

  1. Local Model Runtime: Powered by ollama running an open-weight 3B parameter model (Qwen2.5-Coder-3B).
  2. Execution Hook: A lightweight Python wrapper traps shell commands, preserves original output streams, and passes execution status to the local LLM.
  3. Spectral Injection: The model processes the shell action in real time and streams a single-line spooky observation styled with ANSI color codes.
$ g git push origin main --force
Everything up-to-date
👻 [Ghost in the Machine]: You overwrite history so casually... but the past never truly stays buried.

Enter fullscreen mode Exit fullscreen mode

Why Open Innovation & Open Weights Matter

  • 100% Offline & Zero Latency: Running an open-weight model locally via Ollama means the daemon operates with zero network round-trips. It works completely with the lights (and internet) off.
  • Complete System Privacy: Terminal history frequently contains sensitive paths, repository structures, environment keys, and command flags. Sending shell logs to a third-party closed API is a security risk—open-weight models keep command telemetry strictly on local hardware.
  • Zero Operational Cost: Running locally allows high-frequency background inference on every single command with zero token costs or API rate limits.
  • No Cloud Lock-in: Open models ensure the software remains functional indefinitely without depending on external service uptime or changing API pricing tiers.

Tech Stack

  • LLM Engine: Ollama / Qwen2.5-Coder-3B (Open-Weight)
  • Core Logic: Python 3 (Zero external dependencies)
  • Shell Integration: Bash / Zsh alias hooks

Source Code (ghost.py)

import sys
import subprocess

if len(sys.argv) < 2:
    sys.exit(0)

command = " ".join(sys.argv[1:])
result = subprocess.run(command, shell=True)

prompt = f"System: You are an eerie ghost trapped inside a terminal. The user executed: '{command}'. Return a 1-sentence spooky commentary."

try:
    whisper = subprocess.run(
        ["ollama", "run", "qwen2.5-coder:3b", prompt],
        capture_output=True,
        text=True,
        timeout=5
    )
    if whisper.stdout.strip():
        print(f"\n\033[31m👻 [Ghost in the Machine]: {whisper.stdout.strip()}\033[0m")
except Exception:
    pass

Enter fullscreen mode Exit fullscreen mode

Setup Instructions

  1. Install and start Ollama, then pull the lightweight open model:
ollama run qwen2.5-coder:3b

Enter fullscreen mode Exit fullscreen mode
  1. Clone the repository and configure the alias in your .bashrc or .zshrc:
git clone https://github.com/sumeet57/ghostterminal.git
alias g="python3 ~/ghostterminal/ghost.py"

Enter fullscreen mode Exit fullscreen mode
  1. Run commands with the ghost wrapper:
g ls -la
g npm build

Enter fullscreen mode Exit fullscreen mode

Top comments (0)