If you're burning tokens on full file reads and massive grep results, this MCP gives you compressed alternatives. It indexes your codebase and exposes tools like smart_read (outline or focused chunks), smart_search (ranked, limited results), and smart_context (curated multi-file context). The real win is task checkpoints that persist between sessions so you don't re-explain the same context. Ships with workflow metrics showing 85-90% token reduction on debugging and refactoring tasks, though that requires multi-file work where you actually need the index. For single-file edits or when you already know what to touch, native tools are faster. Includes a reactive file watcher, semantic search via local embeddings, and declarative playbooks that chain multiple operations in one call.
MCP server that reduces AI agent token usage by up to 90% through intelligent context compression (measured on this project).
An MCP (Model Context Protocol) server that provides specialized tools for reading, searching, and managing code context efficiently. Instead of loading full files or returning massive search results, it compresses information while preserving what matters for the task.
Real metrics from production use:
Workflow-level savings:
Real adoption in non-trivial tasks:
smart_read (850+ uses), smart_search (280+ uses), smart_shell (220+ uses)See Workflow Metrics and Adoption Metrics for details.
1.20.0Minor release. Same 20 tools, but several gain new parameters and response fields. SQLite schema bumps 7 → 8 (new read_cache table; auto-migrates on first run). Global memory DB schema bumps 1 → 2 (new noise_hints table). Zero new runtime dependencies.
tokenBudget across tools. smart_read, smart_read_batch, smart_context, smart_turn (start + end) and smart_resume now accept tokenBudget: number | { id?, maxTokens, shared? }. When shared:true (or id set), the budget is reused across calls inside the same task — so a multi-step agent flow can stay under a hard token ceiling without per-call bookkeeping. Responses include taskBudget, remainingBudget, and budgetDetails (scope, actions, degraded mode) when the budget actually changed the output.smart_search search modes. New mode: 'needle' | 'balanced' | 'semantic' (default balanced). needle = literal exact only (no regex / no term expansion) — kills noise on debug queries. balanced = exact + regex + term expansion. semantic = exact-first plus the local semantic block only when exact signal is weak. The previous semantic: true flag remains as a legacy alias for mode: 'semantic'. Default maxFiles tightened 15 → 5. New maxTokens caps the whole response and compacts intelligently (matches first, then diagnostics, then semantic block). Per-file ranking is now inspectable via matchedBy, boostSource, scoreBreakdown, whyRanked. Response also returns hasMore / totalFiles / nextSuggestedMaxFiles and actionable suggestions when the query is too broad or empty.smart_read persistent cache + budget-aware full degradation. New SQLite read_cache table keyed by (filePath, mode, selector, content_hash). Second read of an unchanged file is virtually free. Mode full is now an explicit last resort: if a tokenBudget/maxTokens is set, it degrades to lighter modes first (outline → signatures → truncated) and reports the real mode used in fullMode + budgetDetails. New clearReadCachePersistent + GC integration in runStorageMaintenance.smart_turn simple-task skip heuristic. When the prompt is short (≤ 40 chars after normalization), classified as a simple task, and no session/task is pinned, smart_turn(start) now returns skipSmartTurn: true with recommendedPath.mode='simple_task_skip' instead of paying the full orchestration cost. Saves continuity-resolution overhead on trivial prompts. minimal verbosity additionally compacts summary/refreshedContext to the fields agents actually consume.global_memory noise hints. Per-project, scrubbed noise telemetry persisted to ~/.devctx/global.db (noise_hints table). New actions noise_stats and noise_reset (full or via query). Lets smart_search learn which queries the agent already discovered to be noisy in a given repo and adjust ranking, without ever leaking content.evals/kpi-baseline.js + evals/kpi-utils.js aggregate harness.js and realworld-eval.js runs into a single JSON snapshot with top-5 precision, recall, reread task/call rate, and per-task-size buckets (short / long). Persists kpi-baseline-latest.json for regression detection across releases. New test suite tests/eval-kpis.test.js.1.19.0 (still current)Five-step quality jump executed as sequential commits with full dogfooding. MCP grows from 18 → 20 tools, +68 tests, zero new dependencies, suite green at 882/883 (1 skipped).
smart_playbook (new tool). Declarative composite workflows that run multiple smart_* tools in a single MCP call. Five built-in playbooks ship with the package: preflight-merge (review + affected tests + checkpoint), debug-flake (last failure + curated debug context + affected), refactor-safe (curated context + affected + checkpoint), doc-sync (ADR search + docs context), ramp-up (status + doctor + ADR overview). Project-level overrides via .devctx/playbooks/*.{yaml,json} with {{args.X}} interpolation, when / label / stopOnFail / dryRun. Tool allowlist restricted to smart_*. Zero deps: built-in minimal YAML parser.fs.watch (native, recursive, debounced 600ms + batch flush every 2s) keeps the symbol index hot between calls. Filters .git, node_modules, .devctx, dist, build, lockfiles, .min.*, .map, .snap, and non-indexable extensions. Stats surface in smart_status (enabled, flushes, eventsObserved, filesReindexed, filesRemoved, errors, lastFlushAt, pending). Opt-out via DEVCTX_WATCH_INDEX=false. Wired to MCP shutdown for clean close + final flush.decorators: ["dataclass", ...]), async def (kinds async-function / async-method), TypeAlias and TypeVar / NewType / ParamSpec / TypeVarTuple as kind="type", and respects class indent for accurate scope. Go now captures methods with receiver type as parent, interfaces as kind="interface", top-level const / var. src/parsers/registry.js exposes registerParser / getParser so future tree-sitter parsers can plug in without touching index.js. INDEX_VERSION bumped 6 → 7 (auto-reindex).smart_search. Opt-in semantic: true (with semanticLimit) returns a semantic: { embedder, symbols[], files[] } block ranked by hashing/TF-IDF embeddings (256-dim, FNV-1a buckets, L2-normalized, cosine similarity, <5ms). Default behavior unchanged. Pluggable embedder interface (id, dimensions, embed, similarity) ready to swap in ONNX/transformers without touching callers.global_memory (new tool, opt-in). Cross-project memory persisted to ~/.devctx/global.db (override via DEVCTX_GLOBAL_DB, gated by DEVCTX_GLOBAL_MEMORY=true). Stores canonical decisions, recurring patterns, playbook drafts, and notes across repos. Content scrubbed for likely API keys / bearer tokens / JWT / PEM private keys / AWS / OpenAI / GitHub / Slack / Google API / DB URLs / emails / home paths before persistence. Project paths stored as FNV-1a hash, not raw path. Recall uses the local hashing/TF-IDF embedder for semantic ranking.See CHANGELOG.md for the full v1.20.0 + v1.19.0 entries.
See CHANGELOG.md for full release history.
Use devctx when:
Skip devctx when:
Honest verdict from real users:
"The MCP shines in long, multi-session tasks or when you don't know the codebase. For contained refactors where you already know what to touch, native tools are just as fast or faster. The real value was
smart_read(outline)for the initial analysis and checkpoints to not lose the thread between sessions."
The 90% token savings are real, but they require the right task type to materialize.
AI agents waste tokens in three ways:
This MCP solves all three by providing tools that return compressed, ranked, and cached context.
📋 Official Prompt (Copy & Paste)
⚡ Ultra-Short Version
|
When to use: Agent read large files with Read, used Grep repeatedly, or you see no devctx tools in a complex task.
Why this happens: Task seemed simple, no index built, native tools appeared more direct, or rules weren't strong enough.
Use if: You work in Cursor IDE and want the best balance of guidance and flexibility.
Workflow:
1. Install MCP → rules auto-load
2. Start task → agent reads .cursorrules
3. Agent decides when to use devctx
4. Use /prompt commands to force usage if needed
Automaticity: Medium by default. Medium-High if you use the assisted launcher ./.devctx/bin/cursor-devctx for task-runner workflows.
Use if: You want highest session continuity with automatic context recovery.
Workflow:
1. Install MCP + hooks
2. Start task → hook auto-triggers smart_turn(start)
3. Work with devctx tools
4. End task → hook auto-triggers smart_turn(end)
Automaticity: High (with hooks) - Can auto-trigger smart_turn on session start/end.
Use if: You prefer terminal-based workflows or scripting.
Workflow:
1. Install MCP
2. Rules embedded in prompts
3. Agent reads rules, decides when to use
4. Explicit instructions work best
Automaticity: Low-Medium - Rules are visible but require explicit prompting.
| Client | Automaticity | Best For |
|---|---|---|
| Cursor | Medium | Complex IDE tasks |
| Claude Desktop | High (hooks) | Session continuity |
| Codex CLI | Low-Medium | Terminal workflows |
| Qwen Code | Low-Medium | Alternative to Cursor |
Important: Agent always decides whether to use devctx. Rules increase probability, but don't guarantee it.
If you want a more repeatable path: use the task runner or the assisted launcher instead of relying on rules alone. See Task Runner Workflows.
📖 Full setup: Client Compatibility
Key point: The MCP doesn't intercept prompts automatically. You need to tell the agent to use it.
/prompt use-devctx
[Your task here]
Other prompts:
/prompt devctx-workflow - Full workflow/prompt devctx-preflight - Build index + start sessionUse smart_turn(start) to recover context, then [your task]
For a more guided CLI path:
smart-context-task task --prompt "your task"
smart-context-task implement --prompt "your task"
smart-context-task continue --session-id <session-id>
smart-context-task doctor
Agent should use devctx for complex tasks if rules are active:
.cursorrulesCLAUDE.mdAGENTS.mdBut: Agent decides based on task complexity.
| Scenario | Command |
|---|---|
| Start new task | /prompt devctx-workflow |
| Guided terminal workflow | smart-context-task task --prompt "..." |
| Guided implementation | smart-context-task implement --prompt "..." |
| Continue previous task | smart_turn(start) and continue |
| Continue via runner | smart-context-task continue --session-id <id> |
| Force MCP usage | /prompt use-devctx |
| First time in project | /prompt devctx-preflight |
| Trust automatic rules | Just describe your task normally |
Before starting complex tasks, ensure:
# 1. MCP is installed
npm list -g smart-context-mcp # or check your MCP client
# 2. Build the index (IMPORTANT)
npm run build-index
# or tell the agent: "Run build_index tool"
# 3. Rules are active
# - Cursor: .cursorrules exists
# - Claude Desktop: CLAUDE.md exists
# - Other clients: AGENTS.md exists
# 4. Start with smart_turn
# Tell the agent: "Use smart_turn(start) to begin"
Copy-paste to agent (first time):
Run build_index, then use smart_turn(start) to begin this task.
Without index:
smart_search returns unranked resultssmart_context can't build optimal contextWith index:
smart_search ranks by relevancesmart_context includes related filesWhen to rebuild:
.devctx/)smart_turn(start)For non-trivial tasks (debugging, review, refactor, testing, architecture), the optimal flow is:
0. build_index (if first time in project)
↓ enables search ranking and context quality
1. smart_turn(start, userPrompt, ensureSession=true)
↓ recovers previous context, classifies task, checks repo safety
2. smart_context(...) or smart_search(intent=...)
↓ builds context or finds relevant code
3. smart_read(mode=outline|signatures|symbol)
↓ reads compressed, cascades to full only if needed
4. [work: make changes, analyze, review]
5. smart_shell('npm test')
↓ verifies changes safely
6. smart_turn(end, event=milestone|blocker|task_complete)
↓ checkpoints progress for recovery
Why start with smart_turn?
When to skip smart_turn:
smart-context-taskIf you want the same lifecycle packaged into named workflows, use the task runner:
smart-context-task task --prompt "inspect the auth flow and continue the bugfix"
smart-context-task implement --prompt "add a token guard to loginHandler"
smart-context-task review --prompt "review the latest diff"
smart-context-task doctor
This layer runs the same smart_turn(start) / context / checkpoint flow, but adds:
smart_context or smart_search)smart_doctortask_runner quality signalsFor the full command set and client-specific usage, see Task Runner Workflows.
This MCP does not intercept your prompts magically. Here's what actually happens:
smart_turn(start)"smart_turn({ phase: 'start', userPrompt: '...', ensureSession: true })smart_search(intent=debug) for error locationsmart_read(mode=symbol) for specific functionsmart_shell('npm test')smart_turn(end) to persist progressKey points:
smart_turn(start) is recommended entry point for non-trivial tasksTools (20): Efficient alternatives to built-in operations
smart_read / smart_read_batch - Compressed file reading (outline, signatures, symbol, explain)smart_search - Intent-aware code search with ranking, ADR filtering, and opt-in semantic re-ranksmart_context - One-call context builder with graph + paths: { from, to } traversalsmart_test - Affected tests via graph + sandboxed runner + persisted last_failuresmart_review - Code review preflight: diff + callers + heuristic findingssmart_playbook - Declarative composite workflows (5 built-in: preflight-merge, debug-flake, refactor-safe, doc-sync, ramp-up)smart_shell - Safe diagnostic commands (TAP/git-log/diff compression)smart_turn / smart_resume - Session persistence + nextActions[] machine-readable plansmart_summary / smart_status / smart_doctor / smart_metrics / smart_editglobal_memory - Opt-in cross-project memory in ~/.devctx/global.db (scrubbed, semantic recall)build_index / warm_cache / git_blame / cross_projectRules (5 profiles): Task-specific workflows
Storage (.devctx/): Local context database
index.json - Symbol index (functions, classes, imports, ADRs, sections) — INDEX_VERSION 7state.sqlite - Sessions, metrics, patterns, task handoffs, test failures, explain cache (Node 22+, node:sqlite)metrics.jsonl - Opt-in legacy file, only when DEVCTX_METRICS_FILE=path.jsonl is set~/.devctx/global.db - Cross-project memory (opt-in via DEVCTX_GLOBAL_MEMORY=true)What gets persisted:
When it's consulted:
smart_turn(start) - Recovers task checkpointsmart_context - Uses patterns for predictionsmart_summary - Gets task summaryWhat is NOT persisted:
Limitations:
smart_turn (not automatic).devctx/ is local)Honest truth: Task context persistence is opt-in via agent behavior, not automatic via client interception.
Best case scenario:
Typical scenario:
Worst case scenario:
You can check: npm run report:metrics shows actual tool usage and measured smart_turn quality signals.
What we improve:
What we don't guarantee:
The benefit: Agents work with better input, but output quality still depends on agent capability and task complexity.
Honest claim: We provide better context (more relevant, less noise), which can help agents respond more efficiently in complex tasks when the workflow is followed.
What's proven: 90% token savings (measured across 3,666 operations).
What's inferred: Quality improvement (better input → potentially better output, but not explicitly measured).
What we don't control: Agent correctness, task success, response accuracy.
// 1. Start session
smart_turn({
phase: 'start',
userPrompt: 'TypeError: Cannot read property "user" of undefined',
ensureSession: true
})
// → Recovers: "Last worked on auth system, checked validateToken()"
// 2. Find error
smart_search({
query: 'TypeError user undefined',
intent: 'debug'
})
// → Returns: src/auth.js (error handling), src/routes/login.js (recent change)
// 3. Read structure
smart_read({
filePath: 'src/routes/login.js',
mode: 'signatures'
})
// → Returns: loginHandler, validateCredentials, generateToken
// 4. Extract failing function
smart_read({
filePath: 'src/routes/login.js',
mode: 'symbol',
symbol: 'loginHandler'
})
// → Returns: Full function code (250 tokens vs 5K for full file)
// 5. Reproduce error
smart_shell({ command: 'npm test -- login.test.js' })
// → Returns: Test failure output
// [Fix bug]
// 6. Verify fix
smart_shell({ command: 'npm test -- login.test.js' })
// → Returns: Tests pass
// 7. Checkpoint
smart_turn({
phase: 'end',
event: 'milestone',
summary: 'Fixed TypeError in loginHandler - null check added',
nextStep: 'Consider adding integration tests'
})
Token usage: 150K → 15K (90% savings)
// 1. Start session
smart_turn({
phase: 'start',
userPrompt: 'Review PR #123 - Add JWT refresh token support',
ensureSession: true
})
// 2. Get changed files context
smart_context({
diff: true,
detail: 'balanced'
})
// → Returns: Changed files with graph, prioritizes API surface
// 3. Review API surface
smart_read({
filePath: 'src/auth.js',
mode: 'signatures'
})
// → Returns: Exported functions only
// 4. Check implementation
smart_read({
filePath: 'src/auth.js',
mode: 'symbol',
symbol: 'refreshToken'
})
// 5. Check authorship
git_blame({
mode: 'symbol',
filePath: 'src/auth.js'
})
// → Returns: Who wrote each function
// 6. Verify tests
smart_shell({ command: 'npm test' })
// 7. Checkpoint
smart_turn({
phase: 'end',
event: 'milestone',
summary: 'PR #123 approved - JWT refresh implemented correctly',
nextStep: 'Monitor production metrics after deploy'
})
Token usage: 200K → 25K (87% savings)
// 1. Start session
smart_turn({
phase: 'start',
userPrompt: 'Extract authentication logic into separate service',
ensureSession: true
})
// 2. Build dependency graph
smart_context({
entryFile: 'src/routes/login.js',
detail: 'balanced'
})
// → Returns: Dependencies, imports, exports
// 3. Understand current structure
smart_read({
filePath: 'src/routes/login.js',
mode: 'signatures'
})
// 4. Extract target function
smart_read({
filePath: 'src/routes/login.js',
mode: 'symbol',
symbol: 'validateCredentials'
})
// 5. Check authorship
git_blame({
mode: 'symbol',
filePath: 'src/routes/login.js'
})
// [Refactor: create src/services/auth.js, move logic]
// 6. Verify tests still pass
smart_shell({ command: 'npm test' })
// 7. Checkpoint
smart_turn({
phase: 'end',
event: 'milestone',
summary: 'Extracted auth logic to AuthService - tests pass',
nextStep: 'Update other routes to use AuthService'
})
Token usage: 180K → 20K (89% savings)
// 1. Start session
smart_turn({
phase: 'start',
userPrompt: 'Write tests for validateToken function',
ensureSession: true
})
// 2. Find existing test patterns
smart_search({
query: 'validateToken test',
intent: 'tests'
})
// → Returns: Existing test files, test patterns
// 3. Read function to test
smart_read({
filePath: 'src/auth.js',
mode: 'symbol',
symbol: 'validateToken'
})
// 4. Understand dependencies
smart_context({
entryFile: 'src/auth.js',
detail: 'minimal'
})
// → Returns: Dependencies (jwt, bcrypt, db)
// [Write test]
// 5. Run tests
smart_shell({ command: 'npm test -- auth.test.js' })
// 6. Checkpoint
smart_turn({
phase: 'end',
event: 'milestone',
summary: 'Added 5 tests for validateToken - all pass',
nextStep: 'Add edge case tests for expired tokens'
})
Token usage: 120K → 12K (90% savings)
// 1. Start session
smart_turn({
phase: 'start',
userPrompt: 'Understand how authentication works in this codebase',
ensureSession: true
})
// 2. Get high-level overview
smart_context({
detail: 'minimal'
})
// → Returns: Project structure, key modules
// 3. Find auth-related code
smart_search({
query: 'authentication authorization',
intent: 'explore'
})
// → Returns: Ranked files by relevance
// 4. Review API surface
smart_read({
filePath: 'src/auth.js',
mode: 'signatures'
})
// → Returns: Exported functions only
// 5. Check cross-project patterns (if monorepo)
cross_project({
mode: 'search',
query: 'AuthService'
})
// → Returns: Similar auth patterns in other projects
// 6. Checkpoint
smart_turn({
phase: 'end',
event: 'milestone',
summary: 'Auth uses JWT with 1h expiry, refresh tokens in Redis',
nextStep: 'Document auth flow in architecture.md'
})
Token usage: 300K → 30K (90% savings)
These are the essential tools you should understand first:
Read files in compressed modes instead of loading full content.
// Outline mode: structure only (~90% savings)
{ filePath: 'src/server.js', mode: 'outline' }
// Signatures mode: exported API only
{ filePath: 'src/api.js', mode: 'signatures' }
// Symbol mode: extract specific function/class
{ filePath: 'src/auth.js', mode: 'symbol', symbol: 'validateToken' }
Modes: outline, signatures, symbol, range, full
When to use: Any time you need to understand file structure without reading everything.
Intent-aware code search with ranked, deduplicated results and index boosting.
// Find where a symbol is used
{ query: 'validateToken', intent: 'implementation' }
// Debug intent: prioritizes errors, logs, exception handling
{ query: 'authentication error', intent: 'debug' }
// Limit results
{ query: 'UserModel', maxFiles: 5 }
Intents: implementation, debug, tests, config, docs, explore
Best for: Finding symbol definitions/usages, understanding call chains, locating implementations.
NOT ideal for: Exact string matching (use Grep), finding files by name (use Glob), broad multi-word queries (generates noise — results include a hint when >30 files match).
One-call context builder: search + read + graph expansion.
{
task: 'Fix login authentication bug',
detail: 'balanced' // minimal | balanced | deep
}
Returns relevant files with compressed content, symbol details, and relationship graph.
Smart pattern detection: Automatically detects literal patterns in your task (TODO, FIXME, /**, console.log, debugger) and prioritizes them in search results.
When to use: Starting a new task and need comprehensive context.
Build a symbol index for the project (functions, classes, imports).
{ incremental: true } // Only reindex changed files
When to use: Once after checkout, or after major changes. Improves search ranking and context relevance.
Inspect token savings and usage statistics.
{ window: '24h' } // or '7d', '30d', 'all'
When to use: Verify the MCP is working and see actual savings.
These tools provide specialized capabilities for specific workflows:
Maintain compressed task state across sessions.
// Save checkpoint (flat API - recommended)
{ action: 'update', goal: '...', status: 'in_progress', nextStep: '...' }
// Or nested format (backward compatible)
{ action: 'update', update: { goal: '...', status: 'in_progress', nextStep: '...' }}
// Resume later
{ action: 'get' }
Compresses task context to ~100 tokens (goal, status, decisions, blockers). Critical for long tasks. Supports both flat and nested formats.
When git hygiene or SQLite health affects local state, responses also surface mutationSafety, repoSafety, degradedMode, and storageHealth.
Run one operational preflight across repo hygiene, SQLite health, compaction, and legacy cleanup.
smart_doctor({})
smart_doctor({ verifyIntegrity: false })
Use this before release, after long-lived local usage, or whenever .devctx/state.sqlite looks suspicious.
Display current session context with progress visibility.
{ format: 'detailed' } // Full formatted output with emojis
{ format: 'compact' } // Minimal JSON
Shows goal, status, recent decisions, touched files, pinned context, and progress stats. Updates automatically with each MCP operation.
When repo safety or SQLite health affects state, smart_status stays useful via degraded mode and surfaces storageHealth plus the same mutationSafety contract as smart_turn.
Batch edit multiple files with pattern replacement.
{
pattern: 'console.log',
replacement: 'logger.info',
files: ['src/a.js', 'src/b.js'],
mode: 'literal' // or 'regex'
}
Supports dryRun: true for preview. Useful for bulk refactoring, removing patterns, or renaming across files.
Orchestrate turn start/end with automatic task checkpoint recovery.
{ phase: 'start', prompt: '...' } // Recovers task checkpoint
{ phase: 'end', event: 'milestone', update: {...} } // Saves checkpoint
Recovers task state (goal, status, decisions, next step), not full conversation history.
Read multiple files in one call.
{
files: [
{ path: 'src/a.js', mode: 'outline' },
{ path: 'src/b.js', mode: 'signatures' }
]
}
Reduces round-trip latency when you know you need several files.
Safe diagnostic command execution (allowlisted commands only).
{ command: 'git status' }
Blocks shell operators and unsafe commands by design.
Analyze git changes intelligently (part of smart_context):
{ task: 'Review changes', diff: 'main' }
Returns changed files prioritized by impact + related files (tests, importers).
Learn from usage patterns and predict needed files (part of smart_context):
{ task: 'Implement authentication', prefetch: true }
After 3+ similar tasks: 40-60% fewer round-trips, 15-20% additional savings.
Preload frequently accessed files into OS cache.
{} // No parameters
First query: 250ms → 50ms (5x faster cold start).
Function-level code attribution.
// Who wrote each function?
{ mode: 'symbol', filePath: 'src/server.js' }
// Find code by author
{ mode: 'author', authorQuery: 'alice@example.com' }
// Recent changes
{ mode: 'recent', daysBack: 7 }
Share context across monorepos and microservices.
// Search all related projects
{ mode: 'search', query: 'AuthService' }
// Find symbol across projects
{ mode: 'symbol', symbolName: 'validateToken' }
Requires .devctx-projects.json config file.
| Client | MCP | Rules | Hooks | smart_turn | Persistence | Near-Automatic | Key Limitations |
|---|---|---|---|---|---|---|---|
| Cursor | ✅ Full | ✅ Conditional ( .cursor/rules/*.mdc) | ❌ No | ✅ Manual call | ✅ SQLite (Node 22+) | 🟡 Medium Agent decides when | • No auto smart_turn• Agent must follow rules • Requires Agent mode |
| Claude Desktop | ✅ Full | ✅ Embedded ( CLAUDE.md) | ✅ SessionStart PostToolUse Stop | ✅ Can auto-trigger via hooks | ✅ SQLite (Node 22+) | 🟢 High Hooks auto-trigger | • Hooks are opt-in • No conditional rules • Fixed context: 200t |
| Codex CLI | ✅ Full | ✅ Embedded ( AGENTS.md) | ❌ No | ✅ Manual call | ✅ SQLite (Node 22+) | 🟡 Low-Medium Agent decides when | • No auto smart_turn• No conditional rules • No hooks |
| Qwen Code | ✅ Full | ✅ Embedded ( AGENTS.md) | ❌ No | ✅ Manual call | ✅ SQLite (Node 22+) | 🟡 Low-Medium Agent decides when | • No auto smart_turn• No conditional rules • No hooks |
Legend:
🟢 High (Claude Desktop with hooks):
smart_turn(start) when you start a session🟡 Medium (Cursor):
smart_turn (not auto-triggered)🟡 Low-Medium (Codex, Qwen):
smart_turn (not auto-triggered)❌ Not automatic prompt interception - MCP cannot intercept or modify your prompts before the agent sees them
❌ Not forced tool usage - Agent always has autonomy to decide which tools to use
❌ Not guaranteed workflow - Agent may skip devctx tools for simple tasks (this is fine)
❌ Not client-level magic - Behavior depends on agent following rules and making good decisions
All clients work the same way:
npm run report:metrics)The differences:
smart_turn(start) on session start)Choose Cursor if:
Choose Claude Desktop if:
smart_turn)Choose Codex or Qwen if:
AGENTS.md file)smart_turn calls and no conditional activationBottom line: All clients work well. The choice depends on your preference for automation level vs simplicity.
See Client Compatibility Guide for detailed comparison.
npm install -g smart-context-mcp
npx smart-context-init --target .
Restart your AI client. Done.
# Check installed version
npm list -g smart-context-mcp
# Should show: smart-context-mcp@1.20.0 (or later)
# Update to latest version
npm update -g smart-context-mcp
# Or reinstall from scratch
npm uninstall -g smart-context-mcp
npm install -g smart-context-mcp
After updating: The binary is updated globally, but agent rules (.cursorrules, CLAUDE.md, AGENTS.md) in each project are generated from the installed version and are not updated automatically.
Re-run init after each update to get the latest rules:
# Re-apply rules to a project after updating
npx smart-context-init --target /path/to/your/project --clients cursor
# or for all clients
npx smart-context-init --target /path/to/your/project --clients all
Then restart your AI client to load the new version.
npm install -g smart-context-mcp
npx smart-context-init --target . --clients cursor
Restart Cursor. Tools appear in Agent mode.
Files created:
.cursor/mcp.json - MCP server config.cursor/rules/devctx.mdc - Base agent rules (10 lines, always active).cursor/rules/profiles-compact/*.mdc - Task profiles (conditional).devctx/bin/cursor-devctx - Optional assisted launcher for long tasks.git/hooks/pre-commit - Safety hook.gitignore - Adds .devctx/npm install -g smart-context-mcp
npx smart-context-init --target . --clients codex
Restart Codex.
Files created:
.codex/config.toml - MCP server configAGENTS.md - Agent rules.git/hooks/pre-commit - Safety hook.gitignore - Adds .devctx/npm install -g smart-context-mcp
npx smart-context-init --target . --clients claude
Restart Claude Desktop.
Files created:
.mcp.json - MCP server config.claude/settings.json - Hook configCLAUDE.md - Agent rules.git/hooks/pre-commit - Safety hook.gitignore - Adds .devctx/npm install -g smart-context-mcp
npx smart-context-init --target . --clients qwen
Restart Qwen Code.
Files created:
.qwen/settings.json - MCP server configAGENTS.md - Agent rules.git/hooks/pre-commit - Safety hook.gitignore - Adds .devctx/What makes this MCP different is task-specific agent guidance. Installation generates rules that teach agents optimal workflows:
smart_turn(start) → smart_search(intent=debug) → smart_read(symbol) →
smart_shell('npm test') → fix → smart_turn(end)
Savings: 90% (150K → 15K tokens)
smart_turn(start) → smart_context(diff=true) → smart_read(signatures) →
review → smart_turn(end)
Savings: 87% (200K → 25K tokens)
smart_turn(start) → smart_context(entryFile) → smart_read(signatures) →
refactor → smart_shell('npm test') → smart_turn(end)
Savings: 89% (180K → 20K tokens)
smart_turn(start) → smart_search(intent=tests) → smart_read(symbol) →
write test → smart_shell('npm test') → smart_turn(end)
Savings: 90% (120K → 12K tokens)
smart_turn(start) → smart_context(detail=minimal) → smart_read(signatures) →
analyze → smart_turn(end)
Savings: 90% (300K → 30K tokens)
Key insight: The value isn't just in the tools—it's in teaching agents when and how to use them.
To ensure agents use devctx automatically, set up client-specific rules:
Already included: .cursorrules is committed in the project.
Verify it's working:
./.devctx/bin/cursor-devctx task --prompt "..." -- <agent-command>Create CLAUDE.md in your project root:
# Copy template
cp docs/agent-rules-template.md CLAUDE.md
# Edit to keep only the CLAUDE.md section
Or copy the content from docs/agent-rules-template.md.
Create AGENTS.md in your project root using the same template.
Why these rules matter:
See Agent Rules Template for complete setup.
If the agent doesn't use devctx tools in a non-trivial task, it will add a note:
Note: devctx not used because: [reason]
To use devctx next time: "Use smart-context-mcp: smart_turn(start) → ..."
Why this matters:
When to use these prompts:
Official prompt (complete workflow):
Use smart-context-mcp for this task:
1. Start with smart_turn(start, userPrompt, ensureSession=true) to recover context
2. Use smart_context or smart_search before reading files
3. Use smart_read(outline|signatures|symbol) instead of full reads
4. Close with smart_turn(end) when you reach a milestone
Ultra-short prompt (copy-paste ready):
Use devctx: smart_turn(start) → smart_context/smart_search → smart_read → smart_turn(end)
Example usage:
User: "Debug the authentication error"
Agent: [uses native tools]
Agent: "Note: devctx not used because: already had sufficient context..."
User: "Use devctx: smart_turn(start) → smart_context/smart_search → smart_read → smart_turn(end)"
Agent: [uses smart_turn, smart_search, smart_read]
Agent: "Found the issue in validateToken()..."
See agent-rules/ for complete profiles.
Install:
npm install smart-context-mcp
npx smart-context-init --target .
Build index (REQUIRED for quality):
npm run build-index
# or tell agent: "Run build_index tool"
Why critical: Without index, smart_search and smart_context are degraded. Agent may prefer native tools. No token savings.
Use core tools:
smart_read for file structuresmart_search for finding codesmart_context for comprehensive contextsmart_metrics to verify savingsLet the agent decide: Don't force tool usage. The generated rules will guide the agent naturally.
smart_summary if you work on long taskssmart_turn if using Claude Code CLIgit_blame for code attributioncross_project if working in monorepossmart_metrics for usage patternswarm_cache if cold starts are slowprefetch in smart_context for repetitive tasksnpm run benchmark
Runs all verification suites:
Takes 3-4 minutes. See Benchmark Documentation for details.
Release gating for orchestration quality is also available with npm run benchmark:orchestration:release, and npm publish now blocks on that gate via prepublishOnly.
npm run report:metrics
Good signs:
Bad signs:
Example output:
devctx metrics report
Entries: 3,696
Raw tokens: 14,492,131
Final tokens: 1,641,051
Saved tokens: 13,024,099 (89.87%)
By tool:
smart_search count=692 saved=5,817,485 (95.45%)
smart_read count=2108 saved=2,355,809 (70.52%)
smart_summary count=449 saved=1,897,628 (97.89%)
Adoption Analysis (Inferred from Tool Usage)
Total sessions: 156
Sessions with devctx: 89 (57%)
Sessions without: 67 (43%)
Non-Trivial Tasks Only:
Total: 112
With devctx: 78 (70%)
Without devctx: 34 (30%)
By Inferred Complexity:
- complex 56/68 (82%)
- moderate 25/52 (48%)
- simple 8/36 (22%)
When devctx IS used:
Avg tools/session: 2.8
Avg token savings: 146,337 tokens
Top Tools Used:
- smart_read 89 sessions
- smart_search 67 sessions
- smart_context 45 sessions
Limitations:
- Complexity inferred from operation count (not actual task complexity)
- Can only measure when devctx IS used (tool calls visible)
- Cannot measure feedback shown or forcing prompts (requires agent cooperation)
- Sessions without devctx may be simple tasks (not adoption failures)
The metrics report now includes adoption analysis to measure how often devctx is actually used.
What we measure:
What we DON'T measure:
Limitations:
Why this is useful:
See Adoption Metrics Design for complete analysis.
Get immediate visibility into devctx tool usage in every agent response.
ENABLED BY DEFAULT - Shows feedback after every devctx tool call.
Disable if too verbose:
export DEVCTX_SHOW_USAGE=false
What you'll see:
---
📊 **devctx usage this session:**
- **smart_read**: 3 calls | ~45.0K tokens saved (file1.js, file2.js, file3.js)
- **smart_search**: 1 call | ~12.0K tokens saved (query)
**Total saved:** ~57.0K tokens
*To disable this message: `export DEVCTX_SHOW_USAGE=false`*
Benefits:
When to use:
See Usage Feedback Documentation for complete guide.
Understand why the agent chose devctx tools and what benefits are expected.
ENABLED BY DEFAULT - Shows decision explanations for every devctx tool call.
Disable if too verbose:
export DEVCTX_EXPLAIN=false
What you'll see:
---
🤖 **Decision explanations:**
**smart_read** (read src/server.js (outline mode))
- **Why:** File is large (2500 lines), outline mode extracts structure only
- **Instead of:** Read (full file)
- **Expected benefit:** ~45.0K tokens saved
- **Context:** 2500 lines, 50000 tokens → 5000 tokens
**smart_search** (search "authentication" (intent: debug))
- **Why:** Intent-aware search prioritizes relevant results
- **Instead of:** Grep (unranked results)
- **Expected benefit:** ~12.0K tokens saved, Better result ranking
*To disable: `export DEVCTX_EXPLAIN=false`*
Benefits:
When to use:
Combine with usage feedback for maximum visibility:
export DEVCTX_SHOW_USAGE=true
export DEVCTX_EXPLAIN=true
See Decision Explainer Documentation for complete guide.
Detect when devctx should have been used but wasn't.
ENABLED BY DEFAULT - Shows warnings when devctx adoption is low.
Disable if not needed:
export DEVCTX_DETECT_MISSED=false
What you'll see:
---
⚠️ **Missed devctx opportunities detected:**
**Session stats:**
- Duration: 420s
- devctx operations: 2
- Estimated total operations: 25
- devctx adoption: 8%
🟡 **low devctx adoption**
- **Issue:** Low devctx adoption: 2/25 operations (8%). Target: >50%.
- **Suggestion:** Agent may be using native tools. Consider forcing prompt.
- **Potential savings:** ~184.0K tokens
**How to fix:**
1. Use forcing prompt
2. Check if index is built
3. Verify MCP is active
Detects:
Benefits:
Limitations:
All features enabled by default. To disable all:
export DEVCTX_SHOW_USAGE=false
export DEVCTX_EXPLAIN=false
export DEVCTX_DETECT_MISSED=false
See Missed Opportunities Documentation for complete guide.
The project includes agent rules that enforce devctx usage across different clients:
.cursorrules (committed to git)CLAUDE.md (create from template in docs/agent-rules-template.md)AGENTS.md (create from template in docs/agent-rules-template.md)All rules enforce the same policy:
smart_read instead of Readsmart_search instead of Grepsmart_context instead of multiple readsSee Agent Rules Template for setup instructions.
The MCP server provides prompts that automatically inject forcing instructions:
Quick forcing:
/prompt use-devctx
This injects: Use devctx: smart_turn(start) → smart_context/smart_search → smart_read → smart_turn(end)
Available prompts:
/prompt use-devctx - Ultra-short forcing prompt/prompt devctx-workflow - Complete workflow template/prompt devctx-preflight - Preflight checklist (index + session init)Benefits:
See MCP Prompts Documentation for complete guide.
npm run verify # Feature verification (20 tools)
npm test # Unit tests (740+ tests)
npm run eval # Synthetic corpus
npm run eval:self # Real project
Check:
# 1. Rules installed?
cat .cursor/rules/devctx.mdc
# 2. MCP running?
# Cursor: Settings → MCP → Check "smart-context" active
# 3. Index built?
ls .devctx/index.json
# 4. Metrics show usage?
npm run report:metrics
Possible causes:
npx smart-context-init --target .npm run build-index or tell agent "Run build_index tool"Force devctx usage (copy-paste ready):
Use devctx: smart_turn(start) → smart_context/smart_search → smart_read → smart_turn(end)
See How to Force devctx Usage for complete workflow.
To track complete workflows (debugging, review, refactor, testing, architecture):
export DEVCTX_WORKFLOW_TRACKING=true
Then restart your AI client. View workflow metrics:
npm run report:workflows -- --summary
See Workflow Metrics for details.
Check:
npm run report:metrics
Look for:
full mode usage (agent not cascading)Possible causes:
Check:
# 1. Node version (need 22+ for SQLite)
node --version
# 2. SQLite exists?
ls -lh .devctx/state.sqlite
# 3. Agent calling smart_turn?
sqlite3 .devctx/state.sqlite "SELECT COUNT(*) FROM sessions"
Possible causes:
smart_turn → No task checkpoints.devctx/state.sqlite tracked/staged → runtime context writes are intentionally blocked until git hygiene is fixed.devctx/state.sqlite locked/corrupted/oversized → inspect storageHealth from smart_status or smart_metricssmart_doctor or smart-context-doctor --jsonRecovery flow:
missing → run a persisted action like smart_summary update or smart_turn endoversized → run smart_summary compactlocked → stop competing devctx processes, then retrycorrupted → back up .devctx/state.sqlite, remove it, and let devctx recreate local stateCheck:
cat .cursor/rules/devctx.mdc # or AGENTS.md, CLAUDE.md
If missing:
npx smart-context-init --target .
If exists but agent ignores:
First-class (AST parsing): JavaScript, TypeScript, JSX, TSX
Heuristic parsing: Python, Go, Rust, Java, C#, Kotlin, PHP, Swift
Structural extraction: Shell, Terraform, HCL, Dockerfile, SQL, JSON, YAML, TOML
# Point to different project
export DEVCTX_PROJECT_ROOT=/path/to/project
# Disable cache warming
export DEVCTX_CACHE_WARMING=false
# Change warm file count
export DEVCTX_WARM_FILES=100
Create .devctx-projects.json:
{
"version": "1.0",
"projects": [
{ "name": "main-app", "path": ".", "type": "main" },
{ "name": "shared-lib", "path": "../shared-lib", "type": "library" },
{ "name": "api-service", "path": "../api-service", "type": "service" }
]
}
Build indexes for each project:
cd main-app && npx build-index
cd ../shared-lib && npx build-index
cd ../api-service && npx build-index
All data stored in .devctx/:
index.json - Symbol index (INDEX_VERSION 7: ADR + ADR sections, richer Python/Go)state.sqlite - Sessions, metrics, patterns, task handoffs, test failures, explain cache (Node 22+)metrics.jsonl - Opt-in legacy file, only when DEVCTX_METRICS_FILE=path.jsonl is setCross-project (opt-in via DEVCTX_GLOBAL_MEMORY=true):
~/.devctx/global.db - Scrubbed decisions, patterns, playbooks, notes with semantic recallAdd to .gitignore:
.devctx/
This MCP is secure by default:
ls, git status, npm test, etc.)|, &, ;, >, <, `, $()What smart_shell can run:
# Allowed
git status # ✓ Safe git read operations
npm test # ✓ Safe package manager scripts
find . -name "*.js" # ✓ File discovery
rg "pattern" # ✓ Code search
# Blocked
git commit # ✗ Write operations blocked
npm install pkg # ✗ Package changes blocked
ls | grep secret # ✗ Shell operators blocked
rm -rf / # ✗ Dangerous commands blocked
Real rejection examples:
// Shell operator blocked
smartShell({ command: "ls | grep secret" })
→ { exitCode: 126, blocked: true, output: "Shell operators are not allowed..." }
// Dangerous command blocked
smartShell({ command: "rm -rf /" })
→ { exitCode: 126, blocked: true, output: "Dangerous pattern detected..." }
// Git write blocked
smartShell({ command: "git commit -m 'test'" })
→ { exitCode: 126, blocked: true, output: "Git subcommand not allowed: commit..." }
// Package install blocked
smartShell({ command: "npm install malicious" })
→ { exitCode: 126, blocked: true, output: "Package manager subcommand not allowed: install..." }
Verification:
# Run 60+ security tests to verify behavior
cd tools/devctx && npm test -- tests/smart-shell-security.test.js
Configuration:
# Disable shell execution entirely
export DEVCTX_SHELL_DISABLED=true
# Disable cache warming
export DEVCTX_CACHE_WARMING=false
Complete security documentation:
@vscode/ripgrep (no system install needed)| Operation | Without MCP | With MCP | Savings |
|---|---|---|---|
| Read file | 4,000 tokens | 400 tokens | 90% |
| Search code | 10,000 tokens | 500 tokens | 95% |
| Session resume | 5,000 tokens | 100 tokens | 98% |
| Cold start | 250ms | 50ms | 5x faster |
smart_read
{
filePath: string;
mode?: 'outline' | 'signatures' | 'symbol' | 'range' | 'full';
symbol?: string | string[];
startLine?: number;
endLine?: number;
maxTokens?: number;
context?: boolean;
}
smart_search
{
query: string;
intent?: 'implementation' | 'debug' | 'tests' | 'config' | 'docs' | 'explore';
cwd?: string;
maxFiles?: number; // 1-50, default 15
}
smart_context
{
task: string;
intent?: string;
detail?: 'minimal' | 'balanced' | 'deep';
maxTokens?: number;
entryFile?: string;
diff?: boolean | string;
prefetch?: boolean;
include?: string[];
}
build_index
{
incremental?: boolean;
warmCache?: boolean;
}
smart_metrics
{
window?: '24h' | '7d' | '30d' | 'all';
tool?: string;
sessionId?: string;
}
smart_summary
{
action: 'get' | 'update' | 'append' | 'checkpoint' | 'reset' | 'list_sessions';
sessionId?: string;
update?: {
goal?: string;
status?: 'planning' | 'in_progress' | 'blocked' | 'completed';
nextStep?: string;
completed?: string[];
decisions?: string[];
};
maxTokens?: number;
}
smart_turn
{
phase: 'start' | 'end';
prompt?: string;
event?: string;
update?: object;
}
smart_read_batch
{
files: Array<{
path: string;
mode?: string;
symbol?: string;
}>;
maxTokens?: number;
}
smart_shell
{
command: string;
}
warm_cache
{} // No parameters
git_blame
{
mode: 'symbol' | 'file' | 'author' | 'recent';
filePath?: string;
authorQuery?: string;
limit?: number;
daysBack?: number;
}
cross_project
{
mode: 'discover' | 'search' | 'read' | 'symbol' | 'deps' | 'stats';
query?: string;
symbolName?: string;
maxResultsPerProject?: number;
}
See CHANGELOG.md for full release history.
This repository contains the smart-context-mcp npm package in tools/devctx/:
/
├── tools/devctx/ ← Publishable package
│ ├── src/ ← Source code
│ ├── tests/ ← 740+ unit tests
│ ├── evals/ ← Benchmarks & scenarios
│ ├── scripts/ ← CLI binaries
│ └── package.json ← Package metadata (v1.20.0)
├── docs/ ← Documentation (GitHub only)
├── .github/workflows/ ← CI/CD with release gating
└── README.md ← This file
What gets published to npm: Only tools/devctx/ contents (src + scripts)
Development: All work happens in tools/devctx/
See CONTRIBUTING.md for development setup.
Pull requests welcome for:
See CONTRIBUTING.md for guidelines.
Francisco Caballero Portero
Email: fcp1978@hotmail.com
GitHub: @Arrayo
MIT License - see LICENSE file for details.
io.github.ericm1018/skillfm-llm-cost-optimizer-openai-anthropic-usage
io.github.mikerawsonnz/llm-orchestration-agent
io.github.mikerawsonnz/authenticated-llm-agent
labforgedev/copilot-memory-mcp
csoai-org/agent-prompt-injection-firewall-mcp
io.github.mikerawsonnz/authenticated-multi-llm-agent