Programmatic API
Everything codescope does is importable. The package ships ESM with type declarations.
npm install @abdulmunimjemal/codescopeIndex and query a repo
Section titled “Index and query a repo”import { GraphStore, Indexer } from "@abdulmunimjemal/codescope";
const store = new GraphStore("graph.db"); // or ":memory:"const indexer = new Indexer(store, "/path/to/repo");await indexer.indexAll();
store.searchSymbols("config"); // fuzzy symbol searchstore.getSymbol("GraphStore"); // exact definition lookupstore.findCallers("parseSource"); // who calls it (by file)store.findCallees("indexAll"); // what it callsstore.impact("replaceFile", { depth: 3 }); // transitive callersstore.neighborhood("handleRequest", { depth: 2 });store.context("auth flow", { maxSymbols: 30 });store.stats();store.close();Keep it fresh
Section titled “Keep it fresh”import { watch } from "@abdulmunimjemal/codescope";
const handle = watch(indexer, { onChange: (file, action) => console.log(action, file), // "indexed" | "removed"});// …laterawait handle.close();Affected tests
Section titled “Affected tests”import { affected } from "@abdulmunimjemal/codescope";
const { tests } = affected(store, ["src/store.ts", "src/parser.ts"]);// tests: string[] — the test files a change likely affectsParse a single source string
Section titled “Parse a single source string”import { parseSource, languageForPath } from "@abdulmunimjemal/codescope";
const lang = languageForPath("example.ts"); // → LanguageConfig | undefinedconst { symbols, refs } = await parseSource("typescript", "export function f(){}");Run the MCP server in-process
Section titled “Run the MCP server in-process”import { createServer, runStdioServer, GraphStore } from "@abdulmunimjemal/codescope";
const store = new GraphStore(":memory:");// …index…await runStdioServer(store); // connect over stdio, or:const server = createServer(store); // an McpServer you can wire to any transportProgrammatic install
Section titled “Programmatic install”import { install } from "@abdulmunimjemal/codescope";
install("/path/to/repo", { agents: ["claude", "cursor"] });Exports
Section titled “Exports”GraphStore, Indexer, watch, parseSource, languageForPath, LANGUAGES,
SUPPORTED_EXTENSIONS, createServer, runStdioServer, affected,
isTestFile, install, serverEntry, format (the compact renderers),
VERSION, and the full set of types (SymbolRow, RefRow, Neighborhood,
ContextBundle, IndexStats, …).