Skip to content
docs

Context window

The agent keeps the whole conversation in the model’s context window: every message, every file it read, the output of every command. The window fills up fast, and the fuller it gets, the weaker the replies: the agent starts forgetting early instructions and makes more mistakes.

The status bar shows how full the window is, as a bar and a percentage. The indicator changes color as the window nears automatic compaction. In a subagent’s window, the indicator shows that subagent’s own context. /status shows how many tokens are used and the window size of the current model.

Each subagent has its own window. It starts with an empty history and does not receive the main agent’s conversation. The window size depends on the subagent’s model: if its definition sets the model field, it is that model’s window; otherwise it is the window of the main agent’s current model. You cannot set the window size as a number. A subagent compacts its history on its own, by the same rules as the main agent.

During compaction, older turns are replaced with a summary, and recent messages stay as they are. A limited selection of your recent messages from the compacted part is added to the summary. Long messages are shortened; older ones may survive only as part of the summary. Compaction does not touch the system prompt with your instructions (WAIBEE.md, CLAUDE.md). The saved conversation does not change and stays available in the interface, including after you resume the session.

  • Automatically. Compaction starts at the share of the window set by context.compact_at: 20 to 70 percent, 70 percent by default.
  • By hand. /compact requests compaction of the context; a short history stays as it is. After the command, you can say what must survive compaction: /compact keep the list of failed tests and the log path.

The session’s own model writes the summary using the conversation already in its prompt cache. This gives it the full conversation to work from and improves the summary. Most of the input is read from the cache. There is no separate summary model. helper.model chooses the model for titles and other small background jobs. Old configurations with compaction.model still work.

The context window and the per-message limits are different constraints. The limits are not set by default. If a limit is set, compaction does not reset it: compaction frees room in the request, but the tokens and time already spent still count, and the limit can stop the work before the task is done.

In an interactive session, Waibee Code may compact the conversation while you are away. This does not run in waibee run or in a subagent. It starts 54 minutes after the last request, only when all of these hold:

  • the context contains at least 200k tokens;
  • context.prompt_cache is not 5m;
  • the model supports prompt caching (Anthropic models and waibee/auto).

It happens at most once per pause. Stop cancels it, and a message sent meanwhile waits until it finishes. The chat then shows a line such as “context shortened while idle 300k → 30k”, with the real token counts. Set context.idle_compact to false to turn it off. It is on by default.

context.prompt_cache applies only to Anthropic models and waibee/auto. It accepts auto, 5m, or 1h:

  • auto keeps the main agent’s cache for an hour.
  • 5m keeps it for five minutes. This is cheaper for short sessions.
  • 1h keeps it for an hour. This is cheaper for long sessions with pauses.

Subagents and waibee run always use five minutes, including with auto or 1h. Changing the setting can rewrite the cache once.

The Context settings are in the Context section of /settings, the web Settings page, and waibee config.

  • Start a new chat (Ctrl+N or /new) between unrelated tasks: a clean context is almost always better than a long one full of unrelated history.
  • Ask a small side question with /btw: the answer appears in a popup and does not go into the history.
  • Hand code exploration to a subagent: it reads files in its own window and returns a short summary without cluttering the main conversation.

For more techniques, see Best practices.