A modular runtime for recursive improvement in long-running LLM agents
Context Cleaner is available, with the same plan, approval, status, and cancellation model across hosts. In Codex, /lightrsi-clean opens the host-rendered task selector; the direct terminal equivalent is lightrsi codex clean. Analysis is read-only until you confirm a selection, and protected tasks cannot be selected.
LightRSI separates reusable improvement capabilities from shared runtime infrastructure and host-specific integration. TokenPilot is the first preset.
| Papers | What It Does | How It Works | Effect |
|---|---|---|---|
TokenPilot |
Keeps long-running agent sessions smaller, cheaper, and easier to sustain | Stabilizes the reusable prompt prefix, trims oversized tool output before it poisons later turns, and limits how much old context is carried forward as sessions grow | Better cache reuse, lower token usage, lower cost, and less context bloat in shared sessions |
- π’ News
- π οΈ Products
- π Papers
- π§ Installation
- β‘ Quick Start
- πΌοΈ Visual Results
- ποΈ Architecture
- π§ͺ Experiment Reproduction
- π‘ Commands
- π Experimental Results
- π Citation
- π€ Contributing
- π Contributors
- π Related Works
- π¬ Community
- [2026-09-16]: π Context Cleaner, our first product, is now available, and TokenPilot now supports DeepSeek Harness.
- [2026-08-21]: πππ TokenPilot: Cache-Efficient Context Management for LLM Agents has been accepted by EMNLP 2026!
- [2026-06-28]: π§© TokenPilot now supports Codex and Claude Code. Demo video: YouTube Β· Bilibili
- [2026-06-16]: π TokenPilot: Cache-Efficient Context Management for LLM Agents is released.
Clone the repository and build the shared packages:
git clone https://github.com/zjunlp/LightRSI.git
cd LightRSI
corepack enable
pnpm installThe Host-specific Cleaner installer below builds the shared CLI, recovery MCP, and selected adapter before installing them. A separate repository-wide build is not required for this flow.
Open the host you want and run the default install commands.
OpenClaw
Default install:
pnpm component:install:tokenpilot:openclawThis installs the current TokenPilot OpenClaw adapter, updates ~/.openclaw/openclaw.json, enables the plugin, switches plugins.slots.contextEngine to layered-context, applies the default normal mode, and tries to restart the OpenClaw gateway automatically.
If your OpenClaw home or config path is not under the default ~/.openclaw, set:
export LIGHTRSI_OPENCLAW_HOME="/path/to/openclaw-home"
export OPENCLAW_CONFIG_PATH="/path/to/openclaw.json"Then run the same install command again:
pnpm component:install:tokenpilot:openclawCodex CLI
Default install:
corepack pnpm cleaner:install:codexThis builds and installs the shared CLI, recovery MCP, Codex adapter, and the
explicit-only lightrsi-clean, lightrsi-clean-status,
lightrsi-clean-apply, and lightrsi-clean-cancel command skills. It keeps
your current active Codex provider, reroutes it through the local TokenPilot
proxy, writes ~/.codex/tokenpilot.json, and registers the required hooks and
MCP server.
If your Codex config files are not under the default ~/.codex, set:
export CODEX_CONFIG_PATH="/path/to/config.toml"
export CODEX_HOOKS_CONFIG_PATH="/path/to/hooks.json"
export TOKENPILOT_CODEX_CONFIG="/path/to/tokenpilot.json"Then run the same install flow:
corepack pnpm cleaner:install:codexOn Windows, the installer uses the npm command directory when that directory is
already on PATH and creates lightrsi.cmd. On Linux/macOS it installs under
~/.local/bin by default. Set LIGHTRSI_BIN_DIR to choose another command
directory.
Claude Code
Default install:
corepack pnpm cleaner:install:claude-codeThis builds and installs the shared CLI, recovery MCP, Claude Code adapter, and
the explicit-only Cleaner analysis, status, apply, and cancel command skills. It
updates local gateway routing, registers the required hooks and MCP server, and
preserves existing Claude files as .tokenpilot.bak backups before rewriting.
If your Claude Code files are not under the default ~/.claude, set:
export CLAUDE_CODE_SETTINGS_PATH="/path/to/settings.json"
export CLAUDE_CODE_MCP_CONFIG_PATH="/path/to/.claude.json"
export TOKENPILOT_CLAUDE_CODE_CONFIG="/path/to/tokenpilot.json"Then run the same install flow:
corepack pnpm cleaner:install:claude-codeUse node scripts/install-cleaner.mjs <host> --dry-run to inspect the exact build
and installation commands without changing Host configuration.
Add --skip-build only when reusing an existing local build; the installer
rejects missing or older CLI, MCP, and adapter artifacts before changing Host
configuration.
DeepSeek Harness
The DeepSeek Harness adapter is a native Cordis plugin and is installed into a DeepSeek Harness checkout rather than through the shared CLI. Build a local package from this repository:
corepack pnpm --filter @lightrsi/deepseek-harness-adapter build
corepack pnpm --filter @lightrsi/deepseek-harness-adapter pack --pack-destination ./artifactsFrom the DeepSeek Harness checkout, add the generated .tgz to the profile you use, such as web:
node --import tsx/esm apps/cli/src/bin.ts plugin --profile web add /absolute/path/to/lightrsi-deepseek-harness-adapter-<version>.tgzThe plugin is registered as tokenpilot-dsh and is disabled by default. Configure and enable it only after supplying a durable stateDir and the estimator and eviction settings required by your Harness profile. Its failure mode is fail-open, so an optimization failure does not block the agent.
Pick your host and open the matching one-pass setup below.
OpenClaw
- Start or restart OpenClaw.
- Open a session with a
lightrsi/<model>model such aslightrsi/gpt-5.4-mini. - Run:
/lightrsi status
You should see a status block similar to:
- plugin entry enabled
- config enabled
- mode
normal - context engine slot
layered-context - stabilizer enabled
- reduction enabled
For a fuller runtime summary, run:
/lightrsi report
/lightrsi doctor
/lightrsi visual
/lightrsi mode normal
/lightrsi doctor is the quickest integration self-check for the current OpenClaw adapter surface. /lightrsi visual opens the local visual inspector for stability, reduction, and eviction snapshots. /lightrsi mode <conservative|normal|aggressive> switches preset runtime behavior.
You can also use the standalone CLI outside OpenClaw:
lightrsi openclaw status
lightrsi openclaw report
lightrsi openclaw doctor
lightrsi openclaw visual
lightrsi openclaw mode normalCodex CLI
The current Codex path uses the standalone CLI plus Codex hooks.
- Run the Codex install flow shown above.
- Start Codex normally.
- If Codex asks you to review or trust the installed TokenPilot hooks, approve them.
- Open a new Codex session so
SessionStartcan start the local proxy. - In another terminal, verify the adapter:
lightrsi codex status
lightrsi codex doctor
lightrsi codex report
lightrsi codex mode normal
lightrsi codex reduction status
lightrsi codex stabilizer target userExpected first-run shape:
lightrsi codex doctorreportsproxy healthy: yeslightrsi codex statusshowsstabilizerandreductionenabled- after a few turns,
lightrsi codex reportno longer saysNo TokenPilot session stats yet.
Install success does not always mean the proxy is already running before the first trusted session. If doctor still reports proxy healthy: no after trusting hooks and opening a new Codex session, use the manual fallback:
tokenpilot-codex status
tokenpilot-codex startClaude Code
The current Claude Code path also uses the standalone CLI, but routes requests through a local Anthropic-compatible gateway and a shared MCP recovery server.
- Run the Claude Code install flow shown above.
- Start Claude Code normally.
- Open a new Claude Code session so
SessionStartcan auto-start the local gateway. - In another terminal, verify the adapter:
lightrsi claude-code status
lightrsi claude-code doctor
lightrsi claude-code report
lightrsi claude-code mode normal
lightrsi claude-code reduction status
lightrsi claude-code stabilizer target developerExpected first-run shape:
lightrsi claude-code doctorreportsproxy healthy: yeslightrsi claude-code statusshowsstabilizerandreductionenabled- after a few turns,
lightrsi claude-code reportno longer saysNo TokenPilot session stats yet.
Like Codex, install success does not guarantee that the gateway is already healthy before the first real session triggers SessionStart.
DeepSeek Harness
After adding and enabling the tokenpilot-dsh Cordis plugin, open a DeepSeek
Harness session and run:
/tokenpilot-status
The command reports estimator, scheduling, application, and deferral state without creating a model turn. By default, the adapter runs its eviction pass before the Harness's native compaction; preserve this ordering unless you deliberately change the profile configuration.
The screenshots below come from the built-in visual inspector opened with:
lightrsi visual
The current public repository separates reusable capabilities, verified presets, host adapters, and user-facing products.
At a high level:
components/packages- shared foundation and independently composable feature packages
components/presets- verified feature combinations such as TokenPilot
components/adapters- host-specific integration, install surfaces, runtime hooks, and product registration
components/products- shared CLI, Visual launcher, recovery MCP, and interactive Cleaner surfaces
LightRSI/
βββ components/
β βββ packages/
β β βββ foundation/ # contracts, runtime, host, history, artifact, product infrastructure
β β βββ features/ # stabilizer, reduction, eviction, and memory
β βββ presets/
β β βββ tokenpilot/ # Stabilizer + Reduction + Eviction composition contract
β βββ adapters/
β β βββ openclaw/ # OpenClaw adapter
β β βββ codex/ # Codex CLI adapter
β β βββ claude-code/ # Claude Code adapter
β β βββ deepseek-harness/ # native DeepSeek Harness Cordis adapter
β βββ products/
β βββ cli/ # shared lightrsi CLI, browser visual launcher, and Cleaner UI
β βββ mcp/ # shared recovery and interactive MCP session support
βββ docs/ # Public-facing notes and smoke helpers for the current runtime path
βββ website/ # Documentation site
βββ README.md
TokenPilot is now a preset rather than a source-code parent directory. Each adapter explicitly binds the preset and contributes host discovery metadata; the shared CLI and Visual surface consume those registrations.
Benchmark tasks, runners, profiles, and analysis are maintained in the separate TokenPilot experiment repository. LightRSI contains the runtime and plugin platform; it no longer vendors the experiment harness.
Experiment entrypoints:
Use the basic commands first, then the session-aware and advanced ones when you need them.
Shared standalone CLI patterns:
lightrsi report
lightrsi visual
lightrsi use openclaw
lightrsi use codex session <session-id>
lightrsi context
lightrsi <host> session <session-id> reportlightrsi reportshows the latest available report across hostslightrsi visualopens the shared browser visual and lets you switch hosts and sessionslightrsi use <host>sets the default host for hostless CLI commandslightrsi use <host> session <session-id>pins the default session for laterreportandvisuallightrsi contextshows the current default host, pinned session, and remembered config targetlightrsi <host> session <session-id> reportreads one specific session directly
Pick your host for the command surface below.
OpenClaw
Inside an OpenClaw session:
/lightrsi status
/lightrsi report
/lightrsi doctor
/lightrsi visual
/lightrsi mode normal
/lightrsi stabilizer target developer
/lightrsi reduction mode balanced
/lightrsi eviction on
/lightrsi help
Outside OpenClaw, the standalone CLI supports the same host directly:
lightrsi openclaw status
lightrsi openclaw report
lightrsi openclaw doctor
lightrsi openclaw visual
lightrsi openclaw mode normal
lightrsi openclaw session <session-id> reportUseful OpenClaw-only controls:
mode aggressiveenables the most aggressive runtime policy preseteviction ...controls lifecycle-aware context evictionsettings details onexpands status output with more runtime detailstabilizer ...andreduction ...let you tune prefix stabilization and observation reduction directly
Codex CLI
Use the standalone CLI:
lightrsi codex status
lightrsi codex report
lightrsi codex doctor
lightrsi codex visual
lightrsi codex session <session-id> report
lightrsi codex reduction status
lightrsi codex stabilizer target developer
lightrsi codex mode normal
lightrsi codex reduction mode balanced
lightrsi codex helpUseful Codex controls:
stabilizer on|offtoggles stable-prefix rewritingstabilizer target <developer|user>chooses where dynamic context is attachedreduction on|offtoggles observation reductionreduction mode <light|balanced>switches between lighter and stronger trimmingreduction pass toolPayloadTrim offdisables one specific reduction passlightrsi codex cleananalyzes a session and interactively selects tasks to clean
Claude Code
Use the standalone CLI:
lightrsi claude-code status
lightrsi claude-code report
lightrsi claude-code doctor
lightrsi claude-code visual
lightrsi claude-code session <session-id> report
lightrsi claude-code reduction status
lightrsi claude-code stabilizer target developer
lightrsi claude-code mode normal
lightrsi claude-code reduction mode balanced
lightrsi claude-code helpUseful Claude Code controls:
stabilizer on|offtoggles stable-prefix rewritingstabilizer target <developer|user>chooses where dynamic context is attachedreduction on|offtoggles observation reductionreduction mode <light|balanced>switches between lighter and stronger trimmingreduction pass toolPayloadTrim offdisables one specific reduction pass
DeepSeek Harness
Inside a DeepSeek Harness session:
/tokenpilot-status
This read-only command reports estimator activity, eligible eviction work, scheduled or applied changes, and any deferrals. The DeepSeek Harness adapter is registered by Cordis as tokenpilot-dsh; it does not use the shared lightrsi CLI.
Benchmark tasks, runners, profiles, analysis, and result bundles are maintained in the separate TokenPilot experiment repository. This repository keeps only the runtime and plugin platform.
For the latest commands, configurations, and reported results, use the experiment repository as the source of truth.
Please cite our paper if you use LightRSI in your work.
@article{xu2026tokenpilot,
title={TokenPilot: Cache-Efficient Context Management for LLM Agents},
author={Xu, Buqiang and Xue, Zirui and Chen, Dianmou and Fu, Chenyang and Wu, Chiyu and Huang, Caiying and Jiang, Chen and Fang, Jizhan and Deng, Xinle and Chen, Yijun and others},
journal={arXiv preprint arXiv:2606.17016},
year={2026}
}We welcome bug fixes, host adapter improvements, onboarding fixes, tests, and documentation updates, see CONTRIBUTING.md for more details.
We thank all the contributors to this project, more contributors are welcome!




