Skip to content

About

Local-first prompt routing for Codex and Claude Code through LM Studio.

Topics

Resources

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Request Classifier — local-first prompt routing

Request Classifier

A conservative, local-first prompt router for Codex, Claude Code, and LM Studio.

Node 24+ TypeScript MCP License

Request Classifier sends small, non-mutating requests to a local LM Studio model and leaves everything else with the host. It integrates at user scope through UserPromptSubmit hooks and exposes delegated answers through a narrow MCP tool.

Important

The router is intentionally conservative. Uncertainty, outages, unsafe requests, or exhausted limits all fail open to Codex or Claude Code.

How it works

flowchart LR
    P["Your prompt"] --> H["UserPromptSubmit hook"]
    H --> R{"Rules + local classifier"}
    R -->|"small and read-only"| M["request_classifier MCP"]
    M --> L["LM Studio"]
    L --> A["Local · model answer"]
    R -->|"complex, mutating, or uncertain"| C["Codex / Claude Code normally"]
Loading

The hook creates an opaque, one-time route record for eligible prompts and injects context that asks the host to call mcp__request_classifier__answer_route. The MCP server consumes the route, asks LM Studio for the answer, and returns display-ready text. A route cannot be replayed.

Routing policy

Routes locally Stays with the host
General questions and explanations File or code edits
Rewriting, summarizing, and translation Commands, tests, builds, or deployments
Read-only repository questions Git mutations
Small text-only tasks Web or current information
Explicit ::local requests inside the safety boundary Attachments and external connectors
High-stakes or substantial multi-step work

Use ::cloud at the beginning of any prompt to bypass local routing. Use ::local to request local routing; it never overrides the non-mutating safety boundary.

Requirements

  • Node.js 24+
  • Codex CLI and/or Claude Code
  • rg (ripgrep)
  • LM Studio listening at http://127.0.0.1:1234
  • qwythos-9b-claude-mythos-5-1m loaded, or custom model names in ~/.request-classifier/config.json

Install

git clone https://github.com/stag175/request-classifier.git
cd request-classifier
npm ci
npm run build
npm pack
npm install --global --prefix "$HOME/.local" ./request-classifier-0.1.0.tgz
request-classifier install --hosts codex,claude
request-classifier doctor

Ensure $HOME/.local/bin is on your PATH. Restart active Codex and Claude Code sessions after installation. For Codex, open /hooks once and trust the two request-classifier hook commands.

The installer is idempotent. It merges managed handlers with existing hook configuration, creates timestamped backups before changes, and registers the request_classifier stdio MCP at user scope.

Commands

Command Purpose
request-classifier install --hosts codex,claude Install hooks and MCP registration
request-classifier uninstall --hosts codex,claude Remove only package-owned integration entries
request-classifier doctor Check LM Studio, models, permissions, hooks, and MCP registration
request-classifier explain "<prompt>" Preview route, category, rule, and confidence

Safety and privacy

The local worker is read-only. It can list files, perform literal text searches, and read regular text files only within the realpath-resolved workspace root. It has no shell, write tools, network tools, arbitrary command execution, or external connectors.

It rejects path traversal, symlink escapes, binaries, oversized files, .git, environment files, credentials, keys, and ignored hidden content. Default execution limits are:

  • 8 local tool calls
  • 256 KiB aggregate file content
  • 128 KiB per file
  • 4,096 output tokens
  • 120 seconds per answer
  • 8 exchanges and 16,000 history characters per host session

Raw route and local session content is stored in ~/.request-classifier/state.db with user-only permissions and expires after 24 hours. Text-free diagnostic metadata expires after seven days.

Configuration

The first install creates ~/.request-classifier/config.json with mode 0600. You can change LM Studio endpoints, model names, thresholds, timeouts, and execution limits there. The default classification confidence threshold is 0.85.

An optional LM Studio bearer token can be provided through LM_STUDIO_API_TOKEN without writing the secret into project files.

Development

npm ci
npm run check
npm test
npm run build

The test suite covers routing rules, overrides, structured responses, fail-open behavior, workspace boundaries, secret and binary rejection, route replay protection, concurrent sessions, history limits, host hook payloads, installer idempotency, and mocked LM Studio execution.

Project scope

V1 supports text prompts only and never performs local mutations. The host still receives the prompt and performs the MCP call, so local routing reduces answer-generation work but does not eliminate the host turn entirely.

Contributions are welcome—please read CONTRIBUTING.md. For security concerns, follow SECURITY.md.

License

MIT © 2026 Charles

About

Local-first prompt routing for Codex and Claude Code through LM Studio.

Topics

Resources

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages