tools-ast-grep

tools-ast-grep is a skill for Claude Code, Codex from alexei-led/architect. It costs 102 tokens per session (1,031 once invoked), scanned A, original, MIT.

A way to search source code by its syntax tree—the structure a programming language uses to understand code—instead of matching plain text. Searches can survive formatting and comment changes.

In plain words
What is it for?
Use it to find forbidden imports, layer violations, direct database access, route declarations, framework leaks, or overly large exported interfaces.
Why use it?
It gives precise evidence for structural questions that ordinary text search may answer unreliably.

Skill for Claude CodeCodex

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

Good fit Use it to find forbidden imports, layer violations, direct database access, route declarations, framework leaks, or overly large exported interfaces.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/alexei-led/architect/tools-ast-grep
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 alexei-led/architect --skill tools-ast-grep
Clone the repo
git clone --depth 1 https://github.com/alexei-led/architect

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 tools-ast-grep

README.md
[![agentmods](https://agentmods.dev/badge/skills/alexei-led/architect/tools-ast-grep.svg)](https://agentmods.dev/skills/alexei-led/architect/tools-ast-grep)
Your own site
<a href="https://agentmods.dev/skills/alexei-led/architect/tools-ast-grep"><img src="https://agentmods.dev/badge/skills/alexei-led/architect/tools-ast-grep.svg" alt="Measured on agentmods" height="20"></a>
Per session 102 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 1,031 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.00102 $0.01031
Opus 5 $0.00051 $0.00515
Sonnet 5 $0.00020 $0.00206
Haiku 4.5 $0.00010 $0.00103

Measured 7d ago against content hash 4a233dec7c94, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-07, from the pricing page.

Security

Grade A, and why

tools-ast-grep 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 7d ago.

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.

src/skills/tools-ast-grep/SKILL.md · 107 lines

How it starts

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

ast-grep

ast-grep matches code by its syntax tree, so a pattern survives reformatting, whitespace, and comments that defeat grep. It is the cheapest way to answer "does this pattern exist where it shouldn't?" with a precise file:line list.

Evidence dimension: structural. Output is a concrete evidence ref per match.

When to use

Use when a finding hypothesis is a structural code pattern: "domain code imports the ORM directly," "routes are declared outside the router module," "this framework type leaks past the boundary," or "a module exports too much surface." ast-grep confirms presence/absence with line-anchored hits. Use it before claiming a boundary is bypassed — a claim about a pattern needs the matched lines.

Commands

Run from the repo root. -l sets language; -p is an inline pattern; --json gives machine-readable hits for counting.

# Imports of a specific package (TS/JS)
ast-grep -l ts -p 'import $$$ from "typeorm"'

# Direct DB access leaking into a layer (scope with a path)
ast-grep -l ts -p 'createConnection($$$)' src/domain

# Exported symbols (surface-area survey)
ast-grep -l ts -p 'export $$$'

# Route declarations outside the router (framework leak)
ast-grep -l ts -p 'app.$METHOD($PATH, $$$)'

# Framework type used past the boundary (Python example)
ast-grep -l python -p 'Request' src/core

# Count hits without dumping every match
ast-grep -l go -p 'sql.Open($$$)' --json | jq length

For reusable, named rules (relational metavariable constraints, inside, not), put them in a YAML rule file and run ast-grep scan -r rule.yml. See references/rules.md for the rule patterns this review relies on.

Evidence output

Record:

  • dimension: structural.
  • source: ast-grep command, language, pattern/rule file, searched scope, and version when parser behavior is in doubt.
  • facts: matched file:line refs or confirmed zero-match scope.
  • limits: parse errors, unsupported language, regex fallback, or lack of semantic reachability.

Read the full file on GitHub · 107 lines

Files

What ships with it

1 file beside SKILL.md in the same directory: the scripts, references and assets a skill reads on demand. Not counted in the per-session cost; read them before you install if any of them is executable.

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. 7d ago First seen · 107 lines · 102 tokens per session scan A 4a233dec7c94

Subscribe to this mod's changes

tools-ast-grep is a skill published in the GitHub repository alexei-led/architect (2 stars, last pushed 1mo ago), licensed MIT. It adds 102 tokens to every session and 1,031 once invoked, about $0.0005 per session on Opus 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.

Related

Other skills, from other repositories