Skip to main content

ctxrank

A ranked, token-budgeted map of any codebase, built for AI coding agents.

ctxrank finding dictresize in CPython, listing its callers, then printing a 120-token map for the query dict resize

Time to print a 2048-token map of the Linux kernel, rust-lang/rust and CPython, ctxrank against aider's repo map

On CPython, ctxrank prints a 2,048-token map of the repo in 1.2 seconds from a cold start and in 0.16 seconds once its cache exists. aider's own repo map took 88 seconds on the same checkout. Dumping all of CPython's source as text would cost 20.6 million tokens.

ctxrank reads every source file with tree-sitter, records where each function, type and macro is defined and where it is used, ranks the definitions with personalised PageRank over that reference graph, and prints the top signatures that fit in the token budget you give it. An agent gets the shape of a repo for a couple of thousand tokens instead of reading files one by one.

The ranking idea comes from aider's repo map. I wanted it outside aider, as one binary any agent can call, fast enough for repos the size of the kernel.

$ ctxrank sym dictresize
Objects/dictobject.c:2206  function  static int dictresize(PyDictObject *mp, uint8_t log2_newsize, int unicode)
Objects/dictobject.c:432  function  static int dictresize(PyDictObject *mp, uint8_t log_newsize, int unicode);

$ ctxrank callers dictresize
Objects/dictobject.c:1899  in insertion_resize
Objects/dictobject.c:3500  in dict_dict_fromkeys
Objects/dictobject.c:3524  in dict_set_fromkeys
...

$ ctxrank map --tokens 120 --query "dict resize"
Lib/multiprocessing/dummy/__init__.py:
⋮
│dict = dict
⋮
Objects/dictobject.c:
⋮
│static int dictresize(PyDictObject *mp, uint8_t log_newsize, int unicode);
⋮
│static int
│dictresize(PyDictObject *mp,
│           uint8_t log2_newsize, int unicode)
⋮

Install

uvx ctxrank            # run without installing (Python wheel with the binary inside)
pip install ctxrank    # or install it
cargo install ctxrank  # or build from source

Prebuilt binaries for Windows, macOS and Linux (x86_64 and arm64) are on the releases page.

Use it from the command line

Command What it does
ctxrank / ctxrank map --tokens 2048 Ranked map of the whole repo
ctxrank map --focus src/a.rs src/b.rs Rank what those files depend on; leave the files themselves out
ctxrank map --query "retry logic for uploads" Boost identifiers and paths that match the words
ctxrank sym parse_args Where a symbol is defined (--fuzzy for substrings)
ctxrank callers parse_args Every reference, with the function it sits in
ctxrank callees parse_args What a function calls, and where those are defined
ctxrank related src/a.rs --query "auth" Files ranked by relevance to files and/or words
ctxrank stats --dump-tokens Files, symbols, languages, and what a whole-repo dump would cost

Every command takes --json. -C DIR picks the repo, -v prints timings.

Use it from an agent (MCP)

ctxrank mcp is a stdio MCP server with five tools: repo_map, find_symbol, callers, callees and related_files. The index stays in memory and only changed files are reparsed between calls.

Claude Code

claude mcp add ctxrank -- uvx ctxrank mcp

Cursor (.cursor/mcp.json in the project, or ~/.cursor/mcp.json)

{
  "mcpServers": {
    "ctxrank": { "command": "uvx", "args": ["ctxrank", "mcp"] }
  }
}

Codex CLI (~/.codex/config.toml)

[mcp_servers.ctxrank]
command = "uvx"
args = ["ctxrank", "mcp"]

If you installed the binary directly, use "command": "ctxrank", "args": ["mcp"] instead.

Use it from Python

import ctxrank

print(ctxrank.repo_map(".", tokens=1024, query="token refresh"))
ctxrank.find_symbol("RepoMap", root=".")  # list of dicts

How it works

  1. Walk. The ignore crate (the walker ripgrep uses) lists files, honouring .gitignore, .ignore and .ctxrankignore. Files over 1 MB are skipped as generated.
  2. Tag. Each file is parsed with its tree-sitter grammar and the grammar's own tags.scm query, the same one GitHub's code navigation uses, in parallel with rayon. For C and C++ I add calls, type uses and macro references, because the upstream C query only has definitions.
  3. Cache. Tags go into one binary cache file per repo in your OS cache directory. On the next run only files whose size or mtime changed are parsed again.
  4. Rank. Files are nodes. A reference in file A to a name defined in file B is an edge A to B, weighted the way aider weights it (long snake/camel names count more, private _names and names defined in many places count less, sqrt of the reference count). PageRank runs with a personalisation vector built from --focus, --mention and --query, and each file's rank is shared out over the definitions its edges point at.
  5. Fit. A binary search picks how many top definitions fit the token budget, then each file is printed with its signatures and the enclosing class or impl lines, with ⋮ for skipped code.

