Inspiration

The best moments on Twitch are made by chat, but most stream games only let viewers press buttons someone else designed. We wanted viewers to design the buttons. In PATCH WARS a viewer types an idea for a new soldier, the community votes, and a few seconds later that soldier walks onto the battlefield and fights for their team. The catch is that generated mechanics are dangerous: they can be broken, unfair, or try to run code. So the hard part, and the fun part, became making "chat invents a unit" safe and fair enough to run live.

What it does

PATCH WARS is a castle-to-castle auto-battler controlled from Twitch. Two teams, Ember and Azure, push soldiers down a shared lane. Viewers:

  • deploy soldiers with chat commands like !spawn archer, !attack and !defend, spending shared team energy;
  • pitch new units with !forge <idea> and vote with !vote p1 (one effective vote per Twitch account);
  • watch the winning idea go through the Forge: AI generation, strict schema and safety checks, then 200 headless balance engagements against the five starter classes before it is allowed to spawn. <!-- source: docs/forge-pipeline.md -->

Approved units get a reveal card with their abilities, weaknesses and real balance numbers, a three-second countdown, and then they deploy into the live match. Every warrior also gets an original Forge sigil, drawn procedurally in code from its blueprint, so the same unit always gets the same emblem. A small synthesized sound kit (Web Audio, no audio files, muted by default) marks spawns, Forge reveals and victory.

Every chat command gets a visible receipt in the arena and the OBS overlay, and the exact soldier it spawned is highlighted for a few seconds, so viewers can see that their message did something.

How streamers use it

  • Single streamer. Open the dashboard, create a live match and authorize your channel with Twitch OAuth. Add the overlay link to OBS as a browser source. Your viewers play by typing commands in your normal Twitch chat; they need no extra account or extension. With one channel connected, Azure is a server-controlled opposing army.
  • Two-streamer collab battles. Invite a second broadcaster with a private, expiring link. Each community controls one castle. Messages are attributed to their original channel, so a message replicated through Twitch Shared Chat still counts once, for the right team. <!-- implemented and tested; two-channel and Shared Chat live verification pending per docs/readiness.md -->
  • Raids. An incoming raid sends reinforcements to the raided channel's team, scaled by raid size and capped at 8 units. <!-- source: docs/twitch-integration.md (raid strength formula); real raid events not yet verified per docs/readiness.md -->
  • Bits-powered deployments. A native Twitch Extension can sell fixed soldier activations from 10 to 50 Bits. Twitch handles the confirmation; our server verifies the signed receipt and the transaction through Helix before any soldier spawns, and records it in a SQLite ledger so a deployment is never delivered twice. <!-- source: docs/paid-deployments.md --> For streamers this is a new earning loop tied to gameplay instead of a donation box. The landing page has a "For streamers" section with an earnings estimator based on the broadcaster's share of Bits used in an Extension (80% of 1 US cent per Bit); it is clearly labelled as an estimate. Paid mode is off by default, and real Twitch review of the Extension and a live Bits transaction are still pending.
  • OBS overlay. A transparent 1920 x 1080 overlay or a full battlefield page. Overlay links are view-only.
  • Twitch Extension. A transparent video-overlay panel with a compact soldier tray, so viewers can deploy by clicking instead of typing. It is built and tested against mocked Twitch services, but not yet installed through Twitch Hosted Test or approved.

How we built it

Most of PATCH WARS was built in a single OpenAI Codex thread (01a18312-00c1-7360-91d0-27e410da449c). <!-- source: docs/codex-evidence.md --> Codex wrote the deterministic engine, the ability interpreter, the Twitch integration, the Forge worker, the authoritative server, the React and PixiJS interface, the art pipeline and the test suites, and it diagnosed real failures along the way. A final polish pass (the streamer landing section, Bits estimator, procedural sigils and sound kit, and this write-up) was done with Claude Code.

It is a TypeScript pnpm workspace:

  • packages/shared: Zod schemas for every boundary and wire contract.
  • packages/game-core: a seeded, deterministic 20 Hz simulation with no IO, clocks or unseeded randomness. The same seed and inputs always replay to the same match.
  • packages/twitch-adapter: OAuth, EventSub over WebSocket, source attribution and deduplication.
  • apps/forge-worker: AI providers, safety checks and headless balance simulation in a worker.
  • apps/server: Fastify server that owns rooms, permissions, voting, Forge jobs and snapshots.
  • apps/web: React operator dashboard and PixiJS spectator renderer.
  • apps/extension: the native Twitch video-overlay Extension.

