RLM Tools
Large grep results and file reads can fill an AI coding agent's context window before it has answered the question.
RLM Tools gives your agent a persistent sandbox to explore code in. Local exploration keeps intermediate file reads and search results in the server process. The agent receives the output it asks for. Optional model helpers can send repository content to external providers.
RLM Tools keeps raw context in tool-side memory and exposes a genuinely recursive explorer: rlm_recurse runs its own server-side tool-use loop (grep/read/glob/tree) and can spawn depth-limited child agents, so a sub-question is answered by exploring the corpus directly instead of dumping it into the root agent's context. Scored evals and prompt benchmarks measure answer quality alongside efficiency.
# For Codex / generic MCP clients
uvx --from rlm-tools rlm-tools-setup --write-policy AGENTS.md
# For Claude Code
uvx --from rlm-tools rlm-tools-setup --write-policy CLAUDE.md
This auto-detects Claude/Codex on your PATH, registers the MCP server, and writes a policy block that nudges agents toward rlm-tools for repo exploration. Use CLAUDE.md for Claude Code (it reads this file automatically) or AGENTS.md for other clients.
If you prefer manual setup:
# Claude Code
claude mcp add rlm-tools -- uvx rlm-tools
# Codex
codex mcp add rlm-tools -- uvx rlm-tools
What Changes
Without RLM Tools — agent greps for import UIKit, gets 500 matches dumped into context. Reads 10 files, burns all their content as tokens. Context window fills up. Agent forgets what it was doing.
With RLM Tools — agent runs the same exploration in a server-side Python sandbox. In this example, only the printed summary enters the agent's context:
matches = grep("import UIKit")
by_module = {}
for m in matches:
module = m["file"].split("/")[0]
by_module.setdefault(module, []).append(m)
for module, ms in sorted(by_module.items(), key=lambda x: -len(x[1]))[:5]:
print(f"{module}: {len(ms)} files")
500 lines of grep results become 5 lines of summary. The agent sees what it needs, nothing more.
Real-World Impact
On the four checked-in Python and TypeScript fixture tasks, the RLM scripts used 13.6% to 54.5% fewer estimated context characters than the baseline file and search operations. The estimate counts script or tool arguments, returned text, and 350 characters of overhead per measured turn. It excludes session startup and teardown. Run uv run --extra dev python -m pytest evals/test_comparative.py -q -s for the per-task counts. The prompt benchmark measures root-agent token usage and answer quality separately.
In heavy exploration tasks (reading many files, broad searches, multi-file aggregation), savings go much further: on the live Gemini 230-file (heavy) A/B benchmark (gemini-3.5-flash-lite), rlm-tools achieved 100% pass vs 40%–60% for native tools with 87.3%–90.1% fewer tokens (31,208 vs 315,676 post-fix tokens). Conversely, on narrow 1–5 file lookups in small (~28 KB) repositories (long_context), native Read/Grep/Glob uses ~2.5× fewer tokens because MCP session lifecycle adds fixed overhead. Route narrow lookups to native tools and use rlm-tools for broad searches, audits, large files, and multi-step analysis. The table below is a worst-case comparison where the "Standard Tools" baseline dumps full grep/file payloads into context; treat it as an upper bound and see docs/benchmarks.md plus scored evals for full measured results and crossover guidance.
| Scenario | Standard Tools | RLM Tools | Saved |
|---|---|---|---|
| Grep across full app | 40,045 chars | 1,644 chars | 95.9% |
| Read 10 large files | 1,493,720 chars | 13,588 chars | 99.1% |
| Multi-step exploration | 136,102 chars | 5,285 chars | 96.1% |
| Grep then read matches | 340,408 chars | 6,022 chars | 98.2% |
| Find all usages of a pattern | 13,478 chars | 3,691 chars | 72.6% |
| Understand a module | 94,745 chars | 16,925 chars | 82.1% |
Full benchmark methodology and reproduction steps: docs/benchmarks.md
Scored Evals
The repo now carries fixture-backed, always-runnable evals under evals/ plus checked-in corpora under tests/fixtures/.
evals/test_correctness.pychecks helper semantics and security boundariesevals/test_task_completion.pychecks multi-step task workflowsevals/test_comparative.pykeeps context-size microbenchmarksevals/test_robustness.pychecks error handling and timeout behaviorevals/test_session_effectiveness.pycompares a complete session with targeted Read/Grep, including follow-ups where the baseline can reuse its first resultevals/test_longcontext_quality.pychecks grounded answers and plausible wrong answers on the long-context fixtureevals/test_evidence_effectiveness.pymeasures how much tool output the recursive loop replays while checking whether the answer survives filteringevals/test_stdio_workflow.pyexercises independent sessions and compact responses through the actual stdio server
Prompt benchmarks are defined in evals/specs/rlm_core.json and the harder evals/specs/rlm_long_context.json, graded by evals/grade_eval.py, and aggregated with variance notes plus a pass-rate-first preferred-config summary by evals/aggregate_benchmark.py.
How It Works
Three MCP tools. That's the entire API:
| Tool | Purpose |
|---|---|
rlm_start(path, query, code?) |
Open a session on a directory (optionally run initial code immediately) |
rlm_execute(session_id, code, end_session?) |
Run Python in the sandbox (set end_session=true on the final step to close) |
rlm_end(session_id) |
Explicitly close session and free resources |
The sandbox provides built-in helpers:
read_file(path)/read_files(paths)— Read files into variables (cached across calls)grep(pattern)/grep_summary(pattern)/grep_read(pattern)— Searchglob_files(pattern)— Find files by patterntree(path, max_depth)— Directory structurellm_query(prompt, context)— Sub-LLM analysis (optional, requires API key)rlm_recurse(prompt, context)— Ask a sub-agent to explore the session directory (optional, requires API key)
Variables persist across rlm_execute calls within a session. The agent can build up understanding incrementally — search, filter, read, analyze — without any intermediate data touching the context window.
Evidence Gate
A rlm_recurse sub-agent re-sends every tool result on every turn of its loop, so a
large file read is paid for once per remaining turn. When TypeSafe scoring is enabled, each
result is scored in chunks before it joins that history and only the parts bearing on
the question are kept:
worker_runtime.py 12,247 -> 1,256 chars 1 of 9 chunks kept
server.py 15,924 -> 1,491 chars 1 of 11 chunks kept
helpers.py 9,200 -> 3,193 chars 2 of 7 chunks kept
81% of bytes dropped across those reads with every answer still intact. Scoring is batched, so judging a dozen chunks costs about what judging one costs.
The gate fails open. A scoring error, an exhausted call budget, a result too small to
judge, a flat score distribution, or an exhaustive question (every, all, list)
all return the original text untouched — exhaustive questions need every mention, and
relevance scores cannot tell the last one from noise.
The gate supports TypeSafe System One models (uvx --from 'rlm-tools[semantic]' rlm-tools with TYPESAFE_API_KEY) or Google's Decisions API (uvx --from 'rlm-tools[gemini]' rlm-tools with GEMINI_API_KEY and gemini-decision-1, requires Python 3.11+). To enable it, pass a sub-LLM key and scorer key (a single GEMINI_API_KEY can power both), set RLM_RECURSE_GATE=1, and include the repository in RLM_EXTERNAL_ROOTS. The configured provider receives the question and candidate excerpts, including excerpts the gate later drops.
Works With
RLM Tools is a standard MCP server. It works with any MCP-compatible client: Claude Code, Codex, Cursor, and others.
Optional Strict Mode
If your MCP client supports tool permissions or hooks, disable/block default read/grep/glob tools for repository exploration and keep rlm-tools enabled. This is the strongest way to force the token-efficient path.
Other installation methods
JSON MCP config (Cursor, Windsurf, etc.)
{
"mcpServers": {
"rlm-tools": {
"command": "uvx",
"args": ["rlm-tools"]
}
}
}
Setup helper command
# Auto-detect Claude/Codex CLIs and configure rlm-tools
uvx --from rlm-tools rlm-tools-setup
# Print JSON config snippet for other clients
uvx --from rlm-tools rlm-tools-setup --print-json
# Print policy text instead of writing it
uvx --from rlm-tools rlm-tools-setup --print-policy
Direct run
uvx rlm-tools
From source
git clone https://github.com/stefanoshea/rlm-tools.git
cd rlm-tools
uv sync
uv run rlm-tools
Then point your MCP client to command: uv, args: ["--directory", "/path/to/rlm-tools", "run", "rlm-tools"], and set RLM_ALLOWED_ROOTS to the checkout you want to explore.
Configuration
Set these variables in the MCP server environment and restart the server after changing them. By default, the server allows exploration underneath its launch directory. If a client launches it from your home directory or the filesystem root, configure an explicit workspace. Multiple roots use the platform path separator (: on macOS and Linux).
For example, this configuration permits local exploration of two repositories and enables sub-LLM helpers only for the second, when the server also has an Anthropic, Gemini, or OpenAI-compatible provider configured:
{
"RLM_ALLOWED_ROOTS": "/work/private:/work/shareable",
"RLM_EXTERNAL_ROOTS": "/work/shareable"
}
A grant covers the named directory and its descendants. Keep private repositories outside roots granted external processing. The configured provider (Anthropic, Gemini, OpenAI, or any OpenAI-compatible Chat Completions endpoint such as OpenRouter, Ollama, LM Studio, or vLLM) receives the prompts, context, and tool results used by the model helpers. OpenAI-compatible support works out of the box with no extra dependencies. Enabling the optional evidence gate also sends the question and candidate excerpts to TypeSafe or Gemini (gemini-decision-1). Ordinary read, grep, glob, and tree operations require no provider and do not import provider SDKs at startup. Keep real credentials in your client's secret configuration or an environment file outside the explored checkout.
| Variable | Default | Description |
|---|---|---|
RLM_ALLOWED_ROOTS |
Server launch directory, except home or filesystem root | Absolute directories the operator permits sessions to explore. An explicitly empty list denies all roots. |
RLM_EXTERNAL_ROOTS |
Empty | Subset of allowed directories eligible for external model helpers. |
ANTHROPIC_API_KEY |
— | Enables Anthropic model helpers for external-enabled sessions. |
GEMINI_API_KEY |
— | Enables Gemini Interactions helpers and gemini-decision-1 gate ([gemini] extra, Python 3.11+). |
OPENAI_API_KEY |
— | Enables OpenAI (or OpenAI-compatible) llm_query() / rlm_recurse() helpers. |
OPENAI_BASE_URL |
https://api.openai.com/v1 |
Custom OpenAI-compatible Chat Completions base URL (supports keyless local Ollama/vLLM/LM Studio endpoints when set alone). |
RLM_SUB_PROVIDER |
auto |
Sub-LLM provider: auto (Anthropic, then Gemini, then OpenAI-compatible), anthropic, gemini, or openai (openai-compatible). |
TYPESAFE_API_KEY |
— | Credential for optional TypeSafe scoring. |
TYPESAFE_DEFAULT_MODEL |
jev-latest |
System One model used by the TypeSafe evidence gate. |
RLM_GATE_PROVIDER |
auto |
Gate provider: auto (TypeSafe if key set, else Gemini), typesafe, or gemini. |
GEMINI_DECISION_MODEL |
gemini-decision-1 |
Gemini Decisions model used when RLM_GATE_PROVIDER=gemini (or auto with GEMINI_API_KEY). |
RLM_RECURSE_GATE |
0 |
Set to 1 to enable evidence-gate scoring for external-enabled sessions. |
RLM_SUB_MODEL |
claude-haiku-4-5-20251001 / gemini-3.5-flash-lite / gpt-4.1-mini |
Model used for llm_query() / rlm_recurse() (defaults by active provider). |
RLM_SUB_TIMEOUT_SECONDS |
60 |
Per-request timeout for sub-LLM calls |
RLM_SUB_MAX_RETRIES |
3 |
Retry attempts for transient sub-LLM failures |
RLM_RECURSE_MAX_DEPTH |
2 |
Max recursion depth for rlm_recurse() child agents |
RLM_MAX_SESSIONS |
5 |
Max concurrent sessions |
RLM_SESSION_TIMEOUT |
10 |
Session timeout in minutes |
Security
The stdio server is designed for one local MCP client. It starts each Python worker with an empty environment, a private IPC socket, and isolated Python startup. macOS uses Seatbelt. Linux requires libseccomp.so.2 and permits the system calls needed for computation and the private socket. Worker startup fails if the OS or launcher cannot apply the policy, including hosts that forbid nested macOS sandboxing. The trusted parent holds repository descriptors and provider credentials.
- A session can open only an operator-approved directory. Helpers open paths relative to a retained directory descriptor, skip symlinks and multiply linked files, and read regular files only. They exclude Git metadata, local MCP configuration, registry token files, and
.envvariants except.env.example,.env.sample, and.env.template. Other files within the root can be returned to the agent. - Reads, batches, regex searches, directory scans, and IPC messages have size limits. A file read returns at most 4 MiB of source text plus a truncation marker. Grep uses RE2 syntax and a 1 MiB engine memory budget. For patterns that need Python lookaround or backreferences, apply the worker's
remodule to a bounded file read. Narrow the path or pattern when a search reports a limit. Metadata can includetruncated: true. - Workers enforce an execution timeout, restrict Python imports and builtins, and bound printed output. CPU and address-space backstops depend on OS support. Parent-side model requests use the remaining execution time for their network timeouts. An in-flight filesystem or network operation can still delay a response.
- Model helpers are enabled per root. A local session never registers them, even when the server has provider credentials. Treat any root enabled for external processing as shareable with the selected providers.
Background
RLM Tools implements an RLM-style exploration loop: keep raw data in tool-side memory, send only compact outputs to the model. Built on the Model Context Protocol.
Development
git clone https://github.com/stefanoshea/rlm-tools.git
cd rlm-tools
uv sync --locked --extra dev
uv run --no-sync python -m pytest
Run fixture-backed evals:
uv run python -m pytest evals -q
Run comparative benchmarks:
uv run python -m pytest evals/test_comparative.py -q -s
Run scored prompt benchmarks:
./evals/run_ab_eval.sh
By default this now runs the checked-in long-context benchmark corpus at tests/fixtures/rlm_corpus_longcontext. Use RLM_AB_SPEC_PATH and RLM_AB_TARGET_PATH to switch back to lighter smoke-style cases or to point at a different corpus.
License
MIT
Metadata
Release files for rlm-tools 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| rlm_tools-0.2.0.tar.gz | 306.9 kB | With provenance | Details for rlm_tools-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| rlm_tools-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for rlm_tools-0.2.0-py3-none-any.whl |
Total release size: 358.7 kB
Release files / rlm_tools-0.2.0.tar.gz
| Download URL | rlm_tools-0.2.0.tar.gz |
|---|---|
| Size | 306.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b39d44f33d58c01c9cbeec846aa6dbb971d5666cf311367740664a5fbd020905
|
|
BLAKE2b-256 checksum How to use checksums |
df72dd9daf07c1c306d99ccdc38936d5b4fffb920a65c3959752c3df4bd4e689
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 24, 2026.
Transparency logRelease files / rlm_tools-0.2.0-py3-none-any.whl
| Download URL | rlm_tools-0.2.0-py3-none-any.whl |
|---|---|
| Size | 51.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e6e0b76038df5dbcd23e1dea0500468fbe26f1d16df4d97a5d20c5a3fa0fb769
|
|
BLAKE2b-256 checksum How to use checksums |
56a556ca37ac0a47d70d98363115023b6f7f8eab9d51e247bdf65872ea38c941
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 24, 2026.
Transparency logSecurity for rlm-tools 0.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for rlm_tools-0.2.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 24, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.