Inspiration
Twitch chat can trigger commands, but it cannot rewrite the rules of the game. We wanted chat to be a co-author of a small world, without ever letting untrusted chat text reach a coding agent.
What it does
Chat Writes the Laws lets viewers write the physics of a tiny world in one fixed sentence, for example when ball hits wall it turns red. A valid sentence becomes a law: the viewer's name goes into the rulebook and onto the stream overlay (an OBS browser source). Anything outside the grammar is dropped, and only a counter goes up. The text is never shown, stored or sent to an agent. Two viewers asking for conflicting laws on the same pair: the second is rejected as a conflict. There are 7 laws so far, including behaviour laws such as when ball hits floor it bounces higher.
How we used Codex
Codex built the project and is part of every law. Chat is untrusted input, so it never becomes a prompt. A deterministic compiler turns each valid sentence into an executable failing test (112 precompiled grammar combinations for colour laws, plus behaviour combinations). Codex gets only that failing test and edits chatlaws/lawtable.py (and engine.py for behaviour laws) until the test passes. The test is the law, Codex is the builder. Every law has its Codex session id in SESSIONS.log in the repo. Sentence-to-screen latency, measured 3 times with a real codex exec patch: 11.6 to 15.7 s. Law 7 was written by Codex across two files in 47 s.
How it works
IRC line -> grammar (drop = counter only) -> queue -> precompiled test -> red -> codex exec patches the law table -> green -> state.json -> canvas plus rulebook overlay. Python 3 standard library only; 88 tests pass (python3 -m unittest discover -s tests -t .). Live mode reads a public Twitch channel anonymously over IRC (no login, no Twitch app), and we ran it against a public channel; the overlay and rulebook are plain HTML for OBS.
Honest limits
The chat in the demo video is a stand-in: scripted viewer names, shown with a SIMULATED CHAT banner and disclosed in the narration. The Codex run in the video is real and its 47 s patch is time-lapsed. No real viewer has written a law yet; laws 1 to 6 were typed by the developer. Static subjects (wall, floor) never move, so they cannot trigger a law as the subject.
What is different
Twitch Plays Pokemon style control, Nightbot, Crowd Control and Streamlabs let chat issue commands or trigger pre-made effects. Here chat edits the rules themselves, and a sentence becomes a tested rule before any agent sees it.
Try it
python3 -m chatlaws.cli demo replays a simulated chat through the real grammar, queue and compiler, with no Twitch account, no install and no API key. The repository is public: https://github.com/Ryugi62/chat-writes-the-laws
Codex session id (law 001, where Codex fixed the engine): 01a16f43-ef31-7d42-8581-758ecfd5d5fa. Other session ids are in SESSIONS.log.