Our review
rlm is a command-line tool that uses recursive sub-queries to process very long contexts while reducing token usage.
Strengths
- Handles arbitrarily long contexts by programmatically exploring chunks of text.
- Typically saves about 40% tokens on documents larger than 50KB.
- Flexible Query() and FINAL() patterns enable targeted, iterative analysis.
- Supports multiple input modes: file, string, and stdin.
Limitations
- Requires binary installation and an Anthropic API key.
- Not worth the overhead for contexts under 10KB or simple questions.
- Effectiveness depends on the generated code and the max-iterations setting.
Use rlm when analyzing large files or logs over 50KB where token efficiency is important.
Avoid rlm for short contexts, simple single-turn questions, or tasks that do not require data exploration.
Security analysis
SafeThe skill describes a legitimate tool for processing large contexts with an LLM. It does not instruct the agent to perform destructive, exfiltrating, or obfuscated actions. The installation command using curl|sh is for user reference and not automatically executed.
No concerns found
Examples
Use the rlm tool to analyze server.log and find all unique error patterns with their frequencies.Process data.json with rlm and extract all user IDs that have failed transactions, showing the result in JSON.Pipe all .go source files in the current directory into rlm and identify every exported function with its purpose.name: rlm description: Recursive Language Model for processing large contexts (>50KB). Use for complex analysis tasks where token efficiency matters. Achieves 40% token savings by letting the LLM programmatically explore context via Query() and FINAL() patterns. allowed-tools:
- Bash
RLM - Recursive Language Model
RLM is an inference-time scaling strategy that enables LLMs to handle arbitrarily long contexts by treating prompts as external objects that can be programmatically examined and recursively processed.
- License: MIT
- Repository: https://github.com/XiaoConstantine/rlm-go
When to Use
Use rlm instead of direct LLM calls when:
- Processing large contexts (>50KB of text)
- Token efficiency is important (40% savings on large contexts)
- The task requires iterative exploration of data
- Complex analysis that benefits from sub-queries
Do NOT Use When
- Context is small (<10KB) - overhead not worth it
- Simple single-turn questions
- Tasks that don't require data exploration
Command Usage
# Basic usage with context file
~/.local/bin/rlm -context <file> -query "<query>" -verbose
# With inline context
~/.local/bin/rlm -context-string "data" -query "<query>"
# Pipe context from stdin
cat largefile.txt | ~/.local/bin/rlm -query "<query>"
# JSON output for programmatic use
~/.local/bin/rlm -context <file> -query "<query>" -json
Options
| Flag | Description | Default |
|------|-------------|---------|
| -context | Path to context file | - |
| -context-string | Context string directly | - |
| -query | Query to run against context | Required |
| -model | LLM model to use | claude-sonnet-4-20250514 |
| -max-iterations | Maximum iterations | 30 |
| -verbose | Enable verbose output | false |
| -json | Output result as JSON | false |
| -log-dir | Directory for JSONL logs | - |
How It Works
RLM uses a Go REPL environment where LLM-generated code can:
- Access context as a string variable
- Make recursive sub-LLM calls via
Query()for focused analysis - Use standard Go operations for text processing
- Signal completion with
FINAL()when done
The Query() Pattern
// LLM generates code like this inside the REPL:
chunk := context[0:10000]
summary := Query("Summarize the key findings in this text: " + chunk)
// ... iterate through more chunks
FINAL(combinedResult)
The FINAL() Pattern
The LLM signals completion by calling:
FINAL("answer")- Return a string answerFINAL_VAR(variableName)- Return value of a variable
Token Efficiency Benefits
For large contexts (>50KB), RLM typically achieves 40% token savings by:
- Only sending relevant context chunks to sub-queries
- Avoiding repeated full-context processing
- Using programmatic iteration instead of full-context reasoning
Examples
Analyze Log Files
rlm -context server.log -query "Find all unique error patterns and their frequencies"
Process JSON Data
rlm -context data.json -query "Extract all user IDs with failed transactions" -verbose
Code Analysis
cat src/*.go | rlm -query "Identify all exported functions and their purposes"
Requirements
ANTHROPIC_API_KEYenvironment variable must be set- Binary installed at
~/.local/bin/rlm
Installation
# Quick install
curl -fsSL https://raw.githubusercontent.com/XiaoConstantine/rlm-go/main/install.sh | bash
# Or with Go
go install github.com/XiaoConstantine/rlm-go/cmd/rlm@latest
Prompt Engineering
Data & AI
Prompt engineering best practices and templates to maximize AI outputs.
Data Visualization
Data & AI
Generates data visualizations and charts tailored to your data.
RAG Architecture Setup
Data & AI
Setup guide for RAG (Retrieval-Augmented Generation) architectures.