Skip to main content

repo-context-optimizer

rco gives a coding agent a map of a repo as one JSON object: the signatures of each file, how modules fit together, and the parts of a file that changed. No model, no keys, and no network except tiktoken's one-time encoding download when the tokens extra is installed. Install with pip install repo-context-optimizer.

Two things set rco apart from grep, ctags and other search tools:

  • Token density: the agent reads only the fields it needs. rco answers with a JSON object, so an agent takes parts, a signature or a line range and skips the rest. The map may hold more than a task needs, which is safer than holding too little and scanning again. grep and similar tools print lines, and an agent reads that output top to bottom, then often searches again.
  • The measure is tokens to finish a task, not the size of one command's output. A short grep output that leads to rereading files and more searches can cost more in the end. rco is judged by the tokens an agent spends to complete a task with it and without it: the proof.

If you are an agent

rco: look up the map before the code

  • Run rco map --preload once per checkout.
  • Before you read code, run rco map --for FILE... for the files you will touch. It prints JSON.
  • Do not read a source file top to bottom: parts has each --for file's nodes and what changed against base. Open the file only to edit at the part you looked up.
  • The map is JSON, not text to grep: look things up with rco map --get NAME, --search REGEX or --list [KIND|PATH] (each returns a list). Open a raw file only when the map does not answer.
  • If built.behind is not 0, run rco map --preload and map again; read any file in built.differs directly. If built.source is worktree, the map already has those uncommitted edits.
  • To test a change, run pytest $(rco tests BASE HEAD --list) instead of the full suite.
  • After a compaction, rerun rco map --for FILE... instead of rereading the files.

The proof: tokens to finish a task

An agent that has to change a file usually greps for names, then reads whole files to see the signatures around them; most of those tokens go to finding its way, not editing. So rco is measured by the tokens an agent spends to complete a task with rco and without it (grep, ctags and reading files), counting rereads and repeated searches, and whether the answer is right.

Five tasks on rco's own tree at release/0.1.9 c58e3710f9a3, tiktoken cl100k_base. This is a modeled agent, not a live agent run: rco is charged only for the JSON fields the task uses plus any follow-up file slices; grep or git for its full stdout plus re-scans and follow-up slices. Which fields a task needs is a judgement recorded per task. Every step, the method and its limits: docs/baseline/rel019-c58e371-task-cost.md.

