AI Context Guide
How Mikk builds token-budgeted, graph-traced context payloads — and how to tune them for your AI workflow.
The core problem with AI + codebases
Dumping your entire codebase into an LLM context window is wasteful and ineffective. Mikk solves this by tracing only the functions your task actually touches — giving AI assistants the exact context they need, nothing more.
How Context Building Works
The 5-Step Algorithm
Seed — find entry points
Mikk matches your task description against function names, descriptions, and module intents stored in mikk.lock.json.
mikk context for "Fix the session expiry bug"
# Seeds: validateToken, refreshSession, getSessionExpiryWalk — BFS graph traversal
From each seed function, Mikk traces the call graph outward using BFS. Configurable with --hops (default: 2 for CLI, 4 for MCP).
validateToken → parseJWT → getKeystore
→ checkExpiry
refreshSession → validateToken
→ writeSessionScore — rank every function
Each reachable function receives a composite score:
| Factor | Weight |
|---|---|
| Graph proximity to seed | High |
| Keyword match with task | Medium |
| Entry point bonus | Low |
| Module boundary match | Low |
Budget — greedy knapsack
Functions are packed into the context payload in score order until the token budget is exhausted.
Each function's token cost is pre-computed from its source body in mikk.lock.json.
Format — provider-specific output
The payload is formatted for your target AI:
| Format | Use case |
|---|---|
claude | Claude — structured XML tags |
generic | Any LLM — plain text with headers |
compact | Tight budgets — minimal whitespace, no source bodies |
Strict Mode
Set strict: true on mikk_query_context for high-precision context — only functions where the task keywords explicitly appear in name, purpose, or params are included.
mikk_query_context({
question: "How does JWT validation work?",
strict: true,
autoFallback: true, // retry with balanced mode if strict returns empty
})Use strict mode when:
- The query is very specific (a named function, a bug in a known path)
- You want to avoid hallucinated context from loosely-related functions
Use balanced mode (default) when:
- Exploring an unfamiliar area of the codebase
- Building context for a large refactor
CLI Usage
# Basic context for
mikk context for "How does authentication work?"
# With custom token budget
mikk context for "Refactor the payments module" --tokens 8000
# Claude-formatted context, 3 hops deep
mikk context for "Debug the login flow" --provider claude --hops 3
# Compact format for tight context windows
mikk context for "What does parseToken do?" --provider compact --tokens 1000Prop
Type
Impact Analysis
Before touching any file, see what you'd break:
mikk context impact src/auth/login.tsImpact analysis for: src/auth/login.ts
Direct dependents (3):
src/api/routes.ts (imports: login)
src/auth/session.ts (imports: login, validateToken)
tests/auth/login.test.ts (imports: login)
Transitive blast radius (8 files):
src/api/middleware.ts
src/api/user.ts
...
Estimated impact: HIGH (8 files, 2 public API consumers)Pre-Edit Validation
For the most comprehensive safety check before any edit, use mikk_before_edit via MCP:
mikk_before_edit({ files: ["src/auth/login.ts"] })Returns:
recommendation—safe/review/blockviolations— live constraint violationsimpactedNodes— classified blast radius (critical / high / medium / low)circularDeps— circular dependency warnings
The Intent Engine also checks if your changes have an explicit intent marker and runs auto-correction on common issues.
Tuning Tips
claude.md Structure
The generated claude.md contains tiered architecture information, kept within a 12,000 token budget:
| Section | Content |
|---|---|
| Tier 1: Overview | Project name, language, framework, entry points, total function/file counts |
| Tier 2: Modules | Each module's intent, file count, exported API surface, key functions |
| Tier 3: Context files | Discovered schemas, configs, data models |
| Tier 4: Constraints | All architectural rules in plain English |
| Tier 5: Decisions | ADRs summarized for AI context |
Was this page helpful?
Core Concepts
The Mesh, Merkle-tree hashing, AI Context Builder, Intent Engine, Safety Gates, Decision Engine, Risk Engine, and Auto-Correction — the foundational primitives of Mikk.
VS Code Extension
The Mikk VS Code extension brings codebase intelligence directly into your editor — module tree, impact analysis, contract status, and MCP integration.