The API has no memory, so a chat works by re-sending the whole history every turn. Each new message rides on top of everything before it:
Run a few turns and the input count only goes one way. This is example output, not a live run:
Do the sum for a longer chat. If each turn (question plus reply) adds about 500 tokens, turn 20 sends about 10,000 tokens of input. Add up all 20 turns and you've paid for roughly 105,000 input tokens, because the early turns were re-sent nineteen times. Long chats also run into the last lesson's problem: an old tangent stays in the window, competing for attention.
Three ways to keep it in check.
Trim. Drop the oldest turns. Simple, but anything said early (the user's name, a key decision) silently disappears.
Summarise. Replace older turns with a short summary and keep the recent turns word for word. Anthropic's API can do this for you: compaction (in beta, October 2026) has Claude write the summary on the server, either when you ask or when the input passes a token threshold you set. Claude Code does the same when its context fills: it keeps decisions, open bugs and details, and drops repeated tool output.
Clear what's spent. In agents, old tool results are often the bulk of the history. Anthropic's context editing can clear them by rule. You'll meet tools properly in Give your model tools.
The art is in what the summary keeps. Too aggressive, and a detail that turns out to matter later is gone. So a good summary prompt says what to keep and what to drop.
Your turn. Write the summary prompt for this chat. Say what to keep, what to drop, and how long the summary can be.
Run your prompt and the replies land here.