2026-11-26 15:49 UTC

WorldTUI: a 360M model simulates a terminal locally

state: watchingheat: lowuncertainty: mediumrelevance: mediumworld-models terminal-simulation local-inferenceSimon Edwardsson

What is this?

Simon Edwardsson’s WorldTUI is a browser demo of a fine-tuned Qwen2.5-Coder model, reduced to about 360M parameters and quantized to 208 MB. With no real shell or filesystem behind it, the model predicts terminal-screen updates from keystrokes and can imitate applications such as vim and tmux. Edwardsson reports better results than prompted small-model baselines on limited command and file-readback tests, but says it remains unreliable as a filesystem. Inference runs locally via WebGPU.

Why it matters

WorldTUI is a compelling small-scale experiment in learned interfaces: a 360M-parameter model simulates a terminal from keystrokes, including limited persistence and multi-application behavior, entirely in a browser. Its value is not as a usable shell—the author says it is unreliable—but as a concrete demonstration of what task-specific fine-tuning, compact screen representations, and local inference can achieve. It raises an interesting question about interfaces generated by models rather than executed by conventional software, while offering no evidence yet that this approach generalizes beyond a narrow, synthetic terminal setting.

Current assessment

Simon Edwardsson reports fine-tuning a Qwen2.5-Coder-0.5B model to about 360M parameters and int4-quantizing it to 208 MB. WorldTUI runs locally in a browser via WebGPU and predicts terminal-screen updates from keystrokes; it has no real shell or filesystem. On the author’s small tests, it outperformed prompted small-model baselines, including on some file readbacks, but those evaluations are limited and not fully equivalent. The demo imitates several terminal applications and can retain some state, yet breaks on unfamiliar command combinations and is explicitly unreliable as a filesystem. This is an interesting narrow experiment in learned, stateful interfaces and compact local inference—not evidence of general world modeling or a practical shell replacement. No independent evaluation, broader implementation, or other material development has arrived; the discussion and initial attention do not establish the claims.

Measured heat

now 0 pts/hpeak 0 pts/hcomments 0/hpeers p10momentum: steady2 platformsage 890h
points/hour across evidence · reading as of 2026-11-27 02:23:58.509736+11:00 · deterministic, not a model opinion

How the heat travelled

10-20 13:00⭐ origin echo-reconstructedThe author describes fine-tuning a 360M-parameter model to simulate terminal screen updates from keystrokes, reports improvements over promp
Simon Edwardsson on blog (echo) · attributed from hn.story.50190363
—
10-22 02:18first on hacker news · published · +37.3hWorldTUI: I trained a 360M model to pretend to be a terminal
alphax314
—
10-22 02:18amplified on hacker news 👑hn.story.50190363
alphax314
peak 654 · 195 comments · 100% of case engagement
10-22 05:26our radar first saw it · +40.4hdiscovery anchor: hn.story.50190363—
pace: p91 vs 879 stories at the 720h mark (now 890h old) — ahead of claude-linux-kernel-root-exploit-claim (1.0x), behind deepseek-search-fetch-api-launch (1.0x)

Evidence (2) — ⭐ canonical anchor

sourceobjectauthorscorecomments
🟧 hnWorldTUI: I trained a 360M model to pretend to be a terminal
Retrieved article excerpt

Open article · Retrieved 2026-10-22T05:26:52.572983+00:00

# WorldTUI: I trained a 360M model to pretend to be a terminal

