| layout | default |
|---|---|
| title | Chapter 4: Context and Indexing |
| nav_order | 4 |
| parent | Roo Code Tutorial |
Welcome to Chapter 4: Context and Indexing. In this part of Roo Code Tutorial: Run an AI Dev Team in Your Editor, you will build an intuitive mental model first, then move into concrete implementation details and practical production tradeoffs.
In large repositories, quality depends on context precision. This chapter covers how to manage context and indexing strategy in Roo workflows.
Relevance beats volume.
Passing too much context increases token cost and decreases reasoning quality.
flowchart LR
A[Task Goal] --> B[Index or Search Relevant Areas]
B --> C[Curated Context Set]
C --> D[Mode Execution]
D --> E[Validation Results]
E --> F[Next Context Slice]
| Situation | Recommended Slice |
|---|---|
| single bugfix | one module + failing tests/logs |
| feature iteration | active files + adjacent interfaces |
| migration | architecture map + staged module batches |
| production incident | runtime logs + impacted service paths |
Use indexing/search to discover candidates, then manually constrain final context set.
Good pattern:
- broad discovery
- narrow target selection
- bounded execution
- evidence-driven expansion if needed
Roo docs include context and tool usage surfaces. Regardless of mechanism, include:
- exact files
- concrete errors/logs
- expected behavior
- validation command
This prevents speculative edits.
Context discipline improves:
- response latency
- token spend
- patch accuracy
- reviewer confidence
Treat context selection as an engineering activity, not a UI action.
Symptom: unrelated edits and slow loops.
Fix: remove low-relevance files and enforce explicit scope.
Symptom: shallow fixes that ignore true root cause.
Fix: add targeted interface/dependency files and concrete error traces.
Symptom: mode transitions lose constraints.
Fix: include concise state summary when switching modes.
You now have a context/indexing model for large repos:
- discover broadly, execute narrowly
- tie context to validation evidence
- maintain continuity across mode transitions
Next: Chapter 5: Checkpoints and Recovery
Use the following upstream sources to verify context and indexing implementation details while reading this chapter:
src/services/glob/list-files.ts— implements repository file listing and glob filtering used to build the file tree that Roo Code sends to the model as workspace context.src/core/context-management/— contains context window management utilities that truncate, slice, and prioritize messages to stay within model token limits.
Suggested trace strategy:
- trace how
list-files.tsbuilds file manifests that feed into context window construction - review context-management utilities to understand truncation strategies when context grows large
- look at
src/shared/context-window-utils.tsfor token-limit calculations applied before each request
flowchart LR
A[Workspace files] --> B[list-files.ts glob scan]
B --> C[Context window manager]
C --> D[Truncated context sent to model]