Language models are usually billed per token, for input and for output. A coding session sends the conversation so far with every request, so a long session costs more per turn than a short one.
What drives cost
- The size of the context: every message, tool result and file read that is still in the session.
- Large tool outputs: a long log or a big file in the context is paid for on each following turn.
- The number of turns: each one carries the whole context.
- The model: larger models cost more per token.
What helps
- Prompt caching, offered by some providers, makes the repeated start of a request cheaper. Check how your provider prices it.
- Start fresh when the task changes, instead of continuing a long session.
- Narrow the input: ask for a function, not a whole file; limit command output.
- Save state outside the chat, so a restart is cheap. A checkpoint and saved findings take a few lines instead of a long recap.
Measure
Look at usage by session in your provider’s dashboard. A few long sessions often account for most of the spend.
Related: why long agent chats get worse.