2026-10-21
/
Simon Edwardsson
/
[Follow @SimEdw](https://x.com/SimEdw)



TL;DR: I fine-tuned a 360M-parameter language model to act as a terminal. There's no shell or filesystem behind it: every keypress goes in, and the model predicts how the screen changes. It can create files, run vim and tmux, play snake, and usually remembers what you wrote a few commands later. The biggest wins were teaching it to repair its own mistakes and decoding screen rows in parallel. [Try it in your browser (208 MB)](https://simedw.com/projects/worldtui) and type `pythoon` to see that it's not a real shell.

The demo is designed for a desktop browser with WebGPU and a physical keyboard. Chrome or Edge is the best place to try it. It should work on a modern phone, but painfully slowly.

[![

](images/worldtui-tour.jpg)](videos/worldtui-tour.mp4)

When I first saw [Genie 3](https://deepmind.google/models/genie/) last year, I started imagining a future where applications aren't written in code but learned. Instead of a game engine rendering the scene, a model predicts the next most likely frame from the user's inputs.

Naturally I wanted to train my own world model. But I don't have a massive GPU cluster or a pile of video data, so I scaled down my ambition: instead of a game world, a terminal.

A terminal turned out to be a good fit. It's just a grid of characters rather than pixels, and I can generate as much perfectly labelled training data as I want by running real shells. A pretrained language model also already has a pretty good idea of what `ls` or `cat` should print.

What I really wanted to know was whether it could maintain a consistent world, or just generate convincing terminal output.

The final model is based on Qwen2.5-Coder-0.5B, fine-tuned on terminal sessions recorded from real programs running inside Docker.
[Jump to example videos](https://simedw.com/2026/10/21/world-model-terminal/#what-it-can-do)

## How it sees a terminal

Standard LLMs take a prompt and then append tokens to the end, one at a time. That doesn't map well to a terminal. A single keypress can do something on its own, like `esc` in vim, and output doesn't always go to the bottom: `clear` wipes the screen and sends the cursor back to the top. So instead of predicting a stream of text, I need to predict changes to the screen.

I treat the terminal as a grid of characters, one per cell.[1](https://simedw.com/2026/10/21/world-model-terminal/#fn:1) The model doesn't see the grid directly, but a sequence of tokens describing its contents and the changes made to it.

### A session

Every session starts with a snapshot: the screen size, its contents and where the cursor is.

The size is part of the input, not fixed at 32×96. In the demo, you can set the rows and columns when creating a custom starting screen.

```
BOS SCREEN_START 32 96
ROW_0 0 'simedw@laptop:~$ '
CURSOR 0 17 1
SCREEN_END
```

This also lets me start partway through an application. Give it a bash prompt, vim buffer or a game of snake, and the model tries to continue from there. (It does better from bash.)

After that, each keypress goes in as the raw bytes a real terminal would send. Letters are themselves, Enter is `\r`, Escape is `0x1b` and ← is `ESC [ D` and so on.

```
INPUT_START 'l' INPUT_END
```

The model answers with which rows to rewrite and where the cursor ends up:

```
OUTPUT_START
ROW_0 17 'l'
CURSOR 0 18 1
OUTPUT_END
```

In words: on row 0, starting at column 17, write `l`, then move the cursor to row 0, column 18. The last `1` means the cursor is visible, since full-screen apps sometimes hide it.

Nothing gets cleared first. New characters are simply drawn over the old ones.

I didn't need new tokens for characters. Qwen already has tokens for all 256 byte values, which I reuse for characters, coordinates and other small numbers. So a coordinate like 17 takes one token, not two.

Time is an input too. If nothing is pressed, the model gets a WAIT token with a duration instead of a key, which is how snake keeps moving on its own.

### Copying rows

When you reach the bottom of the terminal window and press enter, every line has to move up by one. I could just ask the model to output every row again in its new place, but that's around 3,000 tokens for a single keypress.

So I added a `COPY` operation instead:

```
ROW_0 COPY 1
ROW_1 COPY 2  
ROW_2 COPY 3
...
```

Each operation copies a row from the previous screen. In this example, the old row 1 becomes row 0, row 2 becomes row 1, and so on.

A scroll now costs three tokens per row instead of roughly 96.

The same trick covers clearing the screen, inserting and deleting lines in vim, and navigating man pages. You can also copy a row and then overwrite part of it.

Altogether, the model uses a tiny vocabulary of 333 tokens: 256 byte tokens, 64 row tokens and a handful of special operations. Decoding is grammar-constrained, so every prediction is a valid screen update.

That tiny vocabulary comes back later, when I squeeze the model into a browser.

## Generating the training data

I initially looked for existing datasets of terminal recordings, including asciinema, but couldn't find one with the precise keystroke-to-screen alignment I needed.

Luckily it wasn't too hard to create my own.

The basic idea was to generate believable terminal sessions by running real commands inside Docker containers, recording every keypress and the screen after each one.

The synthetic recipe was:

1. Randomize usernames, hostnames, prompt styles, terminal sizes.
2. Randomize directories and files based on a fictional persona (developer, sysadmin, etc.).
3. Pick 6–24 weighted activities (modify files, vim, python, tmux, etc.).
4. Track state, so sessions mostly open files that exist.
5. Type like a person: one keypress at a time, with tab completion etc. I set the typo rate to 1.2%, which is generous to me.
6. 35% of sessions start partway through, forcing the model to learn to work from any state.

The terminal size was mostly 32×96, with some 24×80 and 40×120, so the model doesn't overfit to one size.

I kept expanding the dataset as the model became more capable, and finally landed on 336k episodes, which corresponds to roughly 2B tokens. For comparison, the base model saw around 18T tokens during training.

## Training

I used Qwen2.5-Coder-0.5B as the starting point. I needed a small model to get close to realtime performance. Being a coding model, it had also already seen plenty of CLI usage.

I started off by doing straightforward supervised fine-tuning: give a screen history and a keypress, predict the screen delta produced by the real terminal.

Ordinary typing was learned quickly: a letter appears, backspace removes it, the cursor moves.

In longer sessions, though, errors started to compound: a mistake in a filename propagated through the rest of the session.

### Learning from its own mistakes

To address this I took a page from DAgger, where a model learns from the states it visits rather than just the ideal demonstrations.[2](https://simedw.com/2026/10/21/world-model-terminal/#fn:2)

For each training example:

1. Pick a point in a recorded session, usually close to the command that produces the output.
2. Let the model predict the next 1-4 events.
3. Compare the resulting screen with the real recorded screen.
4. If the difference is small enough, construct a correction that repairs the model's screen on the next keypress.
5. Continue training on the corrected frame and a few subsequent real events.

The delta takes the model's incorrect screen to the correct next screen. In essence, it learns to "repair" its own mistakes.

There's one important restriction: the model must have enough information to infer the correction. Any words introduced by a correction must have appeared on an earlier real screen or in the user's typing, not just in the model's own predictions.

For example, if the model misspells a filename that appeared earlier, I can teach it to fix that. But if it lists a filename it has never seen, I can't expect it to get it right.

Training on those examples would actually reward hallucinations, which I really don't need more of.

About a third of the sampled sessions produced useful correction examples. I repeated this in three rounds, each time collecting mistakes from the latest model.

Self-correction was one of the more effective training changes. Along with some additional training data, it improved PresetBench (defined below) from 24/47 to 38/47 at int4.

In total, training the model and its later refinements took roughly 75 GPU-hours on an RTX 4090.

### Testing

I use three tests. **ShellBench** has 106 commands across 24 handwritten bash sessions, scored by exact output. **PresetBench** has 47 scripted cases drawn from failures I hit in the demo. Neither test appears in the training data.

The **memory test** has 32 worlds. Each writes two random values to two files, then reads them back in separate sessions. A world passes only if both readbacks are exact, giving 64 readbacks overall. The names and values never appear in training.[3](https://simedw.com/2026/10/21/world-model-terminal/#fn:3)

How much does fine-tuning help?

| Model[4](https://simedw.com/2026/10/21/world-model-terminal/#fn:4) | ShellBench /106 | File readbacks /13 |
| --- | --- | --- |
| Qwen2.5-Coder-0.5B, prompted | 52 | 2 |
| Qwen3-0.6B, prompted | 60 | 3 |
| WorldTUI | 80 | 9 |

The biggest difference was memory: WorldTUI got 9/13 readbacks right, compared with 2/13 and 3/13 for the prompted models.

It's still far from a reliable filesystem. It handles familiar commands fairly well, but combining them in new ways can quickly break things. For example, after `echo green >> colors`, running `cat colors` often doesn't show the appended line.

## Making it fast

For a while I stayed away from autoregressive models altogether. A full redraw is around 3,000 tokens, and generating those one at a time seemed hopeless for something that's supposed to feel like a terminal.

But they just performed so much better than the alternatives I tried, so I gave in. With one token at a time, typing felt fine at ~38 ms per key, but anything that redraws the whole screen (`vim test.txt`, `man`, `clear`) took up to 12 s on my RTX 4090, exactly as feared. Plenty of time to reconsider whether I needed the manual. And I wanted this to run on my Mac, in near real-time.

### Rows in parallel

What I'd missed was that most rows in a frame don't depend on each other, so there's no reason to generate them one after another. I run one batch element per row. Each gets the same previous history (including KV cache) but generates only its own update.

That changes the decoding cost from the sum of all rows, up to 3,000 steps, to the length of the longest row, roughly 100 steps.

The cursor then becomes its own step at the end that can see the whole set of row updates.

This required a matching attention mask during training, but the speed improvement was worth it. Large-frame p95 latency dropped from 6.7 s to 0.87 s.



Large-frame p95 latency (RTX 4090) ↓

Sequential6.7 s

Parallel rows0.87 s

### Rows that can't talk to each other

This might sound too good to be true, and it was.
The issue is that since rows are independent, they can't coordinate, which led to `vim` opening on row 3 instead of row 0, or several rows adding food for snake at once.

The solution was speculative decoding.

Normally speculative decoding uses a small model to draft tokens and a larger model to verify them. Thanks to causal attention, several tokens can be verified in a single forward pass.

Here I use the same model for both: the parallel rows produce a draft, which the model then verifies sequentially.

The verifier keeps tokens up to the first disagreement. From there it generates its own correction and re-proposes the remaining draft.

In the browser on my M4 Mac, typing a single c
alphax314654195
🟧 echo.blog ⭐The author describes fine-tuning a 360M-parameter model to simulate terminal screen updates from keystrokes, reports improvements over prompSimon Edwardsson——

Interpretation history

Decision trace