rlm-tools
Summary: RLM Tools is a read-only MCP server that gives a coding agent a persistent, sandboxed Python session for exploring a repository — running searches and analysis server-side so only compact summaries reach the conversation.
Open a session on a directory (
rlm_startwith an absolutepath+query), optionally running initial Python code immediately and tuning limits (execute calls, LLM calls, memory, output size, timeout).Explore files with built-in helpers in that sandbox:
read_file/read_files,grep,grep_summary,grep_read,glob_files,tree, plus Python AST helpers (outline,enclosing,find_assignments).Keep state across calls: run Python via
rlm_execute; variables persist between calls within a session, so you can search → filter → read → analyze incrementally.Return only compact results: print summaries, or use
rlm_finalize(value)for structured output, keeping large payloads out of the context window (e.g. 500 grep hits → 5 summary lines).Optionally call sub-models:
llm_query/llm_query_batchedfor analysis of supplied context, andrlm_recurse/rlm_recurse_batchedfor sub-agents that explore the session directory — only in roots explicitly enabled for external processing, with an Anthropic/Gemini/OpenAI-compatible/claude-cli provider configured.Run within a restricted sandbox: only select stdlib imports (
re,json,collections,math, etc.);os,glob,pathlib,ast,open(),exec(),eval(),getattr()andstr.format()are blocked.Close sessions efficiently: pass
end_session=trueon the finalrlm_execute, or callrlm_endexplicitly to free resources.Control response verbosity with
detail_level(compact/usage/full) and cap returned variables viamax_new_variables.
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@rlm-tools explore the auth module and summarize its imports"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
RLM Tools
RLM Tools gives coding agents a read-only Python sandbox for exploring a repository. An agent can search files, keep results in memory across calls, and return a count, a list of paths, or a short excerpt to the conversation. Local exploration needs no API key. Optional model helpers (llm_query, rlm_recurse) can send repository content to Anthropic, Gemini, any OpenAI-compatible endpoint (OpenAI, OpenRouter, Ollama, vLLM, LM Studio), or a logged-in local Claude Code CLI (claude-cli) when you enable them for that workspace.
Plugins & Extensions
The plugins register the MCP server and install the rlm-explore skill for Codex CLI, Claude Code, and Gemini CLI. The server runs on macOS and Linux and requires uvx on the client's PATH. Run uvx --version in your terminal to check. Linux also requires libseccomp.so.2. Release notes · Install uv
For Cursor, VS Code, Kiro, and standalone MCP setup, see other clients and installation methods.
Codex CLI
Install the plugin once from your terminal.
codex plugin marketplace add stefanoshea/rlm-tools
codex plugin add rlm-tools@rlm-toolsEach time you start Codex, run this from the repository you want to explore. Codex launches the server in the installed plugin directory, so the workspace grant tells it which checkout it can read.
RLM_ALLOWED_ROOTS="$(pwd -P)" codex --no-daemonClaude Code
Open Claude Code in your repository and enter these commands at the Claude prompt.
/plugin marketplace add stefanoshea/rlm-tools
/plugin install rlm-tools@rlm-toolsThe plugin also bundles an rlm-explorer subagent (model: haiku, restricted to rlm-tools) so Claude Code subscribers get parallel, context-isolated sandboxed exploration out of the box. To also run programmatic llm_query() / rlm_recurse() calls inside sandbox Python scripts on your Claude subscription without an API key, see Claude Code subscription (claude-cli).
Gemini CLI
Install the extension from your terminal.
gemini extensions install https://github.com/stefanoshea/rlm-toolsRestart Gemini in your repository and run /skills list. You should see rlm-explore, ready to load when an exploration task needs it.
Try it
Try this prompt in the client you just configured.
Use RLM Tools to list the top-level directories in this repository, then close the session.
The agent should call rlm_start, run tree(max_depth=1) through rlm_execute, and close the session, ideally by passing end_session=true on that last rlm_execute call (a separate rlm_end also works). If startup returns Directory outside RLM_ALLOWED_ROOTS, check that the MCP server received the absolute path to your checkout. Workspace configuration
Related MCP server: projscan
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.
Live paired A/B runs against Gemini (gemini-3.5-flash-lite, exact JSON grading) show where the tool wins and where it does not:
Repository | Arm | Pass rate | Mean tokens |
230 files, 1.28 MB ( | Native | 60% (3/5) | 315,676 |
230 files, 1.28 MB ( | RLM Tools | 100% (5/5) | 31,208 (−90.1%) |
~28 KB ( | Native | 100% (11/11) | 23,464 |
~28 KB ( | RLM Tools | 81.8% (9/11) | 58,986 |
The heavy row is the 2026-11-24 run after the sandbox-contract and end_session changes; an earlier run of the same tasks measured native tools at 40% pass and 469,392 tokens against RLM Tools at 100% and 59,389 (−87.3%). The long_context row predates those changes, and a later re-run only completed 5 of 11 pairs before hitting a provider quota, so treat it as a baseline. On narrow lookups in small repositories, native tools use about 2.5× fewer tokens because opening and closing a session adds fixed overhead. Route narrow lookups to native tools and use RLM Tools for broad searches, audits, large files, and multi-step analysis; rlm-tools-setup --write-policy writes that guidance into AGENTS.md or CLAUDE.md.
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 |
| Open a session on a directory (optionally run initial code immediately) |
| Run Python in the sandbox (set |
| Explicitly close session and free resources |
The sandbox provides built-in helpers:
read_file(path, start_line=None, end_line=None)/read_files(paths)— Read files or line slices into variables (cached across calls)grep(pattern)/grep_summary(pattern)/grep_read(pattern)— Searchglob_files(pattern, include_ignored=False)— Find files by pattern (passinclude_ignored=Trueto include.gitignored non-secret files)tree(path, max_depth)— Directory structureoutline(path)/enclosing(path, line)/find_assignments(path, target)— Python AST outline (withparentanddepthon every class/function), scope, and assignment lookupllm_query(prompt, context)/llm_query_batched(prompts, context)— Sub-LLM analysis when full context is already in the prompt (optional, requires a provider key,OPENAI_BASE_URL, orRLM_SUB_PROVIDER=claude-cli)rlm_recurse(prompt, context)/rlm_recurse_batched(prompts, context)— Ask a sub-agent to explore the session directory and check code (optional, requires a provider key,OPENAI_BASE_URL, orRLM_SUB_PROVIDER=claude-cli;max_llm_callsdefaults to300, size≈ 4×Nfor N-item recursion; children hittingRLM_CHILD_MAX_TOTAL_TOOL_CHARSreturn a[BUDGET_EXHAUSTED]prefix and incrementusage.child_budget_exhausted)
The sandbox allows only these imports: re, json, collections, math, fnmatch, itertools, functools, operator, string, textwrap, difflib, statistics. os, glob, pathlib, ast, open(), exec(), eval(), getattr(), and str.format() are blocked. Use the helpers and f-strings instead. rlm_start returns the current allowed_imports list (and other_open_sessions if you already have sessions open).
rlm_finalize(value)— Return structured final output inrlm_executeresponses
Variables persist across rlm_execute calls within a session (and truncated stdout is retained in _last_stdout for follow-up paging). 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 kept81% of bytes dropped across those reads with every answer still intact. In a later
direct check with Google's gemini-decision-1 on three source files (llm_bridge.py,
helpers.py, server.py), the gate dropped 91% of characters (73,068 to 6,381) with every
answer surviving, at roughly one second per gate call. These are single-file measurements of
the gate itself. The gate is off by default and was not enabled in the benchmark runs above.
Chunks are split at 40 lines or 2,400 characters, whichever comes first, and each chunk is sent to the scorer in full. Scoring is batched (12 chunks per request), so judging a dozen chunks costs one request.
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.
Other clients
Cursor, VS Code / GitHub Copilot, and Amazon Kiro can use the Agent Plugins 1.0 package in plugins/rlm-tools. If your client starts the server from the plugin directory, set
RLM_ALLOWED_ROOTSto the absolute checkout path in the server environment.Agent Skills clients such as Windsurf, OpenCode, Cline, and Zed can use the standalone skill alongside a standard MCP registration for
uvx rlm-tools.
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.
JSON MCP config (Cursor, Windsurf, etc.)
{
"mcpServers": {
"rlm-tools": {
"command": "uvx",
"args": ["rlm-tools"]
}
}
}Setup helper command
To configure a single client and write exploration guidance into the current repository, run the corresponding command from its root.
# Codex
uvx --from rlm-tools rlm-tools-setup --client codex --write-policy AGENTS.md
# Claude Code
uvx --from rlm-tools rlm-tools-setup --client claude --write-policy CLAUDE.mdTo register just the server manually, use codex mcp add rlm-tools -- uvx rlm-tools or claude mcp add rlm-tools -- uvx rlm-tools.
# 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-policyDirect run
uvx rlm-toolsFrom source
git clone https://github.com/stefanoshea/rlm-tools.git
cd rlm-tools
uv sync
uv run rlm-toolsThen 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, OpenAI-compatible, or claude-cli 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, any OpenAI-compatible Chat Completions endpoint such as OpenRouter, Ollama, LM Studio, or vLLM, or the local claude CLI) 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 |
| Server launch directory, except home or filesystem root | Absolute directories the operator permits sessions to explore. An explicitly empty list denies all roots. |
| Empty | Subset of allowed directories eligible for external model helpers. |
| — | Enables Anthropic model helpers for external-enabled sessions. |
| — | Enables Gemini Interactions helpers and |
| — | Enables OpenAI (or OpenAI-compatible) |
|
| Custom OpenAI-compatible Chat Completions base URL (supports keyless local Ollama/vLLM/LM Studio endpoints when set alone). |
|
| Sub-LLM provider: |
| — | Credential for optional TypeSafe scoring. |
|
| System One model used by the TypeSafe evidence gate. |
|
| Gate provider: |
|
| Gemini Decisions model used when |
|
| Set to |
|
| Model used for |
|
| Max concurrent |
|
| Per-request timeout for sub-LLM calls |
|
| Retry attempts for transient sub-LLM failures |
|
| Max recursion depth for |
|
| Max characters per individual tool result returned to an |
|
| Cumulative tool-result character budget per |
|
| Max concurrent sessions (idle sessions over |
|
| Session timeout in minutes |
|
| Minimum idle seconds before an inactive session can be evicted at |
|
| Default per-session retained memory cap in bytes |
|
| Default per- |
|
| Max bytes read per workspace scan ( |
|
| Max directory entries visited per workspace scan |
|
| Max wall-clock seconds per workspace scan |
Claude Code subscription (claude-cli)
To power llm_query() and rlm_recurse() from an existing Claude Code subscription login without an API key:
Install Claude Code and log in once with
claude(confirmclaude --versionworks onPATH).Set these variables on the
rlm-toolsMCP server (either in your MCP client config or viaclaude mcp add), pointing both roots at the parent directory or repository you want external helpers to inspect:
{
"env": {
"RLM_SUB_PROVIDER": "claude-cli",
"RLM_ALLOWED_ROOTS": "/path/to/your/workspace",
"RLM_EXTERNAL_ROOTS": "/path/to/your/workspace"
}
}Explicit opt-in only:
RLM_SUB_PROVIDER=claude-cli(aliasesclaude_cli,claude-code) is never selected inautomode.No token extraction:
rlm-toolsnever reads or passes your OAuth token. Instead, it runsclaude -pas a subprocess withANTHROPIC_API_KEY,ANTHROPIC_AUTH_TOKEN,ANTHROPIC_BASE_URL, and nested-session variables (CLAUDECODE,CLAUDE_CODE_ENTRYPOINT,CLAUDE_CODE_SSE_PORT) stripped from the child environment, inside a temporary working directory with tools disabled, an empty strict MCP config ({"mcpServers":{}}),--setting-sources "", and--safe-mode.Latency & usage limits: Each call starts a new
claude -pprocess (~1–2 seconds of startup overhead per call), so it is slower than direct API calls and counts toward your Claude subscription usage limits. When runningllm_query_batched()orrlm_recurse(),execution_timeout_secondsdefaults to180forclaude-cli, and you can adjustRLM_CLI_MAX_CONCURRENCY(default8) orRLM_SUB_MODEL(defaulthaiku) as needed.
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 (
.git), local MCP and agent config (.mcp.local.json,settings.local.json), registry/auth token files (.npmrc,.pypirc,.netrc,.mcpregistry_*), and.envvariants except.env.example,.env.sample, and.env.template(committed.mcp.jsonfiles remain readable). 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.Python imports expose selected public names from approved standard-library modules. Relative imports, private attributes, and wrapper helpers are restricted inside the OS-confined worker.
Workers enforce an execution timeout, restrict Python imports and builtins, and bound printed output. Per-session retained memory (default
64 MiB) is enforced post-execution with variable eviction backstops, and LinuxRLIMIT_AScaps runaway virtual allocations in flight (macOS ignoresRLIMIT_AS). 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 pytestRun fixture-backed evals:
uv run --extra dev python -m pytest evals -qRun comparative benchmarks:
uv run --extra dev python -m pytest evals/test_comparative.py -q -sRun scored prompt benchmarks:
./evals/run_ab_eval.shBy 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
Available Tools
3 toolsrlm_endA
End an RLM exploration session and free resources. Prefer passing end_session=true on your final rlm_execute call to save a turn.
Inputs: session_id (required). Returns: result
rlm_executeA
Execute Python in the session sandbox and return printed stdout. Set end_session=true on your final step to close the session without a separate rlm_end call.
Inputs: code (required), session_id (required), end_session, detail_level, +1 more. Returns: result
rlm_startA
Start a persistent RLM exploration session once per task (returns session_id, limits, available_functions, allowed_imports). Optionally pass initial code to explore immediately, then use rlm_execute(session_id, ...) for follow-up steps and pass end_session=true on your final rlm_execute call (do not call rlm_start repeatedly).
Inputs: path (required), query (required), code, max_llm_calls, +6 more. Returns: result
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 3 tools
rlm_start and rlm_execute have clearly distinct roles, but rlm_end overlaps directly with rlm_execute's end_session=true parameter. The descriptions themselves admit the redundancy ("Prefer passing end_session=true... to save a turn"), leaving an agent to decide between two ways to close a session.
All three tools use the same rlm_ prefix with a bare verb (rlm_start, rlm_execute, rlm_end). The pattern is uniform and instantly readable as a lifecycle sequence.
Three tools for a session-scoped Python sandbox is a tight, sensible surface rather than a padded one. It is slightly leaner than ideal because rlm_end is effectively a convenience duplicate of a flag on rlm_execute.
The full session lifecycle (start, execute, end) plus returned limits/available_functions covers the core workflow with no dead ends. Minor gaps remain: no way to interrupt a long-running execution, reset a session, or inspect state without executing code.
Maintenance
Related MCP Connectors
An MCP server that gives your AI access to the source code and docs of all public github repos
Free MCP server for AI agents: Python/JS sandbox, file-to-markdown, speech-to-text.
MCP server for building and testing AI agents with multi-model experimentation and insights.
An MCP server that provides agents access to the KeldynAI platform
Related MCP Servers
- AlicenseNot gradedqualityDmaintenanceAn MCP server that gives AI agents structured code understanding and precise code intelligence via local indexing of AST, call graphs, and semantic search.81 npm4Apache 2.0
- AlicenseNot gradedqualityBmaintenanceAn MCP server that provides AI coding agents with AST-accurate, context-budget-aware codebase querying, safety gates, and team policy integration via structured tools and a local plugin layer.313 npm4MIT
- AlicenseNot gradedqualityDmaintenanceA local MCP server that gives AI coding agents persistent memory and context across sessions.11 npmMIT
- AlicenseNot gradedqualityDmaintenanceAn MCP server that enables AI agents to navigate and understand codebases through file descriptions, semantic search, and code recommendations without repeatedly scanning files.MIT