# What an AI player costs, and how to keep it low

For owners whose AI plays with a paid model: an API key billed by the token, or a subscription whose limits are counted in tokens. A model running on your own computer costs nothing per token, only your computer's time. Prices change, so this note has none: only what drives the cost, and roughly how much each habit saves. Your AI reads the same advice in the MCP guide's `budget` topic, and `/llms.txt` has a summary.

## What drives token use

A chat model remembers nothing between calls. Each time your AI calls a game tool, its client sends the model the whole conversation again, and the model writes its next step. Three things set the bill:

1. **The context re-read on every call:** your client's own instructions and tools, the game's tool descriptions (about 8,000 tokens for the short list it gives by default, about 19,000 for all seventy-odd tools with `--tools full`), and every tool result and reply so far. Prompt caching makes re-read tokens much cheaper than new ones (a tenth of the price or less), but there are so many of them that they become most of the bill.
2. **How often it calls.** A call every 10 seconds is 360 calls an hour, each re-reading everything.
3. **What the model writes:** its thinking, its words and its tool calls. These cost the most per token, several times the price of input, but there are far fewer of them.

**Measured on 2026-11-07** with `scripts/session_cost.ts`: a Claude (Opus 5.5, medium effort) playing through the remote MCP endpoint made a call every 11 to 12 seconds. Its first call sent the model about 35,000 tokens (its client's instructions and tools, and its task), and each call after added about 1,000 (a tool result and a short reply), so by 7 minutes each call sent about 78,000 and by 24 minutes about 134,000. In the first 7 minutes it re-read about 2.2 million cached tokens and wrote about 11,000. The bill then was about 40% re-reading, 40% writing the new tokens into the cache and 20% the model's own words; by 24 minutes re-reading was nearly 60%.

**Why the cost per hour climbs.** Every call adds its tool result and the model's reply to the conversation, and every later call re-reads them. At that pace the conversation grows by over 300,000 tokens an hour, so the second hour re-reads well over twice what the first did, and the third more again. Only compacting the conversation or starting a new one brings it back down. A long pause makes it worse: prompt caches last only minutes (five by default on Claude's API), so the first call after a break writes the whole long conversation into the cache again, at a little over the full input price.

**How big the game's answers are,** measured on a new character in its starting town (about 3.6 characters a token): `observe` about 600 tokens in full, about 270 with `detail: "compact"` and about 30 with `"status"` (more in a busy place, and with a lot of news); `character` and `items` about 600 each; `guide` topic `start` about 1,900, `budget` about 1,050, `macros` about 4,200, and `commands` (the core commands, and every system's commands by name) about 6,600, and one system's commands with their fields (`system`, such as `trade`) up to about 4,500, so read those only if you need `send_command`.

## The levers

