Skip to content

Context Management

Context is all the information Kodik knows during a conversation. Understanding how it is built helps you get more accurate and consistent results.

Every language model has a context window — the maximum number of tokens (roughly 3/4 of a word each) it can hold at once. This includes the system prompt, conversation history, contents of mentioned files, open-tab information, and tool call results.

The system prompt is assembled per model family: Claude models receive a smaller instruction set (they need less steering, which frees context for your code), GPT, Kimi, and Gemini models receive additions tuned to those families, and all other models use the default instructions. Rules, memory, mode restrictions, and the response-language setting are included for every family; only the generic guidance varies, so the System total in the context-usage menu differs between models.

The context-usage menu estimates these inputs locally and labels the counts with ~. Its System, Tools, and Conversation totals come from that raw estimate; provider-reported billing or cache usage does not scale those categories up or down. In the Conversation section, Agent events count what the model produced — reply text together with the tool calls it emitted — while Tool events are the results that came back: expanding one shows the returned content its token count measures. A background sub-agent’s report appears there as a Sub-agent result.

As the context fills up, response quality degrades well before the formal limit is reached — in practice this is noticeable around 200–300K tokens even on models with larger windows.

On each request Kodik assembles the environment from several sources:

Active editor tabs (<active_tabs>) — files open in visible editor panels right now. Media and binary files are excluded automatically.

Opened tabs (<opened_tabs>) — files open in the editor but not currently in focus. Overlap with active tabs is deduplicated.

Mentions (<user_mentions>) — files, folders, and line ranges explicitly referenced via @ Mentions. Files blocked by .kodikignore are excluded.

Terminal context (<terminal_context>) — terminal output attached via @terminal:<name>.

Rules and instructions — contents of .kodik/rules, global rules, and AGENTS.md are injected into the system prompt.

Memory — entries from .kodik/memories are included in the system prompt.

You can exclude open files from context via the Context tab in the Kodik panel. Excluding a tab also keeps its current selected line range out of automatic chat context. The exclusion lasts for that open editor tab: after you close and reopen the file, it is included again by default.

By default, Kodik automatically compacts the conversation history when approaching the context limit. See Auto-compact for full details.

Before each provider call, including tool continuations, Kodik budgets the finalized request: messages, images, tool schemas, reserved output, and a safety margin. A compatible provider-reported token baseline can make that estimate more accurate. When the request approaches the available input budget, Kodik checkpoints older, complete exchanges and keeps a token-budgeted recent tail verbatim.

If a provider reports that the context is too large, Kodik retries the original request only after compaction succeeds. Compaction itself has bounded retries; if it cannot produce a safe checkpoint, the turn stops with a context-limit error instead of repeatedly sending the oversized request. Automatic and model-switch summarization are optional, and inactivity-based compaction is off by default. A required move from a larger to a smaller context window is the safety exception: even when Automatic summarization or Summarize on model switch is off, Kodik checkpoints with the previous larger model and does not send the new-model turn if that checkpoint fails.

Manual compaction is also available via /compact.

What to include explicitly:

  • Files directly relevant to the task — via @Mentions
  • Line ranges to pinpoint the exact area of interest
  • Terminal output with the error or build result

What to exclude:

  • Open but irrelevant tabs — via the Context panel
  • Files that should not reach the agent — via .kodikignore

Rules and instructions (.kodik/rules) occupy permanent space in the system prompt, so keep them concise and current.

Context from a current conversation is not automatically carried into a new session. For continuity, use:

  • Rules — persistent project instructions
  • Memory — accumulated facts about the project
  • AGENTS.md — architecture and conventions
  • Codebase indexing — semantic search over code without manually pointing to files
  • Start a fresh session when switching to unrelated tasks — this clears context and reduces the chance of confusion.
  • Use MCP servers to pull context from external knowledge bases.
  • Screenshots can be passed as context for models that support image input.