codeindex
Self-contained, deterministic repo-indexing engine: file walking, language
detection, symbol/import extraction (tree-sitter AST with a regex fallback),
import resolution, a typed cross-file link-graph, and graph analytics — shipped
as a single zero-dependency engine.mjs that consumer tools vendor (copy
into their repo) instead of installing.
Designed for downstream tools — agent skills, CLIs, CI gates — that vendor the
engine as a single file instead of taking an npm dependency. How it stacks up
against universal-ctags, Serena and Graphify: How it
compares.
What it does
- Walk a repo deterministically: ignore lists,
.gitignore and
.git/info/exclude, binary/lockfile skips, a size cap, symlink-cycle guard.
A symlink that stays inside the repo, file or directory, is an alias: its
target is indexed once, under its own path. build, out, target and
tmp are skipped as build output unless git tracks files in them — they
are ordinary package names too (a Go build package, com.acme.build).
Nested repositories (a subdirectory with its own .git — linked worktrees,
vendored clones, submodules) are skipped like git does, and .git itself —
like the engine's own .codeindex — is never walked even when
--ignore-dir replaces the default ignore list. No
file-count cap unless you ask for one (--max-files), and asking sets the
capped flag — never a silent truncation.
- Scan every file into a
FileRecord: classification, language, symbols,
imports, headings, hashes — with an incremental cache fastpath. Extraction
runs across worker threads by default (--workers, CODEINDEX_WORKERS);
artifacts are byte-identical either way, and anything that would make a
worker's result differ falls back to the single-threaded path. JS/TS and
Python imports are read from code only: comments, docstrings and
string/template-literal text are masked first, so example code quoted in a
JSDoc block, a docstring or a code generator's template never becomes an
edge (JSDoc import("./x") types and @import tags, which are real type
dependencies, are kept). The same scan runs with or without a grammar, so
extractAst and the index report the same imports. Python
from pkg import name also links pkg/name.py when name is a submodule
(and nothing when it is a function or class); PHP group (use A\{B, C}) and
comma use lists and __DIR__-anchored includes are followed, and a trait
use inside a class is not an import. Build output committed under an
ordinary name is recognised by its content: minified JavaScript (not only a
.min.js name) and bundles (esbuild's // src/x.ts module banners, webpack's
and ncc's module loader). It stays in the index with its summary and
imports, flagged generated: "minified" or "bundle" on its FileRecord
and graph node, but its symbols and call sites are not extracted: one-letter
noise for the first, copies of the sources' definitions for the second.
- Extract symbols via tree-sitter (15 committed grammars, plus 6 more via
grammars pull) or per-language regex rules (16 languages, always available).
Each symbol carries its complete signature (parameters and return type,
not the first physical line; one line, with no comment and no body — not an
arrow's expression body, a Go interface's method list or a macro's
expansion), its own doc comment, its qualified parent,
and its line span — including the members a declaration-only walk misses:
interface members, class fields, enum members, every declare/.d.ts
declaration, Rust trait method signatures, Go interface method sets and type
aliases, record components, constructor val parameters and their
TypeScript (private readonly dep: Dep) and PHP 8 (promoted) twins, every
name of a multi-name declaration (var a, b int, int x, y;,
a, b = 1, 2), C #define macros and the members of a typedef struct,
Python declarations under if TYPE_CHECKING: / try: / with blocks, Ruby
class << self methods, private def x definitions and the block of
Point = Struct.new(…) do, Elixir clauses with a when guard and
defguard, and the members of a class bound by module.exports = or an
anonymous export default class (a default export with no name of its own
is named after the file stem). A doc comment is found across Rust
attributes and TypeScript decorators. Visibility is read from a
declaration's modifiers, never from its parameter names or default values;
an export { … } list marks only the bindings of its own scope; and a
Python module's __all__ (when written as literals) decides which of its
top-level names are public, the names it imports and lists becoming
reexport symbols. An out-of-line C++ definition (void Widget::draw())
belongs to its class, and a Lua function M.go() to its table; a .h
header is parsed as C++ when its content is (a namespace, class or
template), as C otherwise. Vue, Svelte and Astro
single-file components are extracted from their <script> blocks (and
Astro's frontmatter) as the JS/TS their lang names, at their real lines:
symbols, imports, and calls from both the script and the template, bound in
the JS/TS call family. A Svelte prop (export let) and an Astro frontmatter
export are not module exports, so they are never reported as dead code.
The regex tier (the only one for Swift and Dart, and for the extended
languages until a pull) reads code only: comments and strings are masked,
so an example in a doc comment or a code generator's template is not a
declaration. It takes each declaration's doc comment from the lines above
it and, in brace languages, its line span, but only where the body's
braces close as a formatter puts them; otherwise the span is left out
rather than guessed. Its signature is the declaration's first line, and it
reports no parent.
Each file's summary is the first leading comment that describes
something: license and copyright text (MIT, BSD, Apache, GPL, MPL, the Go
"governed by" line), linter and editor magic comments (frozen_string_literal,
-*- coding -*-, go:build), Xcode's file stamp and bundler region markers
are skipped, and # reads as a comment only in languages where it is one —
never a C #include or a Rust #[attribute].
Docs get a title, section headings, a summary and doc-link refs: markdown
(ATX and setext headings, inline and reference links) and reStructuredText
(Sphinx section titles; toctree entries, :doc: roles and
include/literalinclude targets as links). Other prose (.txt, .adoc)
is indexed under its file name.
- Resolve imports across languages: tsconfig
paths (tsc's precedence:
exact alias, then longest prefix) and baseUrl, extends chains into
workspace packages and ${configDir}, package exports and imports
(#subpath), bundler ?query suffixes, Python import roots found the way
mypy finds them (the dir holding each top-level package, so src layouts
resolve and a package's own typing.py does not shadow the stdlib), go.mod
(a package's representative file is never a _test.go when it has other
files), Cargo ([lib] names, renamed dependencies, #[path] modules, and
use paths read the way the crate's edition reads them), PSR-4, C#
namespaces, and one JVM index for Java, Kotlin and Scala, so a Kotlin file
importing a Java class (or the reverse, through the <File>Kt facade)
links; Scala selector groups and package-relative imports resolve too. Dart
(relative and package: URIs of an in-repo pubspec.yaml), Lua require
(a/b.lua, a/b/init.lua), shell source/. of a literal path, and
Elixir alias/import/use of a module the repo defines resolve as well.
A markdown link starting with / is repo-root-relative, as GitHub renders
it.
- Build a typed link-graph:
import / call / extends / implements /
use / doc-link / mention edges at file and module level, plus Louvain
communities, PageRank/betweenness centrality, a tests→code map (a test
covers what it imports, uses or calls, the file it is named after, and in Go
its whole package), and surprise-edge detection. Inheritance also yields a type hierarchy (what a
type extends and implements, and what extends and implements IT) and a
symbol-level graph for bounded "what does this reach" neighborhoods.
Go states no implementations, so the hierarchy adds them: a
var _ I = (*T)(nil) assertion, or a type whose methods (its own, plus the
ones embedding promotes) match the interface's by name and parameter count.
The second kind is marked structural: true. These are answers to
hierarchy and implementations only, never graph.json edges.
- Render byte-stable
graph.json / symbols.json (two builds of an
unchanged repo are byte-identical), plus a SCIP code-intelligence index
(index.scip: nested symbols, package identity, implementation
relationships) via a hand-rolled zero-dependency protobuf encoder — validated
by the official scip CLI (stats/lint).
Measured against other indexers
"Finds better" is a claim, so the checks that count are the ones this project did
not author. Four oracles score extraction against outside authorities — a real
compiler, a mature indexer, and the grammars' own published queries and
vocabulary:
| oracle |
what makes it independent |
result |
TypeScript compiler index (scip-typescript 0.4.0) |
an index built by the real TypeScript compiler — authoritative where every other check here is syntactic |
100% of its 93 named declarations, against ctags' 94.6% on the same files |
| universal-ctags differential (Universal Ctags 6.2.1) |
an independent, mature indexer covering ~40 languages |
reports 2,014 declarations ctags does not over 6 real repositories, and reproduces 61.7%–98.8% of ctags' names — what is left bucketed by kind, per repo below |
Official tags.scm queries |
the code-navigation patterns each grammar's own authors publish, and GitHub uses |
1 adjudicated difference, over the 14 of 17 languages that publish one |
| Grammar vocabulary |
each tree-sitter grammar's own declared node types, read at runtime from the parser |
21 grammars audited, 209 declaration-ish node types still unhandled |
The one head-to-head
Exactly one figure on this page is a score: the one where both tools are
measured against the same third-party authority, rather than against each other.
On the 53 files of create-t3-turbo that an index built by the real TypeScript
compiler covers:
| against the compiler's 93 named declarations |
found |
| codeindex |
100% |
| universal-ctags |
94.6% |
All 5 ctags missed are one construct (string-literal declaration names — module
augmentations, quoted interface keys). That head-to-head is also the calibration
for everything below: it is how far a syntactic oracle can be trusted on the ~40
languages no compiler here can check.
Every other percentage in this section is an overlap ratio between two tools
that disagree about what counts as a declaration, which is a different thing and
is not scored as one.
Per repository, against universal-ctags
Declaration names compared per file over real code, not fixtures. The
percentage here is not a score, which is why it is not in the last column. It
is |ours ∩ ctags| / |ctags| — the share of ctags' names this index also reports
— so by construction it can only ever show where we lose: nothing in it measures
what ctags omits. The two count columns are the directions that actually compare
the tools; read those.
| repo |
files |
both report |
of ctags reproduced |
ctags only |
codeindex only |
| BurntSushi/ripgrep |
107 |
3,189 |
98.8% |
40 |
47 |
| gin-gonic/gin |
100 |
2,010 |
98.6% |
29 |
15 |
| pallets/flask |
86 |
1,516 |
93.9% |
98 |
6 |
| t3-oss/create-t3-turbo |
54 |
97 |
76.4% |
30 |
15 |
| nrwl/nx-examples |
87 |
87 |
69.6% |
38 |
27 |
| socialgouv/code-du-travail-numerique |
1,429 |
3,659 |
61.7% |
2,271 |
1,904 |
So no, the low rows are not "ctags finds more" — and that is measured, not
asserted. The differential records what the ctags only column is, bucketed
by the kind ctags itself assigned (ctagsOnlyByKind in the same record). On
code-du-travail, its 2,271 names are:
| ctags kind |
count |
what they are |
constant |
2,020 |
all but a handful sit inside a function body, an object literal or a test block — read off the source, not assumed |
variable |
116 |
same story |
property |
107 |
object-literal keys (Conditions: ConditionsIcon) |
alias |
13 |
import aliases — import type Engine from "publicodes" |
method / class / function / enumerator |
15 |
object-literal methods and test-scope declarations |