The Spectrum Dispatch News

technology

Researcher Fine-Tunes 360M Model to Simulate Terminal Behavior

A developer trained a language model to predict how a terminal screen changes with each keystroke, with no actual shell or filesystem behind it.

Researcher Fine-Tunes 360M Model to Simulate Terminal Behavior

A researcher has fine-tuned a 360-million-parameter language model to act as a terminal emulator, according to a project demonstration. Rather than running an actual shell or filesystem, the model predicts how the screen changes in response to each keystroke.

Researcher Fine-Tunes 360M Model to Simulate Terminal Behavior

The model, based on Qwen2.5-Coder-0.5B, was trained on terminal sessions recorded from real programs running in Docker containers. According to the source, it can create files, run vim and tmux, play snake, and generally remembers context from earlier commands—though errors can compound in longer sessions.

The technical approach treats a terminal as a grid of characters rather than a stream of text. Each keystroke goes in as raw bytes (letters as themselves, Enter as \r, Escape as 0x1b), and the model outputs which rows to rewrite and where the cursor should move. This differs from standard language models, which append tokens sequentially. The model uses a vocabulary of only 333 tokens: 256 for byte values, 64 for row positions, and a few special operations like COPY, which lets the model reference existing rows rather than regenerating them—reducing a full screen scroll from 3,000 tokens to just three per row.

For training data, the researcher generated 336,000 terminal episodes (roughly 2 billion tokens) by running real commands inside Docker, randomizing usernames, hostnames, directories, and terminal sizes to avoid overfitting. Sessions included typing errors at a 1.2% rate and tab completion patterns to simulate human input.

A key innovation was teaching the model to repair its own mistakes using a technique inspired by DAgger, an approach from imitation learning. When the model’s prediction diverged from the recorded ground truth, the training process constructed corrections showing how to fix errors on the next keystroke. This required the model to have seen any referenced information on earlier real screens or in user input—preventing it from learning to hallucinate new content. According to the source, this self-correction approach improved performance from 24/47 to 38/47 on a benchmark.

The model runs in a web browser using WebGPU (208 MB download) on desktop, though mobile performance is described as slow. The creator notes that typing “pythoon” reveals it’s not a real shell, since a genuine terminal would flag the typo.

Key facts

  • A 360M-parameter language model was fine-tuned to predict terminal screen changes from keystrokes with no actual shell behind it
  • The model was trained on 336,000 terminal episodes recorded from real Docker-based programs
  • Training included a self-correction technique inspired by DAgger that taught the model to repair its own mistakes
  • The model uses only 333 tokens total vocabulary, including 256 byte values and special operations like COPY for efficiency
  • It can create files, run vim and tmux, and play snake, though errors can compound in longer sessions

Sources

← All posts