Ctx Search
Navigate docs/code with a strict breadth-first flow and seeded context.
Tools
Use npx @anduril-code/ctx CLI commands.
| Command | Input | Purpose |
|---|---|---|
tree [PATH] [--glob PATTERN] [--depth N] |
Repo | Directory tree with per-file token counts |
rank <QUERY> [--glob PATTERN] [--maxResults N] |
Code + docs | Rank files by query relevance |
gather <QUERY> --maxTokens N [--seeds F,...] [--depth N] |
Code + docs | Auto-discover and assemble context |
context <FILES...> --maxTokens N [--strategy S] |
Code + docs | Assemble context from known files |
read <FILE> [--maxTokens N] [--strategy S] [--lineHashes] |
Code + docs | Token-budgeted file read (with optional per-line hashes) |
outline <FILE> [--depth N] |
Source code | Structural outline with line numbers and content hashes |
imports <FILE> [--direction incoming|outgoing] |
Source code | Dependency graph |
symbols <QUERY> [--glob PATTERN] [--kind K] |
Source code | Cross-file symbol search |
focus <FILE>::<SYMBOL> [--maxTokens N] [--include SECTIONS] |
Source code | One-call symbol context (body, callers, deps, types, tests, conventions) |
tokens [FILE] |
Any | Count tokens, bytes, and lines |
sections <FILE> |
Markdown | List headings with token costs |
extract [--only <heading>] [--strip <heading>] <FILE> |
Markdown | Extract exact section content |
locate <QUERY> [FILES...] |
Markdown | Find headings matching a query across files |
exec '<CODE>' |
Any | Execute a JS code block with all ctx functions pre-loaded |
All commands are invoked as npx @anduril-code/ctx <command>.
Strategy (high-signal defaults)
- Default to
execfor multi-file research. When you need to read 3+ files, or when results from one call feed into the next, use a singleexeccall instead of separate commands. Oneexecreplaces many sequential reads/outlines/symbols calls and cuts round-trips dramatically. - Build a narrow first-pass context:
gather "<query>" --maxTokens 1200 --seeds <seed files>- If blocked, rerun with
--maxTokens 2200
- For file targeting, run
rankbefore opening content. - For code files, prefer
outlinethenread. - For symbol-level understanding before edits, prefer
focus. - For Markdown, run
sectionsfirst, thenextract --onlyexact headings. - Use
importsto trace dependency flow when understanding module relationships. - Use
symbolsto find definitions and call sites for specific functions/types. - Treat
readoutput as triage only; anchor any final claim with line-aware evidence (outlineorrg -n+sed -n).
When given a file path
- If Markdown:
sections→extract --only/read - If source code:
outline→read - If symbol-specific:
focus <file>::<symbol> - To understand context:
importsfor dependency graph,symbolsfor usage sites
When given a question or topic
gather "<question>" --maxTokens 1200for auto-discovery- Or manual:
tree→rank→readtop-ranked files - For docs: add
locateto search across markdown headings - For code: add
outlineandsymbolsfor structural context
Prefer exec for multi-file and chained exploration
Always reach for exec first when your task involves reading multiple files, cross-referencing results, or chaining ctx calls. A single exec call that reads 7 files and cross-references their contents is far better than 7 separate read calls. Only fall back to individual commands when you need just one or two simple lookups.
npx @anduril-code/ctx exec '
const t = await tree({ depth: 2 });
const files = [];
function collect(entries) {
for (const e of entries) {
if (!e.isDirectory) files.push(e.path);
if (e.children) collect(e.children);
}
}
collect(t.entries);
const ranked = await rank({ query: "authentication", files });
const top3 = ranked.results.slice(0, 3);
const contents = await Promise.all(top3.map(f => read({ file: f.file, maxTokens: 2000 })));
const syms = await symbols({ query: "validateToken" });
json({ top3, contents: contents.map(c => c.content.slice(0, 200)), syms });
'
Available functions in exec (all async — use await):
- Read-only:
tree,read,context,gather,rank,focus,symbols,imports,outline,tokenCount - Utilities:
log(...)andjson(value)to produce output - Write (requires
--allow-write):patch,insert,rename
Rule of thumb: if you're about to make 3+ ctx calls, stop and write an exec script instead.
When onboarding to a codebase
treefor shape + token mapgatherwith default seeds for broad contextoutlineentry points and core modulesextractexact sections from README/AGENTS as neededimportson key modules to understand dependency flow
Hashes and editing
outline output includes hash:xxxx for every symbol. These hashes are used by the editing tools (ctx patch, ctx insert, ctx rename).
read --lineHashes annotates each line with lineNo:hash| content — use these 4-char hashes for ctx patch line-hash mode or hashline fallback. Line hashes are derived from line number + line content, so identical text on different lines gets different hashes. Hashes are valid for the specific content block where they were generated.
When you identify what needs to change, hand off to ctx-code.
Stop conditions
- Stop when you can answer with exact file references.
- Do not full-read large files unless ranked and required.
- Do not finalize recommendations without file + line references.
Workflow: search → edit → verify
This skill is phase 1 of a 3-phase cycle. NEVER use raw Edit/Write/MultiEdit tools for source changes. Always follow this sequence:
- Search (this skill) — investigate, gather context, identify what to change
- Edit — invoke
ctx-codeskill via the Skill tool, then use its patch/insert/rename commands - Verify — invoke
ctx-verifyskill via the Skill tool to review diffs and run tests
When you know what to change → STOP and invoke the ctx-code skill before touching any file. Do not call Edit/Write directly.