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

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.0
File Size Uploaded Provenance Actions
ctxrank-0.1.0.tar.gz 67.3 kB With provenance Details for ctxrank-0.1.0.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for ctxrank 0.1.0
File Actions
ctxrank-0.1.0-cp39-abi3-win_amd64.whl CPython 3.9 abi3 Windows x86-64 Details for ctxrank-0.1.0-cp39-abi3-win_amd64.whl
ctxrank-0.1.0-cp39-abi3-musllinux_1_2_x86_64.whl CPython 3.9 abi3 Linux musl 1.2+ x86-64 Details for ctxrank-0.1.0-cp39-abi3-musllinux_1_2_x86_64.whl
ctxrank-0.1.0-cp39-abi3-manylinux_2_28_aarch64.whl CPython 3.9 abi3 Linux glibc 2.28+ ARM64 Details for ctxrank-0.1.0-cp39-abi3-manylinux_2_28_aarch64.whl
ctxrank-0.1.0-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.0-cp39-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
ctxrank-0.1.0-cp39-abi3-macosx_11_0_arm64.whl CPython 3.9 abi3 macOS 11.0+ ARM64 Details for ctxrank-0.1.0-cp39-abi3-macosx_11_0_arm64.whl
ctxrank-0.1.0-cp39-abi3-macosx_10_12_x86_64.whl CPython 3.9 abi3 macOS 10.12+ x86-64 Details for ctxrank-0.1.0-cp39-abi3-macosx_10_12_x86_64.whl

Total release size: 32.3 MB

Release files / ctxrank-0.1.0.tar.gz

Download URL ctxrank-0.1.0.tar.gz
Size 67.3 kB
Tags Source
SHA-256 checksum
How to use checksums
b1aa80a7cb99b1eae0427f04cf3071ae45968971d7514eeddbcba41c9e625099
BLAKE2b-256 checksum
How to use checksums
bc5d5c99c22bf30f5a91cffe096a58786e6db9f06143e44ba84b23a0dc396009
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.0-cp39-abi3-win_amd64.whl

Download URL ctxrank-0.1.0-cp39-abi3-win_amd64.whl
Size 5.2 MB
Tags CPython 3.9 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
f84b5ef5d338e3cced2653745ca2fe1f7e73fe381b41de0a2cbc5c7934c4633f
BLAKE2b-256 checksum
How to use checksums
999b530b90b78589edae7613e28c4f235995c60d8d24523b8406295a527ec6a8
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.0-cp39-abi3-musllinux_1_2_x86_64.whl

Download URL ctxrank-0.1.0-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
4277ca3abb88b5ff3eabd42f1b47f47ebce85baa2a8e83df7df15c57c2d950b8
BLAKE2b-256 checksum
How to use checksums
b412a33b3cbee937ff7cf51942c427369d53d06df978024942efec32f303915f
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.0-cp39-abi3-manylinux_2_28_aarch64.whl

Download URL ctxrank-0.1.0-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
58a1f4e571972ef5eac7595f930d5399c1656a738a6e60eae4b6405a483a99e7
BLAKE2b-256 checksum
How to use checksums
cf8f26960bf17d79a1e75fec9fe358daab816eab5feebd0ec3dfecd9620e3366
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.0-cp39-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl

Download URL ctxrank-0.1.0-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
e2ff89db3863ae50a023ecb24590cf8ef8327634704f95200b7ca684e0c6b40a
BLAKE2b-256 checksum
How to use checksums
7b8c6743298002f5cc2c422068dd866b9cd17a9f30ed8735ad6d9fe55addc147
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.0-cp39-abi3-macosx_11_0_arm64.whl

Download URL ctxrank-0.1.0-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
162cbc2fc6dfc8a1a5d8c2375da956b53e5976e5cbde526aa21bdd6e0a6cc7e3
BLAKE2b-256 checksum
How to use checksums
d7a6fbe4ab31091dcc569951170b72f7e919c1e8ddc66e81a2588f591c831c57
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.0-cp39-abi3-macosx_10_12_x86_64.whl

Download URL ctxrank-0.1.0-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
25bedf96dcdd883c5e8554fc922e656bdfb83265581c36d40bafadb5d6e87957
BLAKE2b-256 checksum
How to use checksums
4cdc288e45a2c56954832baa3249c5b493ee361382d56c6971324a9129aed159
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.0

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