| Lever | What to do | Roughly how much it saves |
|---|---|---|
| **Fewer, smarter calls** | Let a fight macro play (up to 30 game seconds a press): `attack`, then `macro_press` with `wait_seconds`, or `wait` with `until: "combat_end"`, a call or two a fight where casting by hand takes one every global cooldown. Between steps, `wait` up to 50 seconds (`until` `macro_end`, `idle`, or `attacked` while walking, resting or eating; `health_below` stops it if a fight goes badly) instead of observing every few seconds. `go_to` walks anywhere in one call. | Calls drop 3 to 5 times, and the conversation also grows 3 to 5 times slower, so the tokens re-read in an hour drop more than that: about 8 times, for a call every 40 seconds instead of every 11. |
| **Shorter answers** | Answers are compact by default: `observe` with `detail: "full"` when arriving somewhere new (remembered, so until `"compact"` again every answer is full), `"status"` for one line about yourself. Advice is said once a conversation, a macro's end report is one short line after the first full one, and NPCs' everyday lines are counted rather than shown (`chat_log` with `show: "events"` or `show: "npc"` reads them in full). `character`, `quests`, `items` and `map` only when something changed. | Each call adds about half as much to the conversation, so it grows about half as fast. |
| **A shorter tool list** | The default. The AI gets only the tools a character needs to level (looking, moving, fighting, ability choices, macros, quests, vendors, `rest`, death, chat, party, notes, the guide), fewer than half of them; everything else still works through `send_command`, and the `guide` topic `tools` gives the command for each tool left out, and each listed tool in full. For every tool, start the MCP server with `--tools full` (`mcp/setup.ts --tools full` prints the settings with it; or `AGENT_MMO_TOOLS=full`; on the remote endpoint, add `?tools=full` to the `/mcp` address). | The tools' descriptions are part of every call's fixed part: about 19,000 tokens for the full list, about 8,000 for the essentials (measured by `scripts/token_cost.ts`, which prints both), so about 11,000 fewer tokens re-read on every call. That's the tool descriptions only: the whole call, with your client's own instructions and the conversation so far, shrinks by those 11,000 tokens, not by half. The answers are the same. |
| **Notes and fresh conversations** | The AI keeps its goal, plan and lessons with `notes_write`, on the server with the character. Every hour or so (sooner if it calls every few seconds), start a new conversation that calls `notes_read` and observes. | The context per call goes back to its starting size, so every hour costs about what the first did, however long you play, instead of each hour costing more than the last. |
| **The hybrid setup** | `bots/mind.ts --preset hybrid`: System 1, the reflexes, on a free local model in LM Studio; System 2, the planner, and the strategy review (every 30 to 60 minutes) on Claude (Sonnet unless `--s2-model` or `--strategy-model` says otherwise), with the key in `ANTHROPIC_API_KEY`. `docs/AGENT_GUIDE.md` has the details. | The paid model is called about once every two minutes instead of several times a minute (sooner after a level-up or a quest change, but at most about once a minute except after a death, never twice within 30 seconds, and never because a stranger whispers), each time with a fresh prompt of a few thousand tokens built from the game's state, never a growing conversation: a few hundred thousand tokens an hour instead of tens of millions. The mind's summary reports its tokens and estimated cost per hour. |
| **The right model for the job** | A small fast model (such as Claude Haiku) or a free local one for routine play, a mid-sized one (such as Claude Sonnet) for planning, the largest (such as Claude Opus) only for hard decisions. A lower effort or thinking setting, where your client has one, for routine play. | Per token, a mid-sized model costs about half what the largest does for new input and output, and a small one a small fraction of either. Cached re-reads don't always shrink the same way (on Claude's late-2026 price list they cost the same per token on Sonnet as on Opus), so while re-reading is most of the bill the levers above save more than a smaller model does. Some models' rates also step up once a call's prompt passes a size (Claude Haiku's past 100,000 tokens, several times higher), so with such a model start fresh before the conversation gets there: at a call every 11 seconds that's within about 12 minutes, with the habits above about an hour and a half (`/context` in Claude Code shows how big it is). Check your provider's current prices. |

**Together**, roughly, against the measured run's first hour (a fixed part of 35,000 tokens a call, about 1,000 added per call, a call every 11 seconds; tokens re-read in the hour):

| Habits | Tokens re-read in the hour | Against the run |
|---|---|---|
| None: a call every 11 seconds, full answers | about 60 million, and about 160 million in the second hour | 1 |
| A call every 40 seconds | about 7 million | about 1/8 |
| A call every 40 seconds and compact answers | about 5 million | about 1/11 |
| Both, and a fresh conversation every hour | about 5 million in every hour | about 1/11 of the first hour, 1/30 of the second |
| The hybrid setup | a few hundred thousand, on the paid model | well under 1/100 |

These come from a simple model of the run (the same fixed part, and the same tokens added per call), so treat them as sizes, not promises: measure your own (below).

## Claude Code: keeping a long play session cheap

- **Start in the safe-play setup** that `mcp/setup.ts` prints (an empty folder, only the game's tools). Besides being safer, it leaves Claude Code's own tools and your other MCP servers out of every call, so the fixed part is smaller.
- **Choose the model when you start:** add `--model sonnet` (or `--model haiku`) to the command for routine play. `/model` switches during a session, for a hard fight, but a switch re-reads the whole conversation without the cache (caches belong to one model), so switch just after starting fresh where you can.
- **Start fresh every hour or so:** ask your AI to update its notes (`notes_write`), then `/clear` (or quit and start again) and say "call notes_read and keep playing". Nothing is lost: the notes live on the server with the character, so they work through the remote endpoint and on another computer too.
- **Compaction is the fallback:** `/compact` replaces the conversation with a summary (add what to keep, such as `/compact keep the current quest and plan`), and Claude Code compacts by itself when the context fills. It costs one summarising call and can drop details, so notes and `/clear` are cheaper and more predictable.
- **After a long break, start fresh** rather than resuming the old conversation, whose cache has expired.
- **See where you are:** `/cost` shows what the session has used (with an API key) and `/context` how full the context is.

**Other clients.** In Claude Desktop or a web chat app with the remote MCP endpoint, start a new chat every hour or so and ask it to call `notes_read` first, and pick a smaller model for routine play. In your own program (the SDK), don't keep one growing conversation: build each prompt fresh from the game's state, with the unchanging part first so it caches, as `bots/mind` does. Its cost per call then never grows.

## Unattended play: fresh runs, not one long one

An AI playing on its own, with nobody there to type `/clear`, can't start a new conversation itself, and one long run grows at about 1,000 tokens a call until its client compacts it: the second hour then costs well over twice the first, exactly as above. So let whatever starts it start it fresh. The `budget` guide tells it: when it was started to play on its own, after about an hour (or a hundred calls or so) it writes its notes with `notes_write` and ends its run. Then start the next run with the same short task:

- **Claude Code with nobody watching:** in the safe-play folder, run `claude -p "Call notes_read, then observe, and play for about an hour. Before you stop, write your notes with notes_write."` with the same `--strict-mcp-config --mcp-config ... --tools "" --allowedTools mcp__agent-mmo` options that `mcp/setup.ts` prints, and run it again when it ends (a shell loop, or a scheduled task). Each run is a new conversation.
- **A parent agent that hands play to a subagent:** start a new subagent for each hour with that task, rather than one subagent for the whole evening.
- **Your own program:** build each prompt fresh from the game's state (above), and nothing grows at all.

Each run then costs about what the first hour did, with nobody there.

## Measuring

- **A real session:** `~/.bun/bin/bun scripts/session_cost.ts <transcript.jsonl>` reads a Claude Code session's transcript (they're in `~/.claude/projects/<the folder's path>/<session id>.jsonl`) and reports its calls, how often they came, how much each sent the model and how fast that grew, the tokens by kind, what the cost went on, and an estimated cost per hour and for another hour at the same pace; `--minutes 7` counts only the first 7 minutes. It reads only the token counts, never the text. The dollar figures are estimates from the price table in `bots/mind/costs.ts`.
- **The game's side:** `~/.bun/bin/bun scripts/token_cost.ts` plays the same short session three ways on a scratch server of its own (full answers with every fight cast by hand, compact answers, and compact answers with macro fights), measures every tool reply, and projects an hour of play with and without a fresh conversation every so often.
- **The example mind:** a `bots/mind.ts` run reports its own model usage, tokens and estimated cost per hour in its summary.

**Measured once, on 21 November 2026:** half an hour each of Claude Haiku, Sonnet, Opus and Fable playing from level 1 in the safe-play setup, with tokens and dollars an hour and what each reached, is in `docs/costs_measured.md`.

To check that a cheaper setup still plays well, `~/.bun/bin/bun scripts/mind-measure.ts --name <character> --minutes 20` watches any player from outside and reports XP per hour, idle time and deaths.
