← Back to Index

Lesson 2

Context Management

What This Lesson Is About

Every time you send a message, Kiro assembles a context window - the complete set of information the model can see when generating a response. Understanding what goes in, in what order, and what happens when space runs out is the difference between Kiro working with full awareness vs. working half-blind.

What Goes Into the Context Window

Here's everything that can end up in the context, roughly in the order Kiro assembles it:

Context Window Assembly Order 1. System prompt Fixed, you can't change this 2. Always-on steering files .kiro/steering/ (inclusion: auto) 3. Global steering files ~/.kiro/steering/ (inclusion: auto) 4. Active file context Your currently active editor tab 5. fileMatch steering (if triggered) Activated by files entering context 6. Conversation history Previous messages in this session 7. Your current message What you just typed 8. Explicit context you attached #File, #Folder, #Problems, etc. 9. Manual steering (if invoked) / or # invoked steering 10. Tool results Files read, commands run, searches Assembly order Always present Conditional Per-message Agent-driven

The context window is assembled top-to-bottom. Items higher in the stack are always present; lower items are conditional or generated during the session.

Not everything here is present every time. Only items 1, 2 (if they exist), 6, and 7 are guaranteed. Everything else depends on what's active, what you've referenced, and what the agent has done.

Context Keys: The # Menu

When you type # in the chat input, you get a menu of things you can explicitly pull into context. These are the built-in context keys:

Context KeyWhat it adds
#FileContents of a specific file you select
#FolderFile tree structure of a folder (not file contents)
#ProblemsCurrent diagnostics/errors from your editor
#TerminalRecent terminal output
#Git DiffYour current uncommitted changes
Manual steering filesContent of any inclusion: manual steering file

These are additive - each one you select injects more content into the context for that message. Choose deliberately; each one uses tokens.

The Token Budget

The context window has a fixed size (determined by the model - up to 1M tokens for the latest Claude models, though some models still use 200K). Everything listed above competes for space in that window. This is why always-on steering should be concise: it takes up space on every single message, leaving less room for the actual work.

Here's a rough sense of the cost:

ContentTypical token cost
System prompt~3,000 - 5,000 tokens (fixed)
A steering file200 - 2,000 tokens per file
A source code file500 - 5,000 tokens (depends on size)
Conversation history (10 exchanges)5,000 - 20,000 tokens
#Git Diff (moderate changes)1,000 - 10,000 tokens

You don't need to count tokens manually. The point is: context is a finite resource, and everything in the diagram above shares it.

Ad

What Happens When Space Runs Out: Compaction

As a conversation gets long, the accumulated history eventually approaches the context window limit. When this happens, Kiro performs compaction - it summarises older parts of the conversation into a condensed form, freeing up space for new content.

What gets compacted:

What is never compacted:

Practical implication: After a long session, Kiro may lose the details of files it read 20 messages ago. If you notice it making assumptions about code it read earlier, it may be working from a compacted summary. Referencing the file again (with #File or asking Kiro to re-read it) brings the full content back into context.

The Active Editor File

Kiro automatically includes your currently active editor tab as context. You've seen this in our sessions - the <ACTIVE-EDITOR-FILE> section that appears in the environment context.

This is significant because:

Files that are merely open in background tabs are not included. Only the active (focused) tab counts.

Split editor layouts

If you have two files side-by-side in a split layout, only the pane with focus (the one with the blinking cursor) counts as active. The other pane is treated the same as a background tab - Kiro sees its name in the open files list but not its content.

The "unwanted active file" problem

The active file is determined by whether an editor pane has focus. If you click into the chat input to type your message, the editor loses focus and Kiro reports no active file - meaning no file content is sent.

So in practice: if you click into the chat panel before sending, no active file is included. The active file only gets sent if you had an editor pane focused when you triggered the message (e.g. via a keyboard shortcut that doesn't move focus from the editor).

This makes it less intrusive than it might sound - but it's still worth being aware of, especially if you use keyboard shortcuts that keep editor focus.

Open Editor Files vs Active File

Kiro also receives a list of the names of files you have open in editor tabs (the <OPEN-EDITOR-FILES> list). This gives Kiro awareness of what you're working on - useful for understanding your context - but it does not include their contents. Only the active file's content is injected.

You can't see the raw context Kiro receives - there's no "show context" panel in the IDE. But you can infer its effect: Kiro may reference files you have open without you explicitly mentioning them, because it can see their names in this list.

How This Connects to Steering

Now you can see the full picture from Lesson 1:

This is why the inclusion modes exist: they're tools for managing a scarce resource (context window space) efficiently.

Practical Tips

Your Tangible Win

You now understand the full lifecycle of context in Kiro: what goes in, what triggers conditional content, what happens in long sessions, and how to manage it. You can make informed decisions about where to put information (steering vs. chat vs. explicit references) based on how long it needs to persist and how often it's relevant.

Quiz

Your always-on steering files total 3,000 tokens. In a session with 50 messages, how many tokens have those steering files consumed in total?

3,000 (loaded once at session start)
150,000 (3,000 × 50 messages)
3,000 on input, 0 on output

You're in a long session and Kiro makes wrong assumptions about a file it read 30 messages ago. What's the most likely cause?

A bug in Kiro
The file was modified since it was read
The full file content was compacted into a summary to free up context space

You have 5 files open in editor tabs. How many of their contents does Kiro see?

All 5 - open files are included
1 - only the active (focused) tab's content is included
0 - Kiro only sees files you explicitly reference