afk-snake
v0.7.0
Published
A terminal game to play while AI agents finish jobs. npx afk-snake
Downloads
1,075
Maintainers
Readme
afk-snake 🐍
A game you play in your terminal while you wait for your AI agents to finish a job. No install, one command:
npx afk-snakeStep 1: Snake
- Steer: Arrow keys or WASD
- Pause:
P— freezes the game so you can jump back to your Claude terminal (Enterreturns to Claude; an arrow key resumes) - Restart:
R· Quit:Q/Ctrl-C - Walls and your own tail are deadly. The snake speeds up as you eat.
- Levels: every 10 points is a level (
┌─ LV 2 ─in the border). Each run starts with a random wall layout, and every level-up sweeps a ▸ LEVEL ▸ marquee under the board while new walls blink in — they can't hurt you until they turn solid, and the game never stops moving. - Power-ups: now and then a pickup appears — grab it before it blinks away. ✦ ghost slips you through walls and your own tail for a few seconds, ● slow-mo winds the speed back down, ▼ shrink trims your tail, and ★ ×2 doubles the score of every food while it lasts (tokens still count real food eaten).
- AI boss: from level 3 on, a rival crimson snake enters and hunts the same food you do, growing longer every time it feeds. Touching any part of it ends your run — even ✦ ghost won't carry you through it.
- Your best score is saved to
~/.term-game.json.
Beat your high score, screenshot the game-over card, and share it — the install command is right there on the card.
Daily streaks
Log in and play on consecutive days to build a streak. Every day you show up pays
+5 tokens, with milestone jackpots at days 3 (+20), 7 (+50), 14 (+100), and
30 (+250) on top. Miss a day and the streak resets — your card nudges you to keep
it alive.
Leaderboards
Press L on the game-over or ready card to open the leaderboard. Toggle between
the Daily board (your best score on the current UTC day) and the All-time
board (your career best) with ← / →, and B to go back. Each board shows the
top players and your own standing — even when you're outside the top ten. Only
logged-in players appear; names are GitHub logins.
Shop
Press S on the game-over or ready card to open the Shop and spend your tokens.
Switch between the two tabs with ← / →:
- Cosmetics — snake skins. The Glowing Trail (30 tokens) gives your snake a
glowing comet tail, and five more color trails are buyable: Emerald Viper and
Ocean Tide (500 each), Wraith (750), Neon Pulse (1000), and Prism
(1500). Press
Ein the shop to equip any skin you own. - Rewards — lottery raffles. Spend tokens to buy entries into a draw; enter as many times as you like for better odds. Launch rewards: Claude Max (1 month) at 200 tokens/entry and a $25 Visa gift card at 100 tokens/entry.
The shop shows a live preview of what you're browsing: on Cosmetics the comet trail
of the selected skin slithers above the list, and on Rewards you see one ◇ ticket per
entry you already hold. Move the cursor with ↑ / ↓, press Enter to buy or
enter (the bottom line always shows what Enter will do), and B to go back.
You need to be logged in (afk-snake login) to make purchases.
Snake Farm
Press F on the game-over or ready card to open your Snake Farm — a passive
earner that works while you're away (waiting on your agents). You own one snake that
accrues tokens over real time, up to a storage cap.
Ccollect — bank the tokens your snake earned since you last collected.Enterupgrade — raise your snake's level: it earns faster and stores more hours' worth (starts at 5 tokens/hr with an 8-hour cap). Each upgrade costs a little more than the last, and upgrading auto-collects first so you never lose progress.- Your snake evolves in name as it levels — Garden Snake → Corn Snake → Python.
- The farm card is alive: your snake slithers front and center (each evolution has
its own look, and it grows with each stage), a wide gold meter fills as tokens
store up, collects pop a gold flourish, and a full belly pulses
FULLuntil you collect. Colors turn off automatically whenNO_COLORis set or output isn't a TTY.
Storage caps out (8h at level 1), so check back between agent runs. B goes back;
you need to be logged in (afk-snake login) to play the farm.
afk-arcade
afk-snake now has neighbors. npx afk-arcade opens a terminal game arcade —
browse games published by other devs, save favorites to a local library, and
launch them without leaving your terminal. Devs publish their own npm-packaged
games from the TUI (P), listings go live after review, and players rate
games right from the arcade (R).
See arcade/README.md.
The arcade also lives on the web: afk-arcade.pages.dev · browse the catalog, read ratings and reviews, and check live leaderboards.
Develop
npm start # play from source
npm test # run the unit tests (node:test, zero deps)Phase 2: Auto-launch while you wait
Run your AI agent (Claude Code) in a terminal, then once:
afk-snake install # adds wait-game hooks + a resume hotkey (Ctrl-S)Every prompt you send opens the game in a pane beside your agent's terminal —
you play on the right while you watch the agent work on the left. Your game is one
continuous session: it freezes when the pane closes and resumes right where you
left off (same score and snake) on the next prompt — press any key to un-pause.
Dying, quitting (Q), or restarting (R) starts a fresh game next time.
You don't need tmux for this — the hook tries a chain of terminal surfaces and takes the first one that works:
- tmux — if the agent's shell is inside a tmux session (or a tmux client is attached anywhere), a real split opens beside it. This wins even when you're also inside Cursor/VS Code/Windsurf's integrated terminal.
- Cursor, VS Code, Windsurf — a terminal split beside Claude via the companion
extension, provided it's installed (auto-installed by
afk-snake installwhen it detects the editor). To install manually, use<cli> --install-extensionor the Extensions view, then reload the window. - zellij — a right-hand pane via
zellij action new-pane. - WezTerm — a right-hand pane via
wezterm cli split-pane. - kitty — a vertical split via kitten's remote control.
- iTerm2 — a split pane via AppleScript, if iTerm2 is running.
- A new Terminal.app window (macOS only) — the last resort, since it's the most intrusive option.
A few warts worth knowing about:
- kitty needs
allow_remote_control yesin yourkitty.conf. Without it the split silently fails to launch and the chain falls through to the next surface (a new window on macOS, or nothing on Linux) — but only if kitty's own listen-on marker isn't present. If it is (kitty is running but remote control is off), the chain has already committed to kitty and that split attempt just does nothing. - The first AppleScript-driven launch (iTerm2 or the Terminal.app fallback) may trigger a one-time macOS automation consent dialog asking to control that app. Denying it means that surface is skipped from then on and the chain continues without it.
- The Terminal.app fallback window closes itself when the game exits only
if Terminal's "close the window if the shell exited cleanly" preference is
set; otherwise the window sticks around showing
[Process completed]and you close it yourself.
Control which surfaces are eligible:
afk-snake install --no-windowskips the new-window fallback entirely (real splits — tmux/zellij/WezTerm/kitty/iTerm2 — still work; only the last-resort window is disabled).- Set
"surface": "auto" | "panes-only" | "off"in~/.term-game.json—panes-onlyis the same as--no-window,offdisables the auto pop-up altogether. The tmux resume hotkey (Ctrl-S) still works withoffset — it's an explicit ask, so only the automatic per-prompt pop-up is silenced. TERM_GAME_SURFACE(same three values) overrides the file for one shell — handy for scripts or a one-off session without editing your profile.
On Linux, splits work in zellij, WezTerm, and kitty; there's no new-window fallback yet, so outside of those three (and tmux) the hook stays quiet.
Rather browse the whole arcade while you wait? Install with:
afk-snake install --arcade # the side pane opens afk-arcade instead of SnakeThen any game deployed on the arcade plays in that pane, and the arcade shows the same "your agent is ready" beacon when the agent finishes (while a third-party game has the terminal, the beacon appears as soon as you're back in the store).
Jump back in anytime (resume hotkey)
afk-snake install also binds a tmux hotkey — Ctrl-S by default — that
reopens the game pane and resumes your saved game without prompting the agent.
Press it from anywhere inside tmux. Pick a different key with:
afk-snake install --key M-g # e.g. Alt-G instead of Ctrl-SThe binding lives in a managed block in your ~/.tmux.conf (or
~/.config/tmux/tmux.conf if that exists) and is applied live immediately when
you run install from inside tmux. afk-snake uninstall removes it.
Auto-return when the agent needs you
The game also flips to the "ready" card automatically whenever the agent pauses
to wait on you mid-task — a tool permission prompt, an AskUserQuestion choice,
or plan-mode approval — not just when the whole turn ends. Press Enter to close
the pane and hop back to Claude to answer.
Remove it any time with:
afk-snake uninstallNot on a supported surface (no tmux/zellij/WezTerm/kitty/iTerm2, and not macOS)?
The hooks stay out of your way (the pane is skipped) — just run afk-snake in a
spare terminal instead.
Note: the resume hotkey above is tmux-only — it's bound in your tmux config, so it needs an actual tmux session to press it from. The auto pop-up itself works across every surface in the chain.
Profile knobs (~/.term-game.json)
idleExitMinutes(default90): the wait-game and arcade exit on their own after this many minutes without a keypress, so a forgotten pane or window never blocks the next auto-launch.0disables the idle exit.raise(defaulttrue): when a prompt fires while the game is already running, bring its pane/window to the front (tmux pane select; tty-matched window raise for Terminal.app and iTerm2). Set tofalseto restore the old silent behavior. A process whose window has closed is cleaned up and relaunched automatically either way.
MIT © jsiwinski
