How to organize context for AI coding
Build better AI coding context with entry points, callers, tests, constraints, and handoffs. Includes a practical context packet and repair rules.
The quick answer
Organize context around the decision: include the goal, implementation, callers, tests, and constraints. Keep paths and anchors so changed facts can be refreshed. Expand the packet when a concrete dependency appears.
Choose context for the next decision
A response-field change and a timeout investigation need different source. State the behavior first, then choose code explaining it and constraints that can invalidate the patch.
For a response field, inspect builder, callers, schema, and tests. For a timeout, begin with the failing request, handler, and boundary where work stalls.
| Task | First sources |
|---|---|
| API response | Handler, type, consumers, serialization test |
| UI interaction | Component, event handler, interaction test |
| Data bug | Failing input, transformation, invariant test |
| Refactor | Public API, callers, behavior tests |
Create an actionable packet
Use source anchors instead of an untraceable summary. Include known facts, constraints, and uncertainty. A summary guides a refresh; it does not replace changed source.
Goal: optional displayName in profile responses.
Entry: profile handler and serializer.
Consumers: account menu and settings.
Constraint: older clients may omit displayName.
Verify: serializer tests and both UI states.
Unknown: whether another import exposes a second serializer; inspect if callers indicate it.Keep invariants and necessary dependencies
Keep authorization, compatibility, and data invariants governing the change. Leave out old logs and unrelated architecture unless needed. A small packet missing a required invariant is expensive to repair.
- Actual failure or desired behavior.
- Implementation and relevant callers.
- Tests defining expected behavior.
- Permission and compatibility constraints.
- Uncertain or stale facts identified.
Refresh changed facts and repair gaps
After an edit, refresh affected regions and dependencies. After a branch or configuration change, rebuild relevant context. If the agent changes the wrong layer, add the failing input's call path. If a consumer breaks, add its contract.
Use Mikie for focused context, then assess whether the selected lines support the task. Resolve demonstrated gaps before editing.
- Important facts have sources.
- Required callers and tests are present.
- Code matches the current revision.
- No credentials or private configuration values appear.
The serializer changed. Refresh it and its tests. Reuse client constraints unless current source contradicts them. Expand if the updated signature exposes another caller.Put it into practice
- Define behavior and proof.
- Find entry point, callers, and tests.
- Create an anchored context packet.
- Refresh changed facts and concrete dependencies.
| Area | What it means | Who controls it |
|---|---|---|
| Selection | Include facts affecting this change. | Your workflow |
| Ordering | Put the goal and constraints first. | Your workflow |
| Freshness | Refresh changed source and assumptions. | Your workflow |
| Dependencies | Relevant callers and invariants remain necessary. | The provider or measurement |
| Capacity | Context management stays within the model's window. | The provider or measurement |
How Mikie helps
Mikie compiles a bounded, line-anchored context packet through local MCP tools. Inspect selected sources and request focused follow-ups for gaps. Current source and verification remain the authority.
Sources
- OpenAI ↗
Goals, relevant context, output requirements, and task boundaries.
- Anthropic ↗
What occupies a context window and why cached context still occupies it.
- Anthropic ↗
Verification, focused sessions, /clear, and /compact.
Provider plans and prices can change. Source dates show when this guide was checked. How Mikie measures results.
Common questions
Should I paste the entire repository?
Start with relevant code and constraints. Expand for real dependencies; a complete packet can be smaller than a repository dump.
What is a context packet?
A focused set of task facts, source anchors, constraints, and checks for the next coding decision.
When should context be refreshed?
When relevant source, branch, configuration, or assumptions change. A handoff is guidance rather than proof of current code.
Put better context to work.
Keep your coding agent. Give it a clearer view of the code it needs.
Set up Mikie →