Mikk
Guides

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, getSessionExpiry

Walk — 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
               →  writeSession

Score — rank every function

Each reachable function receives a composite score:

FactorWeight
Graph proximity to seedHigh
Keyword match with taskMedium
Entry point bonusLow
Module boundary matchLow

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:

FormatUse case
claudeClaude — structured XML tags
genericAny LLM — plain text with headers
compactTight 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 1000

Prop

Type

Impact Analysis

Before touching any file, see what you'd break:

mikk context impact src/auth/login.ts
Impact 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:

  • recommendationsafe / review / block
  • violations — live constraint violations
  • impactedNodes — 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:

SectionContent
Tier 1: OverviewProject name, language, framework, entry points, total function/file counts
Tier 2: ModulesEach module's intent, file count, exported API surface, key functions
Tier 3: Context filesDiscovered schemas, configs, data models
Tier 4: ConstraintsAll architectural rules in plain English
Tier 5: DecisionsADRs summarized for AI context

Was this page helpful?

On this page