---
title: "Route prompts to the right context file with a keyword table"
description: "Build a keyword table that loads the right domain file for each prompt, add a Claude Code hook, and test the router for overlaps and misses."
canonical: "https://scalewithsearch.com/articles/ai-context-routing-explained"
date: "2026-01-28"
modified: "2026-09-25"
---
## Site navigation

- [Scale With Search](https://scalewithsearch.com/)
- Real estate
  - Real estate
    - [Real estate](https://scalewithsearch.com/for/real-estate)
- Work
  - Start here
    - [Send your brief](https://scalewithsearch.com/work#send-your-brief)
    - [Prepare your six-question brief](https://scalewithsearch.com/work#prepare-your-six-question-brief)
  - Build
    - [Site build, content library with SEO, signal desk](https://scalewithsearch.com/work)
- For your business
  - Trades and home services
    - [Auto body and collision shops](https://scalewithsearch.com/for/auto-body-and-collision-shops)
    - [Foundation and home repair contractors](https://scalewithsearch.com/for/foundation-and-home-repair)
    - [Garage door and fencing contractors](https://scalewithsearch.com/for/garage-door-and-fencing-contractors)
    - [HVAC contractors](https://scalewithsearch.com/for/hvac-contractors)
    - [Janitorial and commercial cleaning companies](https://scalewithsearch.com/for/janitorial-and-commercial-cleaning)
    - [Locksmiths](https://scalewithsearch.com/for/locksmiths)
    - [Moving companies](https://scalewithsearch.com/for/moving-companies)
    - [Pest control companies](https://scalewithsearch.com/for/pest-control-companies)
    - [Plumbing and electrical contractors](https://scalewithsearch.com/for/plumbing-and-electrical-contractors)
    - [Restoration and water or fire damage companies](https://scalewithsearch.com/for/restoration-and-water-fire-damage)
    - [Roofing companies](https://scalewithsearch.com/for/roofing-companies)
    - [Towing companies](https://scalewithsearch.com/for/towing-companies)
    - [Tree services and landscaping companies](https://scalewithsearch.com/for/tree-services-and-landscaping)
    - [Solar installers](https://scalewithsearch.com/for/solar-installation)
    - [General contractors](https://scalewithsearch.com/for/general-contractors-and-construction)
    - [Paving, concrete, and flooring contractors](https://scalewithsearch.com/for/paving)
  - Practices and professional services
    - [Bookkeeping and tax practices](https://scalewithsearch.com/for/bookkeeping-and-tax-practices)
    - [Dental practices](https://scalewithsearch.com/for/dental-practices)
    - [Family and criminal defense law firms](https://scalewithsearch.com/for/family-and-criminal-defense-law-firms)
    - [Med spas and aesthetics practices](https://scalewithsearch.com/for/med-spas-and-aesthetics)
    - [Personal injury law firms](https://scalewithsearch.com/for/personal-injury-law-firms)
    - [Veterinary clinics](https://scalewithsearch.com/for/veterinary-clinics)
    - [Gyms and fitness studios](https://scalewithsearch.com/for/fitness)
    - [Therapy and outpatient health practices](https://scalewithsearch.com/for/therapy-and-outpatient-health)
    - [Medical billing companies](https://scalewithsearch.com/for/medical-billing)
    - [Insurance agencies](https://scalewithsearch.com/for/insurance-agencies)
    - [Financial advisors](https://scalewithsearch.com/for/financial-advisors)
    - [Property management companies](https://scalewithsearch.com/for/property-management)
    - [Recruiting and staffing agencies](https://scalewithsearch.com/for/recruiting-and-staffing)
    - [Architects and interior designers](https://scalewithsearch.com/for/architects-and-interior-designers)
    - [Logistics and supply chain companies](https://scalewithsearch.com/for/logistics-and-supply-chain)
  - Agencies, MSPs, and manufacturing
    - [IT and managed service providers](https://scalewithsearch.com/for/it-and-managed-service-providers)
    - [Machine shops and precision manufacturers](https://scalewithsearch.com/for/machine-shops-and-precision-manufacturing)
    - [Marketing agencies and freelancers](https://scalewithsearch.com/for/marketing-agencies-and-freelancers)
    - [SEO agencies and consultants](https://scalewithsearch.com/for/seo-agencies-and-consultants)
    - [Small manufacturers and fabricators](https://scalewithsearch.com/for/small-manufacturers-and-fabricators)
  - Restaurants, shops, studios, and nonprofits
    - [Restaurants and hospitality businesses](https://scalewithsearch.com/for/restaurants-and-hospitality)
    - [Retail stores and ecommerce sellers](https://scalewithsearch.com/for/retail-and-ecommerce)
    - [Photographers, event planners, and travel agents](https://scalewithsearch.com/for/photographers)
    - [Churches and nonprofits](https://scalewithsearch.com/for/churches-and-nonprofits)
  - [All industries](https://scalewithsearch.com/for/)
- Learn
  - For your office
    - [Office job guides](https://scalewithsearch.com/guides/)
    - [Browser calculators](https://scalewithsearch.com/tools/)
  - Start here
    - [How it works](https://scalewithsearch.com/how-it-works)
    - [Free Starter Kit](https://scalewithsearch.com/kit/business-memory-starter-kit.zip)
    - [Synthetic specimen](https://scalewithsearch.com/specimen/working-session-specimen.zip)
  - Guides
    - [The Complete Guide to Business Memory for AI Agents](https://scalewithsearch.com/articles/business-memory-for-ai-agents-guide)
    - [The Complete Small-Business Guide to AI Agent Governance](https://scalewithsearch.com/articles/ai-agent-governance-guide-small-business)
    - [The Complete Guide to Leaving Vendor AI Memory](https://scalewithsearch.com/articles/leaving-vendor-ai-memory-guide)
  - Articles by cluster
    - [Business memory](https://scalewithsearch.com/articles/business-memory-for-ai-agents-guide)
    - [Agent governance](https://scalewithsearch.com/articles/ai-agent-governance-guide-small-business)
    - [Migration and ownership](https://scalewithsearch.com/articles/leaving-vendor-ai-memory-guide)
  - For machines
    - [llms.txt](https://scalewithsearch.com/llms.txt)
    - [llms-full.txt](https://scalewithsearch.com/llms-full.txt)
    - [Machine view](https://scalewithsearch.com/?view=machine)
- Company
  - Evidence
    - [Proof](https://scalewithsearch.com/proof)
  - Company
    - [About](https://scalewithsearch.com/about)

# Route prompts to the right context file with a keyword table.

You keep separate context files for your day job, your side business, and your household. The files work, but you must tell the AI which one to use each time you change topics. You forget once, ask a work question with household context loaded, and get an answer without the facts it needed.

Context routing removes that manual step. The system reads your prompt, finds keywords you have mapped to a domain, and loads that domain's context file before the model answers. If you mention "client," it loads business context. If you mention "budget," it loads household context.

## Why manual context loading fails

Without routing, every topic change needs a command:

- "Load work context."
- "Now load personal context."
- "Switch to the client A context."

The commands are tedious, and you will skip one. When you do, the model answers from the wrong domain or from none. Routing moves the choice from your memory to a table.

## How routing works

Routing has three steps, in this order:

1. Keyword detection: the router scans your prompt for trigger words.
2. Domain mapping: it matches each trigger word to a domain in the routing table.
3. Context loading: it reads that domain's `_context.md` file and adds it to the session before the model responds.

## Build the routing table

The trigger words are the keywords you define in a routing table. Keep the table in your root `CLAUDE.md` file so a person can read and edit it:

```markdown
| Domain   | Context file            | Load when the 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 the prompt contains "lead," the router selects the work domain. If it contains "client," it selects the business domain. If it contains "budget," it selects the personal domain. The keyword is the command.

Start with five to ten keywords per domain. Pick the words you use most often when you talk about that area. Add more as patterns appear. A table with ten keywords per domain in the first month can grow to thirty by the sixth.

## Map the same name to different domains

The keyword decides the domain, even when the rest of the prompt looks the same.

"What's the status on the Johnson lead?" contains "lead." The router maps it to `work/_context.md`.

"Draft an email to the Johnson client." contains "client." The router maps it to `business/_context.md`.

Same last name. Different context. The keyword decides which file loads.

## Decide what each domain file holds

After the mapping, the router loads the domain file. A work file might hold current projects and deadlines, key people and their roles, database rules, and recent activity. A business file might hold active clients and their status, service packages, brand voice rules, and outreach templates.

The model then answers with that file in its context. You do not see the load, but the answer reflects the right domain. The guide to [what context an agent should read](/articles/what-context-should-an-agent-read) helps you decide what belongs in each file.

## Load two domains when a prompt names both

Some prompts contain keywords from two domains:

"I need to finish the client deliverable and update the lead database."

The router detects "client" (business) and "lead" (work). It loads both files. This is context stacking: the model can use both domains in one answer.

## Set a default for overlapping keywords

Most keywords belong to one domain. Some do not. You may use "project" in both work and business contexts. Add a priority column for those cases:

```markdown
| Domain   | Context file         | Load when the 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 the prompt contains only "project," the router loads the priority 1 file. If the prompt also contains "client," it loads both. The router you write must implement this rule; the table only records it.

Separate domains also protect clients from each other. The guide to [keeping businesses, clients, and roles separate](/articles/separate-business-contexts-ai-agents) explains why a routing mistake can expose one client's facts in another client's work.

## Choose instruction routing or hook routing

You can implement the table in two ways.

Instruction routing puts the table in `CLAUDE.md` with a rule: "Before you answer, read the context file for any domain whose keyword appears in the prompt." The model reads the rule and opens the file. This needs no code. It depends on the model, which can skip the step. Anthropic's page [How Claude remembers your project](https://code.claude.com/docs/en/memory) states that Claude Code treats `CLAUDE.md` as context, not as enforced configuration.

Hook routing uses a script that Claude Code runs every time you submit a prompt. The script, not the model, decides which files load. This is deterministic.

## Add a Claude Code hook

Claude Code supports hooks: shell commands that run at fixed points in a session. A `UserPromptSubmit` hook runs when you submit a prompt, before Claude processes it. The hook receives JSON on standard input, and that JSON includes the `prompt` text. For this event, Claude Code adds plain-text standard output to Claude's context when the hook exits with code 0. Source: the Claude Code [hooks guide](https://code.claude.com/docs/en/hooks-guide), checked 2026.09.25.

A minimal routing hook:

```bash
#!/bin/bash
# route-domain.sh: a Claude Code UserPromptSubmit hook
prompt=$(jq -r '.prompt')
vault="$HOME/vault"

if grep -qiwE 'lead|database|crm|agent|cleanup' <<<"$prompt"; then
  cat "$vault/work/_context.md"
fi
if grep -qiwE 'client|seo|content|article|outreach' <<<"$prompt"; then
  cat "$vault/business/_context.md"
fi
if grep -qiwE 'budget|health|household|family' <<<"$prompt"; then
  cat "$vault/personal/_context.md"
fi
exit 0
```

The `-w` flag matches whole words, so "leader" does not match "lead." The `-i` flag ignores case.

Register the hook in `.claude/settings.json`:

```json
{
  "hooks": {
    "UserPromptSubmit": [
      {
        "hooks": [
          { "type": "command", "command": "$HOME/vault/.claude/hooks/route-domain.sh" }
        ]
      }
    ]
  }
}
```

Make the script executable with `chmod +x`. You set this up once. After that, it runs on every prompt.

## Route nested domains

Some domains have sub-domains. A business domain can contain one folder per client:

```markdown
| Domain   | Context file                        | Load when the prompt mentions   |
|----------|-------------------------------------|---------------------------------|
| Business | business/_context.md                | client, SEO, content, outreach  |
| Client A | business/clients/acme/_context.md   | Acme, roofing                   |
| Client B | business/clients/birch/_context.md  | Birch, dental                   |
```

If the prompt says "client," the router loads the general business file. If it says "Acme," the router loads the business file and the Acme file. This is nested routing: the parent file carries general rules, and the child file carries client detail. The client names in this table are fictional.

## Keep a default and an override

When no keyword matches, the model works from the root `CLAUDE.md` alone. That file holds rules for every domain: identity, voice, and general working style. Domain files add to the root context. They do not replace it.

Sometimes you know the domain and the keywords do not show it. Add an explicit override: "[personal] What's the status on the Johnson situation?" Add a matching rule to the hook, or to `CLAUDE.md`, that loads the named domain when the bracket tag appears.

Without Claude Code, you can still route by hand. Keep the table in your context file and start each prompt with the domain tag. It is slower, but it works in any chat tool.

## Know how loaded context behaves in a session

Loaded context stays in the conversation. Once the hook adds the work file, later prompts in the same session can use it without a new keyword. A new domain keyword adds a second file; it does not remove the first. In a long session, Claude Code can compact old content, and the loaded file can be summarized with it.

If you need a clean domain, start a new session. This also stops facts from one domain from shaping answers in another.

## Test the router before you rely on it

Write a small set of test prompts and the files you expect each one to load:

| Test prompt | Expected files |
|---|---|
| "Status on the Johnson lead?" | work |
| "Draft an email to the Johnson client." | business |
| "Finish the client deliverable, then clean up the lead database." | work, business |
| "What's our lead time on the Acme order?" | work (false match), business, Acme |
| "What's on my calendar tomorrow?" | none (root only) |

Run each prompt in a fresh session. Ask the model to name the context files it received, and compare the answer with the table. The fourth prompt shows a real risk: "lead" in "lead time" triggers the work domain. Fix false matches with more specific keywords, such as "sales lead."

Retest after every change to the table or the hook. The [CLAUDE.md template for business context](/articles/claude-md-template-business-context) shows where the routing table fits in the root file.


## Related: AI memory

- [Measure the time you lose to AI context setup before you fix it](/articles/how-much-time-wasted-on-ai-context)
- [Reorganize an existing AI vault so the assistant finds the right context](/articles/how-to-organize-ai-knowledge-vault)
- [Route AI context across work, business, and personal domains without mixing them](/articles/multi-domain-ai-context-architecture)

----

```text
                  .|########||.                                       .|########||.                                       .|########||.
               |##||.      .||##|.                                 |##||.      .||##|.                                 |##||.      .||##|.
             |#|.              .|#|.                             |#|.              .|#|.                             |#|.              .|#|.
           |#|                    |#|                          |#|                    |#|                          |#|                    |#|
         .#|                        |#.                      .#|                        |#.                      .#|                        |#.
        .#.                          .#|                    .#.                          .#|                    .#.                          .#|
       |#.                            .#|                  |#.                            .#|                  |#.                            .#|
      |#             ......             #|                |#             ......             #|                |#             ......             #|
     .#           ||#########|           #|              .#           ||#########|           #|              .#           ||#########|           #|
    .#.         |######||######|.        .#.            .#.         |######||######|.        .#.            .#.         |######||######|.        .#.
    #.        .##|###|##|#|######|        .#            #.        .##|###|##|#|######|        .#            #.        .##|###|##|#|######|        .#
   ||        |##|#||||||||||||#||#|        ||          ||        |##|#||||||||||||#||#|        ||          ||        |##|#||||||||||||#||#|        ||
   #        |#||||||||||||||||||||#|        #.         #        |#||||||||||||||||||||#|        #.         #        |#||||||||||||||||||||#|        #.
  ||       |#||||||||||||||||||||||#|       ||        ||       |#||||||||||||||||||||||#|       ||        ||       |#||||||||||||||||||||||#|       ||
  #       .#||||||||||||||||||||||||#|       #        #       .#||||||||||||||||||||||||#|       #        #       .#||||||||||||||||||||||||#|       #
 ||   ....|||#||||||##|#|||#|#||##||||....|. ||      ||   ....|||#||||||##|#|||#|#||##||||....|. ||      ||   ....|||#||||||##|#|||#|#||##||||....|. ||
 #.  .  ....|#  ....#|||   ||| .#|||  ....#. .#      #.  .  ....|#  ....#|||   ||| .#|||  ....#. .#      #.  .  ....|#  ....#|||   ||| .#|||  ....#. .#
 #   .  ||||#| .#####||  . .#| .#|||  ||||#   #.     #   .  ||||#| .#####||  . .#| .#|||  ||||#   #.     #   .  ||||#| .#####||  . .#| .#|||  ||||#   #.
.|   |||||  #. |#|||||. ||  #. |#||. .|||||   ||    .|   |||||  #. |#|||||. ||  #. |#||. .|||||   ||    .|   |||||  #. |#|||||. ||  #. |#||. .|||||   ||
||   |....  #. ....|#.      |. ...|. ....||   ||    ||   |....  #. ....|#.      |. ...|. ....||   ||    ||   |....  #. ....|#.      |. ...|. ....||   ||
#.  .||||||##||||||##||####|||||||#||||||#|   .#    #.  .||||||##||||||##||####|||||||#||||||#|   .#    #.  .||||||##||||||##||####|||||||#||||||#|   .#
#    .||####|###########################|.     #    #    .||####|###########################|.     #    #    .||####|###########################|.     #
#      .#||||||.#.|| # |. ..# #| #|||||#|      #    #      .#||||||.#.|| # |. ..# #| #|||||#|      #    #      .#||||||.#.|| # |. ..# #| #|||||#|      #
#      .#|||||| ..  |# ## |#| ...#|#|||#|      #    #      .#|||||| ..  |# ## |#| ...#|#|||#|      #    #      .#|||||| ..  |# ## |#| ...#|#|||#|      #
#      .#|||#|# .# .#| #| ##|.#..#|||||#|      #    #      .#|||#|# .# .#| #| ##|.#..#|||||#|      #    #      .#|||#|# .# .#| #| ##|.#..#|||||#|      #
#      .#||||||############|######|||||#|      #    #      .#||||||############|######|||||#|      #    #      .#||||||############|######|||||#|      #
#   |...||#||||||#||||#|#||||||#|||||#||| |.|  #    #   |...||#||||||#||||#|#||||||#|||||#||| |.|  #    #   |...||#||||||#||||#|#||||||#|||||#||| |.|  #
#. .. ||||# .|||##|.  |#| .|| || .|||#. #|  # .#    #. .. ||||# .|||##|.  |#| .|| || .|||#. #|  # .#    #. .. ||||# .|||##|.  |#| .|| || .|||#. #|  # .#
|| |  ...||  ...##| |  #| .|. |. #####  .. .| ||    || |  ...||  ...##| |  #| .|. |. #####  .. .| ||    || |  ...||  ...##| |  #| .|. |. #####  .. .| ||
|| ||||| || ||||#|  .  |. |. |#. ||||| |#| || ||    || ||||| || ||||#|  .  |. |. |#. ||||| |#| || ||    || ||||| || ||||#|  .  |. |. |#. ||||| |#| || ||
.# |.....#|....|#.||||.|||##.|#|....||.#||.#. #.    .# |.....#|....|#.||||.|||##.|#|....||.#||.#. #.    .# |.....#|....|#.||||.|||##.|#|....||.#||.#. #.
 #.|||||||#############################| ||| .#      #.|||||||#############################| ||| .#      #.|||||||#############################| ||| .#
 ||       ##||#||#||||||#||#||#||#||##.      ||      ||       ##||#||#||||||#||#||#||#||##.      ||      ||       ##||#||#||||||#||#||#||#||##.      ||
  #       .#|||||||||#||#|||||||||||#|       #        #       .#|||||||||#||#|||||||||||#|       #        #       .#|||||||||#||#|||||||||||#|       #
  ||       |#||||||||||||||||||||||#|       ||        ||       |#||||||||||||||||||||||#|       ||        ||       |#||||||||||||||||||||||#|       ||
  .#        |#||||||||||||||||||||#|        #.        .#        |#||||||||||||||||||||#|        #.        .#        |#||||||||||||||||||||#|        #.
   ||        |#||||||||||||||||||#|        ||          ||        |#||||||||||||||||||#|        ||          ||        |#||||||||||||||||||#|        ||
    #.        .######|#|#########|        .#            #.        .######|#|#########|        .#            #.        .######|#|#########|        .#
    .#.         |#####||||#####|         .#.            .#.         |#####||||#####|         .#.            .#.         |#####||||#####|         .#.
     |#           ||########||           #.              |#           ||########||           #.              |#           ||########||           #.
      |#             ......             #|                |#             ......             #|                |#             ......             #|
       |#.                            .#|                  |#.                            .#|                  |#.                            .#|
        |#.                          .#.                    |#.                          .#.                    |#.                          .#.
         .#|                        |#.                      .#|                        |#.                      .#|                        |#.
           |#|                    |#|                          |#|                    |#|                          |#|                    |#|
            .|#|.              .|#|.                            .|#|.              .|#|.                            .|#|.              .|#|.
               |##||.      .||##|                                  |##||.      .||##|                                  |##||.      .||##|
                 .||########||.                                      .||########||.                                      .||########||.

Scale With Search  2026  [scalewithsearch.com](https://scalewithsearch.com)
```