Languages: Rust, Python, JavaScript, TypeScript and TSX, Go, C, C++, Java, C#, Ruby, PHP, Swift, Kotlin, Scala, Lua, Elixir, OCaml, Haskell, Zig and Bash.

Benchmarks

All numbers are from one laptop: AMD Ryzen 9 8940HX (16 cores), 32 GB RAM, NVMe SSD, Windows 11, measured with hyperfine 2.0 (3 cold runs, 10 warm runs). Each run prints a 2,048-token map. "Cold" means no cache, so every file is parsed. "One file changed" touches one source file before each run, so ctxrank reparses that file and reloads the rest from the cache.

Repo (commit) Files indexed ctxrank cold ctxrank, one file changed ctxrank warm aider repo map, cold
CPython (eeafc73) 3,541 1.19 s 0.19 s 0.16 s 88.4 s
rust-lang/rust (ae36fe22c) 39,986 1.82 s 0.36 s 0.32 s crashed after 23 s
Linux (6628e7d4c) 67,204 12.4 s 3.94 s 3.21 s not done after 30 min

aider is version 0.86.2, installed from PyPI with uv pip install aider-chat, and timed with bench/aider_map.py, which calls its RepoMap.get_repo_map the way aider does. On rust-lang/rust it stopped with tree_sitter.QueryError: Invalid node type ... module from one of its bundled tag queries. On Linux I stopped it at the 30 minute cap, with 81,030 of 97,348 files scanned. So the only head-to-head time I have is CPython, where ctxrank is 74 times faster cold. aider also caches its tags, so its warm runs are quicker than its cold one; I did not time those.

Tokens for a whole-repo text dump against an 8k ctxrank map

Token counts use o200k_base (the GPT-4o tokenizer) through --features exact-tokens. The "whole repo" figure counts every indexed file with a path header and code fences, the way repo dump tools print it.

Repo Whole repo as text 2k map 8k map
CPython 20,563,405 1,826 7,447
rust-lang/rust 35,323,765 1,966 8,289
Linux 331,800,357 2,041 7,921

The 8k map of rust-lang/rust comes out at 8,289 tokens, about 1% over its 8,192 budget, because the default build estimates tokens from byte counts. Build with --features exact-tokens if you need the budget to be exact.

Reproduce with bench/run.sh (needs hyperfine). Raw hyperfine JSON is in bench/results/.

Limits

  • Names are matched as text, with no type information. Two unrelated functions called init are the same identifier. As in aider, names defined in more than 5 files count for less. I also ignore names defined in more than 200 files.
  • tree-sitter parses C without running the preprocessor, so code hidden behind macros can be missed or misread, and kernel-style headers full of #defines rank high.
  • On the Linux kernel a warm run still takes 3.2 seconds. Most of it is loading an 835 MB cache (4 million definitions with their signature text) and rebuilding the symbol table. Smaller repos stay well under half a second. Making the cache smaller is the next thing I want to fix.
  • --query matches words against identifiers and paths (with snake_case and camelCase split and crude stemming). There are no embeddings, so a query has to share words with the code.
  • I have only benchmarked on Windows so far, so I have no timings from Linux or macOS.
  • Map quality is judged by eye. I have not run an evaluation of whether agents finish tasks faster with it.

Credits

The repo-map idea, its weighting heuristics and the output format are from aider by Paul Gauthier (Apache-2.0). ctxrank is a separate implementation in Rust and contains no aider code. Tags queries come from the tree-sitter grammar projects (MIT). See NOTICE.

Licence

Apache-2.0.

Metadata

Release files for ctxrank 0.1.1

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

Source distribution (sdist)

Source distribution for ctxrank 0.1.1
File Size Uploaded Provenance Actions
ctxrank-0.1.1.tar.gz 67.3 kB With provenance Details for ctxrank-0.1.1.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for ctxrank 0.1.1
File Actions
ctxrank-0.1.1-cp39-abi3-win_amd64.whl CPython 3.9 abi3 Windows x86-64 Details for ctxrank-0.1.1-cp39-abi3-win_amd64.whl
ctxrank-0.1.1-cp39-abi3-musllinux_1_2_x86_64.whl CPython 3.9 abi3 Linux musl 1.2+ x86-64 Details for ctxrank-0.1.1-cp39-abi3-musllinux_1_2_x86_64.whl
ctxrank-0.1.1-cp39-abi3-manylinux_2_28_aarch64.whl CPython 3.9 abi3 Linux glibc 2.28+ ARM64 Details for ctxrank-0.1.1-cp39-abi3-manylinux_2_28_aarch64.whl
ctxrank-0.1.1-cp39-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl CPython 3.9 abi3 Linux glibc 2.17+ x86-64 Details for ctxrank-0.1.1-cp39-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
ctxrank-0.1.1-cp39-abi3-macosx_11_0_arm64.whl CPython 3.9 abi3 macOS 11.0+ ARM64 Details for ctxrank-0.1.1-cp39-abi3-macosx_11_0_arm64.whl
ctxrank-0.1.1-cp39-abi3-macosx_10_12_x86_64.whl CPython 3.9 abi3 macOS 10.12+ x86-64 Details for ctxrank-0.1.1-cp39-abi3-macosx_10_12_x86_64.whl

