Frontier AI models charge by the token, and costs add up. A coding session can burn half a million tokens, and a single prompt can cost more than a cup of coffee. Run ten sessions a day and your AI bill can easily surpass your caffeine budget.
Tarsk ships fourteen token minimization techniques that run automatically every session. Some shrink the input before the model reads it. Some skip entire rounds of conversation. Some learn your project patterns to predict what you need before you ask.
If you have used Tarsk for a week, most of these are already running.
The token problem
An AI agent session is a loop. You send a prompt. The model responds. The model calls a tool. The tool returns output. The model reads the output and responds again. Every step appends text to the conversation. The model re-reads the full conversation on every turn.
A grep across a large project can return 15KB of text. After 30 tool calls, that same 15KB has appeared in 30 turns. You pay for it on every turn, not just the turn that produced it.
Token costs are the largest variable expense in agent usage. Each technique below attacks a different slice of that expense.
Lossless output compression
Tool output is the single largest consumer of context in a coding session. Every file listing, every search result, every build log gets re-read by the model on subsequent turns. Tarsk compresses repetitive output before the model ever sees it — identical information in fewer characters, with no loss of fidelity.
Tarsk applies multiple compression strategies tuned for common agent output patterns. Redundant file paths get collapsed. Repeated directory prefixes get factored out. Search results get restructured so file names appear once instead of once per match.
Compression is lossless. Every byte removed is redundant. The model receives the same data in a denser form, and every guard checks that compression never expands the output. The result: tool output that would cost 15KB in context lands closer to 5KB.
Prompt caching
When the same text appears in consecutive API requests, many providers offer prompt caching — cache reads cost a fraction of full input tokens. Tarsk marks the system prompt and early conversation turns as cacheable on every request. The system prompt rarely changes and earlier turns stay identical across requests, so large portions of each call qualify as cache reads. You pay less for the same input.
Caching runs automatically on every model call.
Structured conversation history
AI agents need memory of earlier conversation turns. The naive approach dumps past exchanges as a text blob inside the current user prompt. This changes the entire prompt on every turn and breaks caching.
Tarsk passes prior exchanges as structured user and assistant message pairs. Earlier turns remain identical across requests and stay eligible for caching. The model receives the same history at a lower price.
Assistant summary compression
Only the most recent assistant response needs full fidelity. Older turns carry more detail than value. Tarsk compresses older replies to their salient lines: headings, bullet points, code blocks, and action verbs like “implemented”, “fixed”, or “created”. Cap: 12 lines and 3,000 characters.
When Tarsk builds conversation history for a new turn, the most recent assistant reply passes through unmodified. Earlier replies receive the compressed summary labeled [Earlier assistant response summarized to reduce context tokens].
Multi-turn history shrinks substantially. The model still sees what happened. It no longer reads verbatim code blocks and file contents from 10 turns ago.
Conversation window limit
Long conversations accumulate history. Tarsk caps the sent history at 10 exchanges and drops earlier exchanges entirely.
Ten exchanges give the model enough context to understand the current thread. The cap prevents history from growing without bounds into the tens of thousands of tokens.
The /compact command
When 10 exchanges is not enough, or the conversation feels long, type /compact. Tarsk sends the full conversation to a cheap model which produces a single summary paragraph. The summary preserves project goals, technical decisions, files changed, current state, and outstanding tasks.
After compaction, your conversation resets to one exchange containing the summary. The context window drops to near zero while the model retains everything needed to continue.
Compaction deliberately excludes debugging noise, failed attempts, and verbose tool output. Those consume tokens without contributing to the project state the model needs.
Cache-stable skills and tools
Tarsk keeps the skill catalog and tool schemas in a deterministic order across conversation turns. Full skill instructions are added only to the current user turn when a skill is explicitly invoked or enabled for the thread.
Tools load eagerly so their schemas do not shift after a tool_search call. The first request may contain more input, but later requests can reuse the same cached system-and-tools prefix instead of paying for repeated cache misses.
Volatile information such as the current date, dev-server status, and skill arguments is placed beside the latest user message rather than in the system prompt. Earlier conversation content remains byte-stable and eligible for provider prompt-cache reads.
System prompt conciseness
The system prompt tells the model: “Be concise and answer directly; do not restate the question, add preamble, or end with unsolicited follow-ups.” This discourages the verbose conversational filler many models default to.
Output tokens cost more than input tokens on most providers. A single conciseness instruction meaningfully cuts output token usage across a session.
Additional prompt sections (plan mode, Ralph mode, developer context, project analysis) only appear when those features are active. The model never reads rules for features you are not using.
Event storage compaction
Streaming events (incremental tool call updates, partial responses) help during a live session but waste storage. Tarsk strips them before persisting conversation history. Only final tool results and completed messages get stored.
Inline base64 image data also moves to separate storage. A single image in context can consume tens of thousands of tokens. Keeping images out of conversation records reduces database size and speeds up history queries.
Ralph Mode context reset
Ralph Mode (autonomous story implementation) generates a fresh conversation for each iteration. Memory across iterations passes through git history, progress files, and todo lists.
Each iteration starts with a clean context. The model never reads the full conversation from iteration one through twelve. Input stays small and predictable regardless of how many stories preceded the current one.
Disabled tools
Projects can disable tools globally in project settings. Remove a tool you never use and its schema disappears from the system prompt on every request. Stop sending what you do not need.
Context breakdown monitoring
The context breakdown view shows where your tokens go: system prompt, tool definitions, rules, skills, subagent definitions, conversation history. Each category shows its estimated token count.
When a category grows large, act on it. Large system prompt? Prune unused skills. Large tool definitions? Disable unused tools. Large conversation history? Run /compact.
The breakdown uses actual token counts when the provider reports them and estimates from character count otherwise (roughly 4 characters per token).
Daily spend tracking
The Daily Spend widget shows token consumption, cost, and savings in one view: bytes saved from compression, tokens saved from neural predictions, turns saved from tool promotion and file prefetch. Tracks today, last 30 days, and cumulative totals.
You can verify each technique is working and measure the combined effect.
How they work together
These techniques form a layered defense.
Prompt caching reduces the cost of static content on every call. Compression shrinks tool output before context entry. Neural predictions skip unnecessary turns by loading the right tools and files upfront. Skill pruning removes irrelevant system prompt text. History compression and the 10-exchange cap keep conversation length in check. /compact resets everything when needed. Context breakdown shows what is consuming tokens so you can tune further.
No single technique solves everything. Together they cut typical token consumption substantially compared to an unoptimized agent session. Across heavy daily usage, the savings add up fast.
What you do
Most techniques run automatically. Three actions you control:
- Run
/compactwhen a conversation grows long. - Disable tools and skills your project does not use. Every removed schema saves tokens on every request.
- Check the Daily Spend widget and context breakdown view. Know what is consuming your tokens and whether savings are accumulating.
Tarsk compresses, caches, prunes, promotes, and prefetches without configuration. Check your spend widget after a few sessions and watch the numbers add up.