Code context

From swissarmyhammer/swissarmyhammer · View interactive version

Code context is an AI agent skill from the GitHub repository swissarmyhammer/swissarmyhammer. Code context operations for symbol lookup, search, grep, call graph, and blast radius analysis. Use when the user says "blast radius", "who calls this", "find symbol", "find references", "go to definition", "symbol lookup", "callgraph", "find callers", "what calls this function", or "what's affected

How to use this skill

Skill file

Code Context

Structural code intelligence for AI agents — indexed symbol lookup, callgraph traversal, blast-radius analysis, semantic search, AST queries. Tree-sitter + optional live LSP.

The code_context tool is structural code intelligence — indexed symbol lookup,

call graphs, and blast-radius analysis backed by tree-sitter and live LSP. It is

not optional background. Lean on the cheap defaults below — list symbols and

get symbol instead of reading whole files, get callgraph (inbound) to find

callers — as part of doing the task, not extra work on top of it.

Do not read files top to bottom, and do not guess where a symbol lives or who

calls it. code_context answers those questions precisely and cheaply.

table of contents, then {"op": "get symbol", "query": "<symbol>"} to pull only

the code you need. Reading a whole file is the fallback, not the default.

"direction": "inbound"}` to see who calls it. When the symbol is shared or public

and you are changing its signature, also `{"op": "get blastradius", "file_path":

"<file>"}` for the wider dependent set. If the result surprises you, you do not yet

understand the change well enough to make it.

blast radius surfaced, and confirm each one still holds.

symbol>"}` to see what the failure actually reaches before you start fixing it.

raw text search; they query the index, with kind and language filters.

If {"op": "get status"} shows indexing incomplete, the live LSP ops

(get definition, get hover, get references, search workspace_symbol) still

work immediately — do not wait on the index. If callgraph or blast radius comes

back empty for code that clearly compiles, the language server is missing or

warming up: check {"op": "lsp status"} and invoke /lsp if needed.

Fall back to raw Read/Grep/Glob only for non-code files (TOML, YAML, Markdown),

string literals and config values not in the symbol index, or confirming exact

syntax once code_context has already given you the location.

When to Use

Operations

get symbol

{"op": "get symbol", "query": "MyStruct::new", "max_results": 5}

Jump to definition with source context. Multi-tier fuzzy matching, supports qualified paths. Use this to avoid whole file reads.

search symbol

{"op": "search symbol", "query": "handler", "kind": "function", "max_results": 10}

Fuzzy by partial name. Kinds: function, method, struct, class, interface, module, etc. Use this to avoid whole file reads.

list symbols

{"op": "list symbols", "file_path": "src/main.rs"}

File overview before reading. Lets you target specific symbols with get symbol instead of reading the whole file.

grep code

{"op": "grep code", "pattern": "unsafe\\s*\\{", "language": ["rs"], "max_results": 20}

Regex over indexed chunks. Filter by language extensions or specific paths. Use this instead of built in Grep tools or using any kind of bash or shell.

search code

{"op": "search code", "query": "authentication handler", "top_k": 5}

Semantic similarity — matches by meaning, not exact text.

get callgraph

{"op": "get callgraph", "symbol": "process_request", "direction": "inbound", "max_depth": 2}

get blastradius

{"op": "get blastradius", "file_path": "src/server.rs", "max_hops": 3}

Transitive set of files/symbols affected by a change. Reach for it when changing a shared or public symbol's signature and you need its dependents — not a gate on every edit. Built from LSP call edges, so edges: [] is common on compiling code when LSP is missing or warming up (see Troubleshooting); empty does not mean "no impact", so don't gate work on it — fall back to inbound get callgraph and targeted reads.

Narrow to a symbol:

{"op": "get blastradius", "file_path": "src/server.rs", "symbol": "handle_request", "max_hops": 2}

find duplicates

{"op": "find duplicates", "file_path": "src/handlers.rs", "min_similarity": 0.85}

query ast

{"op": "query ast", "query": "(function_item name: (identifier) @name)", "language": "rust"}

Tree-sitter S-expression queries — structural search beyond regex.

get status

{"op": "get status"}

Indexing progress. Run first if unsure whether the index is ready.

lsp status

{"op": "lsp status"}

LSP server health per language. Missing? Follow the install hint.

detect projects

{"op": "detect projects"}

Project types, build/test commands, coding guidelines. Run early to learn conventions.

Workflow Patterns

Before modifying code

  1. list symbols on the target file
  2. get symbol to read the function/struct
  3. get callgraph (inbound) on the symbol to find callers
  4. Changing a shared/public symbol's signature? get blastradius on the file for the wider dependent set (skip when it returns empty edges)
  5. Make changes
  6. Re-check callers for compatibility

Exploring unfamiliar code

  1. detect projects for type/conventions
  2. get status to verify the index
  3. search symbol with broad queries → discover key types
  4. get callgraph (outbound) on entry points → trace flow
  5. list symbols on files of interest before reading

Bug fixes

  1. grep code for the error message or pattern
  2. get symbol for the relevant function
  3. get callgraph (inbound) to trace how execution reaches it
  4. get blastradius to verify the fix won't break other code

Troubleshooting

`search symbol` / `get symbol` returns nothing for a symbol you know exists

Index hasn't finished. On a fresh workspace, CodeContextWorkspace::open() runs startup_cleanup() then spawns a background worker. Until it finishes, queries see an empty/partial index.

{"op": "get status"}

If files_pending > 0, wait and poll. Only report missing when files_pending == 0.

`get status` shows `files_indexed: 0` and `files_pending: 0` on a non-empty repo

Startup cleanup didn't run — usually a stale leader lock from an uncleanly exited process. The reader-side workspace never re-scans on its own.

{"op": "rebuild index", "layer": "both"}

Poll get status until files_pending: 0. Persistent → wipe and rebuild:

{"op": "clear status"}

Restart the MCP server so open() runs cleanup as leader.

`get callgraph` / `get blastradius` returns `edges: []` on visible compiling code

Call edges come from LSP. If LSP is missing or warming up, lsp_call_edges is empty and traversal degrades to a single node.

{"op": "lsp status"} — confirm installed/healthy. Missing → follow the install hint (or /lsp), wait for initial scan, re-run after get status shows complete.

`grep code` returns nothing although `rg` finds it on disk

grep code searches stored chunks, not the filesystem. Files modified outside the MCP session aren't auto-invalidated (the file-watcher is currently a FileEvent enum without an active watcher).

{"op": "rebuild index", "layer": "treesitter"}

For one-off live searches, use the host Grep tool. It reads the

filesystem, honors .gitignore, and skips binary files. Do not shell out to

grep -r.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.