Context Mode — Prompt Files (Verbatim Excerpts)
Source: hooks/pretooluse.mjs
Prompting technique: Hook-injected routing decision — the hook analyzes the incoming tool call and can return a decision object with deny, allow, or redirect to guide the agent toward sandbox tools. This is a programmatic routing block, not a text prompt.
/**
* Unified PreToolUse hook for context-mode (Claude Code)
* Redirects data-fetching tools to context-mode MCP tools
*
* Routing is delegated to core/routing.mjs (shared across platforms).
* This file retains the Claude Code-specific self-heal block.
*
* Crash-resilience: wrapped via runHook (#414)
*/
await runHook(async () => {
const { routePreToolUse, initSecurity } = await import("./core/routing.mjs");
const { formatDecision } = await import("./core/formatters.mjs");
// ... routing logic ...
});
Excerpt 2: README — "Think in Code" Paradigm (Core Prompt Design Principle)
Source: README.md
Prompting technique: Mandatory paradigm shift — agents are instructed to generate code that produces results, not to read data into context. The routing block enforces this at the hook level.
### How Context Mode Solves It
3. **Think in Code** — The LLM should program the analysis, not compute it.
Instead of reading 50 files into context to count functions, the agent writes
a script that does the counting and `console.log()`s only the result.
One script replaces ten tool calls and saves 100x context.
This is a mandatory paradigm across all 15 platforms:
stop treating the LLM as a data processor, treat it as a code generator.
```js
// Before: 47 × Read() = 700 KB. After: 1 × ctx_execute() = 3.6 KB.
ctx_execute("javascript", `
const files = fs.readdirSync('src').filter(f => f.endsWith('.ts'));
files.forEach(f => console.log(f + ': ' +
fs.readFileSync('src/'+f,'utf8').split('\\n').length + ' lines'));
`);
## Excerpt 3: SessionStart Hook — Context Injection (Session Continuity)
Source: `hooks/sessionstart.mjs` (conceptual — from README description)
**Prompting technique**: Selective context injection at session start — instead of dumping full session history into context after compaction, the SessionStart hook uses BM25 search to retrieve only relevant prior events and injects them as `additionalContext`. This is the anti-pattern of "context dump after compaction."
From README:
```markdown
2. **Session Continuity** — Every file edit, git operation, task, error, and user
decision is tracked in SQLite. When the conversation compacts, context-mode
doesn't dump this data back into context — it indexes events into FTS5 and
retrieves only what's relevant via BM25 search. The model picks up exactly
where you left off. If you don't `--continue`, previous session data is
deleted immediately — a fresh session means a clean slate.
Excerpt 4: Hooks Configuration — PostToolUse Matchers
Source: hooks/hooks.json
Technique: Exhaustive tool-use capture — the PostToolUse hook matches all significant tool types to build a complete session event log.
{
"hooks": {
"PostToolUse": [
{
"matcher": "Bash|Read|Write|Edit|NotebookEdit|Glob|Grep|TodoWrite|TaskCreate|TaskUpdate|EnterPlanMode|ExitPlanMode|Skill|Agent|AskUserQuestion|EnterWorktree|mcp__",
"hooks": [
{
"type": "command",
"command": "node \"${CLAUDE_PLUGIN_ROOT}/hooks/posttooluse.mjs\""
}
]
}
]
}
}