Total release size: 32.3 MB

Release files / ctxrank-0.1.1.tar.gz

Download URL ctxrank-0.1.1.tar.gz
Size 67.3 kB
Tags Source
SHA-256 checksum
How to use checksums
e9e0735b0310d981c8937893ab7dde8adf29cda1b313f98defd38dba38708892
BLAKE2b-256 checksum
How to use checksums
35b1355bf1336f0ab9d44e7efef22e8039533577e7e21370ccc401f085411eda
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 3, 2026.

Transparency log

Release files / ctxrank-0.1.1-cp39-abi3-win_amd64.whl

Download URL ctxrank-0.1.1-cp39-abi3-win_amd64.whl
Size 5.2 MB
Tags CPython 3.9 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
a06d8dde495d9aa29be59180731e0de179a1dbf6ec459140995788dd03ad2a4e
BLAKE2b-256 checksum
How to use checksums
2860b073da3e1112847f8298c0a20d7bc6f396a570dd21ed1b1e48c4d8bde156
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 3, 2026.

Transparency log

Release files / ctxrank-0.1.1-cp39-abi3-musllinux_1_2_x86_64.whl

Download URL ctxrank-0.1.1-cp39-abi3-musllinux_1_2_x86_64.whl
Size 5.6 MB
Tags CPython 3.9 Linux musl 1.2+ x86-64 abi3
SHA-256 checksum
How to use checksums
bc50a1fcbfa7ae320a139abca853c3eab5ec97e66f410d3c3a3706d68e11b7a5
BLAKE2b-256 checksum
How to use checksums
f1ace27ab7c9f9b1bcff4dec62beb806b19ffbdae79be7a02d4deb61436d7ac7
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 3, 2026.

Transparency log

Release files / ctxrank-0.1.1-cp39-abi3-manylinux_2_28_aarch64.whl

Download URL ctxrank-0.1.1-cp39-abi3-manylinux_2_28_aarch64.whl
Size 5.3 MB
Tags CPython 3.9 Linux glibc 2.28+ ARM64 abi3
SHA-256 checksum
How to use checksums
e551d4efff6ef86aad73d1d480a1081a9e28fa4ddd9ccaa5dcdfdcae41e7f82a
BLAKE2b-256 checksum
How to use checksums
ab020a2da4d513094156738ccfe4dbb49df7fb7d4228a1e0ade6864810fa1121
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 3, 2026.

Transparency log

Release files / ctxrank-0.1.1-cp39-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl

Download URL ctxrank-0.1.1-cp39-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Size 5.4 MB
Tags CPython 3.9 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
f3e77550c0cd5b143b849b807ce76303c89d8269758893115afc35ea27261b93
BLAKE2b-256 checksum
How to use checksums
9aced2f6fc6b715db71d44a1effefde208e77ebf446218f45ab91785692ade46
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 3, 2026.

Transparency log

Release files / ctxrank-0.1.1-cp39-abi3-macosx_11_0_arm64.whl

Download URL ctxrank-0.1.1-cp39-abi3-macosx_11_0_arm64.whl
Size 5.4 MB
Tags CPython 3.9 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
d1da9707e5be9a486025995a0546cf48a30d4594c7fec0b3a18bf78cc335f050
BLAKE2b-256 checksum
How to use checksums
b256a666f73a722d9e0b814ec64df5e51c2a303b610c2d097a98d777943fcb46
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 3, 2026.

Transparency log

Release files / ctxrank-0.1.1-cp39-abi3-macosx_10_12_x86_64.whl

Download URL ctxrank-0.1.1-cp39-abi3-macosx_10_12_x86_64.whl
Size 5.3 MB
Tags CPython 3.9 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
ffce176b87240d488285a4049eabc0d9f7dbf6060b8f117e666a11278d3bb98c
BLAKE2b-256 checksum
How to use checksums
02aa04cad14f878d220355cdea197d866d1411445d592506d87f59f6aaaf1a1c
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 3, 2026.

Transparency log

Security for ctxrank 0.1.1

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

All 7 files in this release have been uploaded with provenance metadata.

Select from 7 files

Attestation for ctxrank-0.1.1.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 3, 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.

Release history Release notifications | RSS feed

This release

0.1.1 This release

7 release files Full provenance

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