task tokens rco tokens grep / git right?
T1 find build_map and open it to change its signature 444 447 both; reading the function body (383) is most of each
T2 which tests to run for a commit 2,781 14 both include the failing test file; rco is a safe superset (172 test IDs in 47 files), grep names 2 files
T3 can a PR merge onto release (#193; #143) 16; 56 25; 72 both; rco reads only onto.clean and onto.conflicts
T4 contract changes of a commit 509 122 but wrong (misses two added fields); 961 to complete rco on the first read
T5 merge order of two open PRs 142 182 both

rco cost less on T3, T5 and T4 (against a complete grep answer), about the same on T1, and far more on T2. What rco prints is often much more than what the task uses (T5: 142 used of 4,448 printed): the map offers more, and the agent reads the fields it needs. rco baseline --grep cannot measure task cost today: it estimates, per commit, the outlined parts of the files that commit changed against ctags -x plus a grep of those files (tiktoken o200k_base), with no import neighbors, callers, field-selective reads, follow-up reads or multi-step tasks.

Earlier estimates, from the replay definition at rco 8730f35 (changed files plus their one-hop imports, budget 12000, tiktoken o200k_base): what an agent would read per commit with and without rco, not a run of an agent on a task. They have not been remeasured with rco baseline. Source: the 8730f35 comparison.

  • Saved 45% to 65% of tokens on our own repos since 1 Nov 2026 (win/tie/loss): md2xarticle e0eee6f 45.2% (18 commits, 13/5/0), this repo 62.5% (149, 121/20/8), the-mill f6daf98 64.8% (298, 205/88/5). rco lost on 13 commits, all after the same-folder import change, where the map followed those imports and cost more than reading the files.
  • grep and ctags saved more on the same commits. Where rco sent a map, % saved for rco / aider's map at rco's size / ctags / grep of changed names: this repo (129 commits) 63.7 / 63.7 / 67.8 / 71.0, the-mill (210) 71.1 / 71.2 / 71.5 / 73.5. ctags and grep there borrowed rco's import graph and changed-name list, so a compact outline, not rco alone, is what saves the tokens.
  • Not measured: a live agent's tokens to finish a task, and whether it does the task better. The task table above is a model of an agent.

What each command prints next to the grep, git or ctags sequence it replaces, with right-or-wrong checks and timings, is an appendix: output size per command, not task cost. Grep often prints less per command; that is not what a task costs.

30-second start

pip install "repo-context-optimizer[tokens]"   # tiktoken adds real token counts
cd your-repo
rco baseline                    # does it help on your repo? estimates your last 10 code commits
rco baseline --grep             # the same commits, estimated for grep plus ctags
rco map --for src/cli.py        # what an agent looks up before editing src/cli.py
rco init --agents               # point AGENTS.md and similar files at `rco map`

CI runs only the tests that matter, and never reruns tests that already passed on the same code. rco tests picks the tests a change can reach; with --passed it picks nothing when the tree under test already passed, and only the tests for what changed since when it did not. It keys on the git tree, so squash, rebase and merge commits, a merge queue, and the push after a merge all get it. On this repo, PR #190's merge-queue run ran 934 tests in 4m45s after its pull request had passed them; its base had moved 6 files since, and with the pull request's record rco tests --passed selects 48 test files (197 test IDs) for that run. rco init --ci-tests writes the workflow. Setting rco up for a team repo: adopting rco, then GitHub setup.

Commands

Nine commands, no setup: the map is built from git and cached in .rco/ as it is read. Every command prints JSON by default and also takes --repo PATH (default .), --format json|markdown (markdown renders the same object) and --out FILE.

flowchart LR
    rco((rco)) --> map["map<br/>--for --list --search --get<br/>--preload --clear --name"] & tree["tree<br/>--for"] & forest["forest"]
    rco --> diff["diff<br/>--staged --worktree"] & tests["tests<br/>--staged --worktree<br/>--ignore --list<br/>--passed --record"] & mc["merge-check<br/>--onto --base --head<br/>--order"]
    rco --> baseline["baseline<br/>--last --since --grep<br/>--pr --max-files"] & verify["verify<br/>--schema --openapi<br/>--help-text"] & init["init<br/>--agents --hooks --remove-hooks<br/>--metrics --ci-tests<br/>--no-config --no-ci"]
Command and flag what it does what it is for
rco map the repo map at a commit (default HEAD) as JSON: the Forest plus every Tree; fills the cache as it reads an agent's first look at a repo
--for FILE... only the modules that own those files and their neighbors, the signatures of the files they import, and each file's parts and what changed before editing: what to know about those files without reading them
--list [KIND|PATH] / --search REGEX / --get NAME nodes from the map as a JSON list, filtered by kind or path, by name pattern, or by exact name looking a name up instead of grepping
--preload [--name NAME] builds and stores the map for a commit ahead of time and moves a named pointer (default main) warming the cache in CI or after a merge
--clear [--name NAME] empties this repo's cache (Trees, prose, pointers); never touches git or sources starting the cache over
rco tree the Trees (signatures) of a commit reading a module's contract
--for PATH... only the modules that own those paths narrowing to one area
rco forest how the modules fit together at a commit seeing the shape of a repo
rco diff added, removed and changed signatures, flags, columns and routes between two commits, with callers reviewing what a change does to its contract
--staged / --worktree diffs the index or the working tree against HEAD checking edits before you commit
rco tests the tests that can see the changes between two commits, through imports and file names running only the tests a change can affect
--staged / --worktree uses the index or working tree as the head picking tests before you commit
--ignore GLOB drops changed paths no test reads (repeatable) keeping data-only changes from running everything
--list the pytest node IDs a change reaches (or whole test files), one per line feeding pytest in CI
--record / --passed RECORD --record names HEAD's tree and parents; --passed (repeatable) takes records of trees that passed: none when HEAD's tree is one, else the diff from the nearest, else BASE never rerunning tests on code that already passed
rco merge-check per BRANCH given: text conflicts onto --onto (default branch), and whether it uses what this PR (--base..--head) changed; exit 1 only on a text conflict knowing before a merge which branches break
--order for two or more branches: what each changes that another uses, and a safe merge order planning the order of several merges
rco baseline per-commit token estimate of the outlined changed parts over the last 10 code commits finding out whether rco helps on your repo
--last N / --since DATE which commits to estimate A longer window, or a roll-up since a date
--grep the same commits estimated for one fixed ctags plus grep run comparing rco with grep on your own history
--pr N the commits of pull request N measuring one pull request in CI
--max-files N skips commits that change more code files (default 50) keeping bulk changes out of the estimate
rco verify compares the map with real outputs you captured; exit 1 on a mismatch proving the map matches the running system
--schema / --openapi / --help-text CMD=FILE A SQL schema dump, an OpenAPI document, or a saved --help (repeatable) checking tables, routes or CLI flags
rco init writes rco.toml and a CI report job, keeping any file that exists one-step setup
--agents writes the agent block above into AGENTS.md and similar files pointing agents at the map
--hooks / --remove-hooks adds or removes a post-merge hook that preloads the map keeping the cache warm locally
--metrics adds a CI step that runs baseline --pr and uploads the report tracking savings per pull request
--ci-tests writes .github/workflows/rco-tests.yml: pytest on what rco tests selects, records each green tree, reads earlier records back CI that runs only the tests that matter, once per tree
--no-config / --no-ci skips rco.toml or the workflow setting up only part
flowchart LR
    G["git commit"] -->|"map reads a commit not stored yet: lazy fill"| S[("store in .rco/<br/>Trees keyed by content hash<br/>commits indexed by sha, named pointers")]
    G -->|"map --preload: fill ahead, move a pointer"| S
    C["map --clear"] -->|"empties Trees, prose, pointers; never git"| S

The cache: map fills it lazily, --preload fills it ahead, --clear empties it, and entries are keyed by content, so a rerun writes nothing new. Exit codes, JSON fields and examples are in docs/commands.md.

Languages, repo types and upcoming work

Status Languages and repo types Token savings (the support matrix gives each sha and source)
✅ shipped in 0.1.9 Python, SQL, JavaScript and TypeScript, Go, shell, PowerShell Python 57.3% to 86.3%; TS/JS 77.4%; Go 83.4%; shell 0%; SQL and PowerShell not measured
✅ shipped in 0.1.9, new Java, C#, Kotlin, PHP, Ruby, CSS, Swift Java 82.6%; C# 78.5% and 60.6%; PHP 62.4%; Ruby 38.7%; CSS-only 40.1%; Swift 56.6% (each at the sha in the matrix)
🟡 partial Rust: 37 of 105 files resolved an import on the 0.1.8 run ripgrep 10.8% at 8730f35
🗓️ upcoming, 0.2.0 Languages: C and C++, COBOL not measured
🗓️ upcoming, no date A concept classifier for prose (map --search matches only node and module names today, so a prose phrase finds nothing); richer map nodes (signatures, imports, callers) and other optimizations in progress not measured
⚪ fallback Any other language: the file shows by path not measured
✅ repo types Single package, monorepo, polyglot, submodules (skipped with a note), LFS (opaque), empty repo not measured by type

How rco is built

flowchart TB
    A["9 commands<br/>commands/: one Spec each"] --> B["Map layer<br/>core/: build, forest, diff, refs"]
    B --> S["Cache<br/>store/: SQLite, filled on read"]
    B --> C["File graph<br/>imports, edges"]
    C --> D["Language registry"]
    D --> E["lang/&lt;language&gt;/ on a shared engine"]
    E --> F["Shared base<br/>gitread, canon, model, output"]

Deterministic, one design for every language, checked in CI and with SPIN, and measured with losses counted: docs/architecture.md has why, the layers and the module behind each command. Design, roadmap and process: docs/design/.

Documentation and license

Commands, support matrix, architecture, adopting rco, GitHub setup, cloud agents, changelog. MIT; see LICENSE.

Metadata

Release files for repo-context-optimizer 0.1.9

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for repo-context-optimizer 0.1.9
File Size Uploaded Provenance Actions
repo_context_optimizer-0.1.9.tar.gz 445.0 kB With provenance Details for repo_context_optimizer-0.1.9.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for repo-context-optimizer 0.1.9
File Interpreter ABI Platform Actions
repo_context_optimizer-0.1.9-py3-none-any.whl Python 3 none any Details for repo_context_optimizer-0.1.9-py3-none-any.whl

Total release size: 729.5 kB

Release files / repo_context_optimizer-0.1.9.tar.gz

Download URL repo_context_optimizer-0.1.9.tar.gz
Size 445.0 kB
Tags Source
SHA-256 checksum
How to use checksums
aac8ae296d40ae16d520ba22964ad16c149852ee65c75c199b177786bd739343
BLAKE2b-256 checksum
How to use checksums
ab73bfc0f80ef9971980f33a30b69f9b0b2d99b5b99e928defef82d0d5ccf878
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 30, 2026.

Transparency log

Release files / repo_context_optimizer-0.1.9-py3-none-any.whl

Download URL repo_context_optimizer-0.1.9-py3-none-any.whl
Size 284.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c56dc19f4e86f87baecda69f8453949985864fccfb8ea6ceb06a3bec27f4c1de
BLAKE2b-256 checksum
How to use checksums
573a9ebd0a76cd9362dc7bb501e7992a5a5ed6a8b3e397219bde71b02cde1a4b
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 30, 2026.

Transparency log

Security for repo-context-optimizer 0.1.9

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.

Select from 2 files

Attestation for repo_context_optimizer-0.1.9.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 30, 2026.

Transparency log

A 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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page