AI Context Routing Explained
You shouldn't have to tell your AI which context to use. If you mention "client," it should know you're talking about work. If you mention "budget," it should know you're talking about personal finance.
This is context routing. The AI detects what you're asking about and loads the right context file automatically.
No manual switching. No explicit commands. Just keywords that trigger the right domain.
Here's how it works.
The Problem: Manual Context Loading
Without routing, you have to tell the AI which context to use every time you switch topics.
"Load work context."
"Now load personal context."
"Switch to client A context."
It's tedious. And you'll forget. You'll ask a work question while personal context is loaded, and the AI won't have the information it needs.
Context routing removes the manual step. The AI figures it out from what you say.
How Context Routing Works
Context routing has three parts:
- Keyword detection — The AI scans your prompt for trigger words
- Domain mapping — It matches those keywords to a domain in your routing table
- Context loading — It reads the corresponding _context.md file before responding
All of this happens in milliseconds, before the AI generates its response.
Step 1: Keyword Detection
Your prompt is the trigger. When you ask a question, the AI scans it for specific words.
These aren't random words. They're the keywords you've defined in your CLAUDE.md routing table.
Example routing table:
| Domain | Context File | Load when prompt mentions... |
|--------|--------------|------------------------------|
| **Work** | `work/_context.md` | lead, database, CRM, agent, cleanup |
| **Business** | `business/_context.md` | client, SEO, content, article, outreach |
| **Personal** | `personal/_context.md` | budget, health, household, family |
If your prompt contains "lead," the AI knows to check the work domain. If it contains "client," it checks the business domain. If it contains "budget," it checks the personal domain.
The AI doesn't wait for you to say "use work context." The keyword is the command.
Step 2: Domain Mapping
Once the AI detects a keyword, it looks up which domain that keyword belongs to.
You type: "What's the status on the Johnson lead?"
The AI sees "lead" → checks the routing table → finds "lead" under the work domain → maps your prompt to work/_context.md.
You type: "Draft an email to the Johnson client."
The AI sees "client" → checks the routing table → finds "client" under the business domain → maps your prompt to business/_context.md.
Same last name. Different context. The keyword determines which one gets loaded.
Step 3: Context Loading
After mapping the domain, the AI reads the corresponding _context.md file.
For work/_context.md, that might include:
- Current projects and deadlines
- Key people and their roles
- Database rules and constraints
- Recent activity logs
For business/_context.md, it might include:
- Active clients and their status
- Pricing and service packages
- Brand voice and content guidelines
- Outreach templates
The AI loads whichever file matches the domain, then uses that context to generate its response.
You don't see this happening. But the response you get reflects the right context.
Multi-Keyword Routing
Sometimes your prompt contains keywords from multiple domains.
"I need to finish the client deliverable and update the lead database."
The AI detects both "client" (business) and "lead" (work). It loads both context files. Now it can reference both domains in its response.
This is context stacking. The AI doesn't force you to pick one domain. It brings in everything relevant.
Routing Priority: What Happens When Keywords Overlap
Most of the time, keywords are unique to one domain. "Lead" means work. "Client" means business. "Budget" means personal.
But sometimes keywords overlap. Maybe you use "project" in both work and business contexts.
When that happens, you can set priority in your routing table:
| Domain | Context File | Load when prompt mentions... | Priority |
|--------|--------------|------------------------------|----------|
| **Work** | `work/_context.md` | lead, database, CRM, agent, cleanup, project | 1 |
| **Business** | `business/_context.md` | client, SEO, content, article, outreach, project | 2 |
If your prompt only contains "project," the AI loads work/_context.md (priority 1) first. If you also mention "client," it loads both.
Priority determines the default when a keyword is ambiguous. But the AI still loads all relevant contexts when multiple domains are detected.
Claude Code Hooks: Automatic Routing Implementation
Claude Code supports hooks—scripts that run automatically when certain events happen.
For context routing, you use a UserPromptSubmit hook. Every time you submit a prompt, the hook runs before the AI responds.
The hook does this:
- Reads your CLAUDE.md routing table
- Scans your prompt for trigger keywords
- Identifies which domains match
- Loads the corresponding _context.md files
- Injects them into the AI's working memory
You set this up once. After that, it happens automatically.
Example Hook Script
Here's a simplified version of what a routing hook looks like:
#!/bin/bash
# route-domain.sh
PROMPT="$1"
CLAUDE_MD="/Users/you/vault/CLAUDE.md"
# Extract routing table from CLAUDE.md
# Scan prompt for keywords
# Match keywords to domains
# Load matching _context.md files
# Return context to Claude Code
The actual implementation is more detailed, but the concept is straightforward. The hook bridges your routing table and Claude Code's context system.
Routing Without Hooks: Manual Fallback
If you're not using Claude Code, you can still do context routing. It's just manual.
You keep your routing table in CLAUDE.md. When you ask a question, you reference which context to load:
"[Work context] What's the status on the Johnson lead?"
The AI sees the bracket notation, knows to load work/_context.md, and responds accordingly.
It's slower than automatic routing. But it works.
Routing Across Nested Domains
Some domains have sub-domains. Maybe your business context splits into multiple clients:
| Domain | Context File | Load when prompt mentions... |
|--------|--------------|------------------------------|
| **Business** | `business/_context.md` | client, SEO, content, outreach |
| **Client A** | `business/clients/acme/_context.md` | Acme, welding, industrial |
| **Client B** | `business/clients/zenith/_context.md` | Zenith, wellness, recovery |
If you mention "client," the AI loads business/_context.md (general business context). If you mention "Acme," it loads both business/_context.md and business/clients/acme/_context.md (specific client context).
This is nested context routing. The AI loads the parent context plus the child context. It gets both the general rules and the specific details.
Default Context: What Happens When No Keywords Match
Sometimes your prompt doesn't contain any routing keywords. You ask a general question or mention something that isn't tied to a specific domain.
What happens?
The AI uses the root CLAUDE.md as default context. This file contains your universal rules—voice, identity, general working style—that apply regardless of domain.
Think of it as the baseline. Domain contexts are additive. They load on top of the root context, not instead of it.
Explicit Context Override
Most of the time, keyword-based routing is all you need. But sometimes you want to force a specific context, even if the keywords don't match.
You can do this with an explicit command:
"[Load personal context] What's the status on the Johnson situation?"
The AI ignores keyword detection and loads personal/_context.md directly. Useful when you know the domain but the keywords are ambiguous.
Session Persistence: Context Stays Loaded Until You Switch
Once a context is loaded, it stays active for the session. You don't have to re-trigger it with every prompt.
You ask: "What's the Johnson lead status?" (loads work context)
You ask: "What about the Anderson lead?" (work context still loaded)
You ask: "Any updates on the Miller lead?" (work context still loaded)
The context persists until you mention a keyword from a different domain.
You ask: "What's the status on the Smith client?" (loads business context, replaces work context)
Now business context is active. Work context unloads.
Multi-Domain Sessions: Keeping Both Active
If you need both contexts active at once, mention keywords from both domains in the same session.
"I need to wrap up the client deliverable and then update the lead database."
Both contexts load. Both stay active. The AI can reference either one until you explicitly switch to a single domain.
Why Routing Beats Manual Switching
Manual context switching requires you to remember where you are. You have to track which context is loaded. You have to think about the system instead of the work.
Context routing removes that cognitive load. You think about the topic. The AI figures out the context.
It's the difference between changing TV channels manually and saying "play the news." The outcome is the same, but one requires less thought.
Building Your Routing Table
Start with 5-10 keywords per domain. Pick the words you use most often when talking about that area.
For work: lead, database, CRM, agent, cleanup
For business: client, SEO, content, article, outreach
For personal: budget, health, household, family, finance
Test it. Ask questions using those keywords. Confirm the AI loads the right context. If it doesn't, adjust the keywords.
Over time, you'll add more keywords as patterns emerge. Month one you might have 10 keywords per domain. Month six you might have 30.
The routing table grows as your usage grows.
The Result: AI That Knows What You're Talking About
With context routing, you stop managing the system and start using it.
You don't think about which file to load. You don't wonder if the AI has the right information. You just ask, and it knows.
The right context, every time, automatically.
Build Context Routing Into Your System
One markdown file. One afternoon. AI that actually remembers who you are, what you do, and how you work.
Build Your Memory System — $997