ast-code-graph

ast-code-graph is a skill for Claude Code, Codex from rolandbrecht/agent-skills. It costs 196 tokens per session (3,056 once invoked), scanned A, original, MIT.

A code-analysis workflow that understands program structure, including definitions, calls, imports, and dependencies, instead of only matching text. It uses syntax trees, which represent how code is arranged.

In plain words
What is it for?
It helps locate structural patterns, analyze dependencies and impact, find dead code, and identify code that needs refactoring.
Why use it?
It reduces mistakes when searching for symbols, tracing what a change may affect, or finding unused code. Plain text search can also match comments, strings, or unrelated names.

Skill for Claude CodeCodex

Written for no agent in particular: nothing here depends on one.

Good fit It helps locate structural patterns, analyze dependencies and impact, find dead code, and identify code that needs refactoring.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/rolandbrecht/agent-skills/ast-code-graph
Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

Any agent
npx skills add rolandbrecht/agent-skills --skill ast-code-graph
Clone the repo
git clone --depth 1 https://github.com/rolandbrecht/agent-skills

Made for: Claude Code, Codex.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for ast-code-graph

README.md
[![agentmods](https://agentmods.dev/badge/skills/rolandbrecht/agent-skills/ast-code-graph/github.svg)](https://agentmods.dev/skills/rolandbrecht/agent-skills/ast-code-graph)
Your own site
<a href="https://agentmods.dev/skills/rolandbrecht/agent-skills/ast-code-graph"><img src="https://agentmods.dev/badge/skills/rolandbrecht/agent-skills/ast-code-graph/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for ast-code-graph

Your own site · 80×15
<a href="https://agentmods.dev/skills/rolandbrecht/agent-skills/ast-code-graph"><img src="https://agentmods.dev/badge/skills/rolandbrecht/agent-skills/ast-code-graph.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 196 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 3,056 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00196 $0.03056
Opus 5.5 $0.00078 $0.01222
Sonnet 5.5 $0.00039 $0.00611
Haiku 4.5 $0.00020 $0.00306

Measured 1mo ago against content hash aad7bcda094b, method: parsed. Prices are Anthropic first-party input rates as of 2026-10-07, from the pricing page.

Security

Grade A, and why

ast-code-graph scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 1mo ago.

The scan reads SKILL.md. This mod also ships 9 executable files (scripts/build-graph.py, scripts/parse-js.mjs, tests/fixtures/sample_helper.py, …), listed below but not scanned — reading those needs a real analyzer, not pattern matching.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

ast-code-graph/SKILL.md · 237 lines

How it starts

The opening of the file, as written. The whole thing — 237 lines — stays where its author put it; the contents beside it link to each section on GitHub.

AST & Code Graph Indexing

Overview

Text-based search (grep, ripgrep) finds string matches. AST-based analysis understands structure — it knows the difference between a function definition, a function call, a comment, and a string literal.

Primary tool: ast-grep (sg / ast-grep) — a fast, Rust-based CLI for structural code search, lint, and rewriting. It uses tree-sitter for parsing and supports 20+ languages out of the box.

Core principle: When the question is about code structure, use AST analysis. When the question is about text content, use grep.

Trigger Patterns

Detailed examples of when to trigger this skill:

Category Example queries
Structural pattern search "useEffect without dependency array", "async functions without try-catch", "User.objects.get() without exception handling", "fetch() calls outside src/api/", "console.log inside class methods", "route handlers missing error handling"
Bulk code migration wrap all async handlers, replace all X() calls with Y(), add error handling to all route handlers, rewrite deprecated API patterns across hundreds of files
Dependency & impact analysis "what does analyzePayment depend on", "blast radius of changing X", "which modules depend on ./lib/database.js", "direct and transitive dependencies"
Safe renaming "rename fetchUserData to getUserData safely", rename across TypeScript/JavaScript codebase
Dead code & circular imports "exports never imported anywhere", "circular imports causing webpack bundle", unused exports, which npm dependencies are actually used in source
ast-grep rules write an ast-grep rule, sg pattern, ast-grep syntax

When to Use

Use this skill when the task involves:

Task Why AST beats grep
Refactoring / renaming Grep finds the string in comments and strings too; AST finds only the symbol
Dead code detection Grep can't tell if an export is actually imported elsewhere
Dependency tracing "What modules does X depend on?" requires understanding import/require
Impact analysis "If I change function X, what breaks?" needs call-graph traversal
Circular dependency detection Requires building and analyzing a full import graph
Code migration Rewriting deprecated API patterns structurally across a codebase
Custom linting Enforcing project-specific patterns that standard linters don't cover

Read the full file on GitHub · 237 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 1mo ago First seen · 237 lines · 196 tokens per session scan A aad7bcda094b

Subscribe to this mod's changes

ast-code-graph is a skill published in the GitHub repository rolandbrecht/agent-skills (4 stars, last pushed 29d ago), licensed MIT. It adds 196 tokens to every session and 3,056 once invoked, about $0.0008 per session on Opus 5.5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.