About this project
claude-code-rlm is a hook for Claude Code that performs pre-research on a codebase before the main model handles a prompt. Instead of letting the primary model (Opus or Sonnet) spend its first tool calls orienting itself, the hook first dispatches the faster, cheaper Haiku model to explore the repository and hands the results to the main model as injected context.
How it works
1. Claude Code invokes rlm-hook.mjs through the UserPromptSubmit hook, passing JSON on stdin with fields such as prompt, cwd and transcript_path.
2. Trivial inputs are skipped immediately: prompts shorter than a configured minimum length, simple shell commands (ls, pwd, cat, echo, git status, npm, yarn), single-word affirmations, slash commands such as /help, /clear and /compact, and code-heavy pastes where more than half the input is code blocks.
3. A SHA-256 hash of the prompt and working directory is checked against a file cache with a one-hour default TTL.
4. On a cache miss, the Claude CLI is spawned with the configured Haiku model, restricted to Read, Glob, Grep and git Bash, and given a system prompt instructing it to explore the codebase within a configurable number of tool calls.
5. Haiku writes its findings to a scratch JSON file; the hook formats them into a structured rlm_preresearch block containing intent, summary, relevant files, existing patterns, recent changes, suggested approach, tasks and warnings, then prints it to stdout so Claude Code injects it ahead of the user prompt.
6. Any failure, including timeouts, API errors and JSON parse errors, exits with no output, so the hook does not block or corrupt a conversation.
Modes and configuration
Everything is configured through environment variables. Agentic mode (the default) enables tool-based exploration and is described as roughly 20 seconds on a cache miss; fast mode performs concise analysis without tool calls in roughly 4 seconds. Other settings cover the model name, total timeout, cache TTL, minimum and maximum input lengths, maximum tool turns, cache and log paths, and a metrics file. An optional SDK-Direct mode uses the Anthropic SDK with an API key instead of a subprocess.
Additional features described in the README include an optional semantic cache that compares embeddings against a configurable cosine similarity threshold, context reuse that looks back over recent RLM blocks to avoid re-analyzing the same intent or files, and a metrics JSONL log with a bundled dashboard (served locally on port 9876) showing latency distribution, cache hit rate, per-mode performance and estimated Haiku cost.
Reported latency figures: about 27 ms when skipping, about 37 ms on a cache hit, roughly 20 s in agentic mode on a miss, and roughly 4 s in fast mode.
Requirements and installation: Node.js 18 or newer and the Claude Code CLI on PATH. The provided install script copies the hook into the Claude hooks directory and makes it executable; a hook entry with a command and a timeout must be added to the Claude Code settings file. Testing and benchmarking are run through npm scripts, and integration tests require a live claude binary. The project is released under the MIT license.
Comments
0 Rating appears after 10 ratings
Sign in to join the discussion.