ast-grep

ast-grep is a skill for Claude Code, Codex from aivrar/portable-hermes-agent. It costs 16 tokens per session (3,452 once invoked), scanned A, a copy of ast-grep, MIT.

A code-structure search and rewrite tool based on the abstract syntax tree, the parsed structure that represents a program. It matches code by its shape rather than by the exact text appearing in a file.

In plain words
What is it for?
Use it to find structural patterns, apply codemods, replace syntax across a repository, detect constructs such as empty catch blocks, and validate rewrite patterns.
Why use it?
It finds and changes patterns more reliably when formatting, variable names, or surrounding text differ. This is useful for large code migrations and automated rewrites across many files.

Skill for Claude CodeCodex

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

Good fit Use it to find structural patterns, apply codemods, replace syntax across a repository, detect constructs such as empty catch blocks, and validate rewrite patterns.

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

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

README.md
[![agentmods](https://agentmods.dev/badge/skills/aivrar/portable-hermes-agent/ast-grep/github.svg)](https://agentmods.dev/skills/aivrar/portable-hermes-agent/ast-grep)
Your own site
<a href="https://agentmods.dev/skills/aivrar/portable-hermes-agent/ast-grep"><img src="https://agentmods.dev/badge/skills/aivrar/portable-hermes-agent/ast-grep/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-grep

Your own site · 80×15
<a href="https://agentmods.dev/skills/aivrar/portable-hermes-agent/ast-grep"><img src="https://agentmods.dev/badge/skills/aivrar/portable-hermes-agent/ast-grep.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 16 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 3,452 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 100% copy Near-identical to another mod 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.00016 $0.03452
Opus 5 $0.00008 $0.01726
Sonnet 5 $0.00003 $0.00690
Haiku 4.5 $0.00002 $0.00345

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

Security

Grade A, and why

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.

The scan reads SKILL.md. This mod also ships 5 executable files (install.ps1, install.sh, scripts/ast_grep_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.

Origin

This is a copy

100% identical to ast-grep — 0 lines differ, which has more behind it and is treated as the original. This page carries a canonical link to it rather than competing with it.

optional-skills/software-development/ast-grep/SKILL.md · 289 lines

How it starts

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

ast-grep

ast-grep (binary also named sg) is an AST-aware search and rewrite tool across 25 languages. It treats your pattern as code, parses it the same way it parses your project, and matches structurally. It is the right tool whenever your question depends on code shape rather than text bytes.

This skill ships a Python wrapper at scripts/ast_grep_helper.py and platform install scripts at install.sh (POSIX) and install.ps1 (Windows). The helper adds offline pattern validation, the two-pass write trick, and binary auto-resolution. Use it as your default entry point.

Upstream source: vendored from code-yeongyu/ast-grep-skill (MIT), as shipped in oh-my-openagent's shared-skills bundle.


When to use this skill

Use it whenever the question is about code structure, not bytes:

  • "Find every function that takes a Request parameter."
  • "Rewrite every console.log(x) to logger.info(x)."
  • "Strip every as any cast."
  • "Replace require(...) with import across the repo."
  • "Find empty catch blocks."
  • "Migrate Optional[X] to X | None."
  • "Apply this codemod across these 200 files."
  • "Run our YAML lint rules and surface violations."

Switch to search_files (or plain rg) when the question is text-shaped (string literal contents, comments, license headers, file names, cross-language regex). When in doubt, ask: "does the answer depend on the language's syntax tree, or just on the file's bytes?" If the former, ast-grep. If the latter, search_files.

Hermes integration notes:

  • Run the helper and sg through the terminal tool. Single-quote every pattern so the shell never expands $VAR.
  • For find→read chains around matches, use --json-out and process with execute_code rather than piping through interpreters.
  • This complements (does not replace) Hermes's patch tool: patch is for targeted edits you author; ast-grep is for pattern-driven bulk rewrites across many sites.

Read the full file on GitHub · 289 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. 7d ago First seen · 289 lines · 16 tokens per session scan A e5404b443ee1

Subscribe to this mod's changes

ast-grep is a skill published in the GitHub repository aivrar/portable-hermes-agent (217 stars, last pushed 2d ago), licensed MIT. It adds 16 tokens to every session and 3,452 once invoked, about $0.0001 per session on Opus 5. A static security scan graded it A with 0 findings. It is 100% identical to ast-grep, differing in 0 lines, and is treated as a copy.

Related

Other skills, from other repositories

ha-self-diagnosis

Self-understanding and issue reporting for Hope Agent itself. Use when the user asks how Hope Agent works internally, asks about its own source code/docs/runtime behavior, reports a bug/failure/slowness/crash, asks to diagnose logs, or asks to create/submit a GitHub issue for a bug, feature request, or improvement…

shiwenwen/hope-agent · 114 tokens

rag-index-decisions

After making a non-obvious architectural decision, solving a novel bug, agreeing on a coding standard, or reaching a conclusion worth remembering, index it back into the knowledge base so the next occurrence is one search away. Uses adddocument or addfromurl. Closes the feedback loop that makes a RAG-backed team…

lyonzin/knowledge-rag · 72 tokens

olares-doctor

Runtime diagnosis for Olares apps and the system via olares-cli — find the root cause when an app won't install or start, crashes, cannot pull an image, is running but unreachable, or is slow; includes doctor images and thirdleveldomain. Use for diagnosing catalog and dev app failures, not for authoring or editing…

beclab/Olares · 74 tokens

log-analyzer

Parse agent log files to identify error patterns, rate limit hits, timeout clusters, tool failures, and component-level error counts. Produces a structured anomaly report. Cron-compatible — silent if no issues, alert digest if anomalies found. Also computes per-tool failure rates from a Hermes profile state.db…

moonlight-lupin/agent-skills · 69 tokens

feishu-troubleshoot

A Feishu troubleshooting tool with FAQs and diagnostic commands. Feishu is a collaboration platform with online documents and workplace services.

op7418/CodePilot · 92 tokens

worth-fix

A verification and decision-making guide for checking whether bug reports, claims, proposals, or refactoring ideas are true and worth acting on.

luochang212/skill-zoo · 134 tokens