Generated units are data, never code. A unit can only use five allowlisted operations (shield, slow, splash, heal, split), at most three per unit, each with hard numeric bounds. The interpreter has no eval, Function, VM or dynamic imports. Blueprints are capped at 10 KB and the battlefield at 160 entities. <!-- source: docs/forge-pipeline.md, docs/security.md -->

Each candidate unit fights 200 cost-matched engagements, alternating sides against all five starter classes, and must land between a 25% and 75% win rate to be admitted. <!-- source: docs/forge-pipeline.md --> Providers include a fixture provider for the demo, free local Ollama, OpenAI Responses, and a Codex SDK provider that stays gated off until OS-level isolation is verified.

On the Twitch side, the server subscribes to channel.chat.message, channel.raid and Shared Chat events over EventSub WebSocket, with keepalive, reconnect and revocation handling. Replies go through the Helix Send Chat Message API. Tokens stay on the server and never reach snapshots, the browser bundle or logs.

Proof

What we measured Result
Live Twitch chat commands Archer and Guardian deployments confirmed by receipts in an authorized channel <!-- source: README.md "Verification status", docs/readiness.md -->
Real local AI unit (Ollama qwen2.5:3b) Passed 200 balance engagements at a 42% win rate, about 56 s for generation plus balance <!-- source: docs/evaluation/local-ai.json (winRate 0.42, generationAndBalanceMs 55529) -->
Adversarial prompts rejected 30 / 30 <!-- source: docs/evaluation/results.md -->
Fixture concepts accepted 20 / 20 <!-- source: docs/evaluation/results.md -->
Forge latency (fixture provider) p50 684 ms, p95 952 ms <!-- source: docs/evaluation/results.md -->
Simulation speed 3,600 ticks in 55.9 ms (64,379 ticks/s) <!-- source: docs/evaluation/results.md -->
Duplicate message suppression 1,000 / 1,000 <!-- source: docs/evaluation/results.md -->
Accelerated soak 4 simulated hours, 288,000 ticks, 0 failures <!-- source: docs/evaluation/soak.json -->
Automated tests 161 tests across 31 files passing <!-- source: docs/paid-deployments.md, "Implementation verification" -->

Fixture numbers measure our pipeline, not model quality. Two-channel Shared Chat, a real raid, a live Bits transaction and Extension Hosted Test have not been verified yet.

Challenges we ran into

  • Counting a message once. With Shared Chat, one message can arrive through several channels. We attribute by source channel and source message ID so it counts once, for the community that sent it.
  • Expressive but safe mechanics. We had to give viewers enough building blocks to invent interesting units while making arbitrary code execution impossible. A small bounded ability language was the answer.
  • Balance that says no. Our own demo star, a splitting slime, failed the balance gate at a 9% win rate. We recalibrated its cost from 6 to 5 instead of bypassing the gate. <!-- source: docs/forge-pipeline.md -->
  • Real models are messy. Local Ollama output failed validation and balance on early attempts. We kept the gates strict and retried within a two-attempt cap instead of silently falling back to fixtures.
  • Paid actions without trusting the browser. A browser callback never spawns a soldier. The server checks the signed receipt and the Helix transaction, and an interrupted delivery goes to the broadcaster for review instead of being guessed.

Accomplishments that we're proud of

  • A viewer idea really does go from chat to a vote, a worker, 200 simulated battles and a deployed unit that behaves the way it was described.
  • Real Twitch chat commands spawned soldiers in a live authorized channel, and a real local model produced a unit that passed the balance gate.
  • The simulation is fully deterministic. The same seed and inputs replay to exactly the same match, and our tests check this, which made debugging much easier.
  • Every simulated or fixture surface is labelled, so the demo never pretends to be live.

What we learned

Showing the engineering checks on stream, like the balance report on a Forge reveal card, turns safety into part of the show. Source attribution matters as much as command parsing. And a constrained language is what makes "let the audience generate mechanics" something you can run live.

What's next

  • Verify two-channel collab battles and Shared Chat with a second broadcaster, and real raids.
  • Get the Extension through Twitch Hosted Test and review, then run a controlled live Bits transaction.
  • Persist match history and tune mixed-army balance from live play.
  • Creator themes and community tournaments.

Built With

Share this project:

Updates

Submission history