Agent skill

Pi Lens Ast Grep

by apmantza in apmantza/pi-lens

A skill your agent uses when searching or replacing code patterns - use ast-grep instead of text search for semantic accuracy

MITAuto-check passedDevelopment

Install Pi Lens Ast Grep

skills CLI
$ npx skills add apmantza/pi-lens --skill pi-lens-ast-grep -a claude-code

Project install by default; add -g for ~/.claude/skills/.

GitHub CLI
$ gh skill install apmantza/pi-lens pi-lens-ast-grep --agent claude-code

Project scope by default; add --scope user for a personal install. Needs GitHub CLI 2.90.0 or later (public preview).

Manual copy
$ git clone --depth 1 https://github.com/apmantza/pi-lens.git skills-src && mkdir -p .claude/skills && cp -r skills-src/skills/pi-lens-ast-grep .claude/skills/pi-lens-ast-grep && rm -rf skills-src

Use ~/.claude/skills/ instead of .claude/skills for a personal install. The folder must contain SKILL.md.

Claude Code skills documentation · loads skills from .claude/skills/

Facts

Skill name
pi-lens-ast-grep
GitHub stars
466
Token cost
~2k tokens
SKILL.md length
745 words
Files
1
Skills in repo
6
Repo updated
First seen
Licence
MIT

At a glance

A skill your agent uses when searching or replacing code patterns - use ast-grep instead of text search for semantic accuracy

  • Works in 7 steps: Be specific — fetchMetrics($ARGS) not… → Scope it — always specify paths to… → Retry once on zero matches — simplify… → …
  • Replacing code patterns - use ast-grep instead of text search for semantic accuracy
  • SKILL.md covers When to Use, Golden Rules, Metavariables and Quick Reference, plus 2 more sections
  • Instructions only: no scripts, shell commands, URLs or credentials in SKILL.md

What it does

Pi Lens Ast Grep is an agent skill from apmantza/pi-lens. Use when searching or replacing code patterns - use ast-grep instead of text search for semantic accuracy

Its SKILL.md is about 2k tokens, which your agent loads only when the skill is triggered. It is a single SKILL.md file with no bundled scripts.

It sits in Development. The repository describes itself as: Real-time code feedback for pi — LSP, linters, formatters, structural analysis. The licence is MIT.

When your agent uses it

  • Replacing code patterns - use ast-grep instead of text search for semantic accuracy

Example prompts

  • “/pi-lens-ast-grep”

Workflow steps

7 steps, taken from the first numbered list in SKILL.md.

  1. Be specific — fetchMetrics($ARGS) not fetchMetrics
  2. Scope it — always specify paths to relevant files
  3. Retry once on zero matches — simplify the pattern, same paths, then fall back to grep
  4. Dry-run first — apply: false before apply: true
  5. Valid code only — function $NAME($$$) { $$$ } not function $NAME(
  6. Avoid selector unless expert — narrows to AST node kind; does not extract metavariables
  7. Metavariables don't work inside strings — from "$PATH" matches literal "$PATH", not a wildcard

What it can do on your machine

Read from SKILL.md and the folder at commit db92612. It shows what the files ask for, not the result of running them.

  • Tool permissions

    Pre-approves nothing: there is no allowed-tools line, so your agent's usual permission prompts apply.

    From allowed-tools in the SKILL.md frontmatter.

  • Runs code

    No scripts in the folder and no shell commands in SKILL.md (its code samples are yaml and bash).

    From the folder's file list and the shell code blocks in SKILL.md.

  • Network

    Links to these hosts (documentation or services it may open):

    • ast-grep.github.io

    From URLs in SKILL.md, links to its own repository left out.

  • Credentials

    Names no API keys, tokens, secrets or passwords.

    From names ending in _API_KEY, _TOKEN, _SECRET, _KEY or _PASSWORD in SKILL.md.

Context cost

Pi Lens Ast Grep loads about 2k tokens when it runs. Until then it costs about 31 tokens; SKILL.md has 745 words of instructions outside code blocks.

Always · name and description, kept in context so the agent knows when to use it
~31
When it runs · the whole SKILL.md, loaded when a task matches
~2k

Estimates: characters ÷ 4, the usual rule of thumb; real counts depend on the model's tokenizer. Scripts and assets cost tokens only if the agent reads them.

Safety

Auto-check passed

The automated check found no risky patterns in SKILL.md.

Automated static check — not a guarantee. Review scripts before installing. It scans the text of SKILL.md for risky patterns (piping downloads into a shell, reading credential files, hidden Unicode, destructive commands); files beside SKILL.md are not scanned.

SKILL.md

The full file from apmantza/pi-lens at commit db92612, republished under its MIT licence (© apmantza). 745 words, ~1,987 tokens.

Download SKILL.mdSave it as .claude/skills/pi-lens-ast-grep/SKILL.md (or your agent's skills folder).
name
pi-lens-ast-grep
description
Use when searching or replacing code patterns - use ast-grep instead of text search for semantic accuracy

Use ast_grep_search and ast_grep_replace for semantic code search/replace. ast-grep understands code structure, not just text.

These tools (plus ast_grep_outline, lsp_navigation) are registered but inactive by default on hosts that support pi's dynamic tooling. If a call to one of them isn't recognized, activate it first: pi_lens_activate_tools tools=["ast_grep_search", "ast_grep_replace"].

On hosts that aggregate pi-lens behind a single lens tool, the ast_grep_* tools and pi_lens_activate_tools may not be registered at all. There, fall back to the ast-grep CLI (alias sg) — patterns, metavariables, and YAML rules are identical:

bash
# search (≈ ast_grep_search)
ast-grep run -p 'fetchMetrics($$$ARGS)' -l ts src/

# rewrite (≈ ast_grep_replace; -U applies all)
ast-grep run -p 'var $X' -r 'let $X' -l js src/ -U

# full YAML rule (≈ the rule: parameter)
ast-grep scan --rule my-rule.yml src/

Structural-intent parameters map to YAML constraints: insideKind → inside: { kind: ..., stopBy: end }, hasKind/hasDescendantKind → has: { kind: ... }, follows → follows: { pattern: ... }, precedes → precedes: { pattern: ... }.

When to Use

  • Function calls, imports, class methods (structured code)
  • Safe replacements across files
  • Use LSP first for: definitions/references/types — then scope ast-grep to files discovered by LSP
  • Use grep for: partial string patterns, comments, URLs, or after one simplified ast-grep retry still returns zero matches

Golden Rules

  1. Be specific — fetchMetrics($ARGS) not fetchMetrics
  2. Scope it — always specify paths to relevant files
  3. Retry once on zero matches — simplify the pattern, same paths, then fall back to grep
  4. Dry-run first — apply: false before apply: true
  5. Valid code only — function $NAME($$$) { $$$ } not function $NAME(
  6. Avoid selector unless expert — narrows to AST node kind; does not extract metavariables
  7. Metavariables don't work inside strings — from "$PATH" matches literal "$PATH", not a wildcard

Metavariables

SyntaxMatchesNamed?
$Xsingle nodeyes — captures the node
$$$zero or more nodesno — unnamed wildcard
$$$ARGSzero or more nodesyes — captures the list

Use $$$ when you don't need the captured value; $$$NAME when you do.

Quick Reference

Patterns
PatternMatches
fetchMetrics($ARGS)call with any single arg
fetchMetrics($$$ARGS)call with any number of args
function $NAME($$$) { $$$ }function declaration
import { $NAMES } from $PATHnamed import (no quotes on path)
const $X = $Yvariable declaration
Structural-intent parameters (preferred for cross-context queries)

Use these instead of writing raw YAML:

ParameterToolWhat it does
insideKindbothOnly match inside an ancestor of this node kind (searches ALL ancestors, stopBy: end)
hasKindbothOnly match nodes whose immediate child has this kind (stopBy: neighbor — NOT recursive)
hasDescendantKindbothOnly match nodes containing this kind anywhere in their descendants (stopBy: end) — use this instead of hasKind when the target isn't a direct child
followsbothOnly match nodes preceded by a sibling matching this pattern
precedesbothOnly match nodes followed by a sibling matching this pattern

hasKind and hasDescendantKind are mutually exclusive on both tools — combining them errors.

⚠ insideKind searches ALL ancestors (stopBy: end) with no boundary of its own — on a deeply nested file it can escalate past the enclosing function you meant and match against an unrelated outer scope; scope with paths or a raw YAML rule: with its own stopBy boundary if that matters.

# console.log only inside functions
ast_grep_search pattern="console.log($MSG)" lang="typescript" insideKind="function_declaration"

# replace var with let, scoped to functions only
ast_grep_replace pattern="var $X" rewrite="let $X" lang="javascript" insideKind="function_declaration"

These synthesize a YAML rule automatically. Use rule: for the full DSL when you need all/any/not, nthChild, regex, or other advanced constraints.

Show full SKILL.md (256 more words)Show less
Raw YAML rule (rule: parameter)

Pass a complete ast-grep YAML rule to unlock the full DSL:

ast_grep_search rule="id: my-rule
language: TypeScript
rule:
  pattern: console.log($MSG)
  inside:
    kind: function_declaration
    stopBy: end" lang="typescript"
Debugging unknown node kinds — ast_grep_search dump mode

When a pattern returns zero matches and you don't know the correct node kind or field name, use ast_grep_search with dump=true to inspect a SMALL representative snippet:

ast_grep_search dump=true pattern="function foo() { return 1; }" lang="typescript"

Returns the full indented AST with node kinds and positions. Then use the correct kind in your pattern or insideKind.

Composite (has/inside) in raw YAML
yaml
# console.log inside a class method
pattern: console.log($$$)
inside:
  kind: method_definition
  stopBy: end

Use kind: directly when you want to match a node type without a pattern:

yaml
# any arrow function
kind: arrow_function

Common Gotchas

❌ $VAR inside quotes — matches literal "$VAR", not a metavar
   from "$PATH"  →  use grep for wildcard path matching
   from "./utils"  →  ✅ exact string literal works fine

❌ Trailing comma in objects
   { type: $T, }  →  use { type: $T }

❌ Shorthand property mismatch
   { runnerId: $RID }  →  won't match { runnerId }
   use { runnerId } or { runnerId, $$$REST }

❌ Unnamed $$$ when you need the value
   foo($$$)  →  captures nothing; use foo($$$ARGS) to inspect matches

❌ Multiple top-level statements — triggers "Multiple AST nodes are detected"
   Two shapes, two fixes:

   1. Sequence inside a block — wrap in braces:
      foo(); bar();  →  { foo(); bar(); }

   2. Cross-context (module-level + block-level together, e.g. an import AND a call) —
      wrapping in {} makes the pattern invalid (imports can't live inside a block).
      Use two searches: find files containing the import, then scope the call search
      to those paths. Or use a YAML `inside:`/`has:` rule (see Composite section above).

No matches?

For nodeKind, do not also pass pattern or rule; those forms are mutually exclusive. For rule, provide YAML containing both id and language fields. Use strictness: relaxed when unnamed punctuation is the only mismatch.

  1. Try strictness: relaxed — ignores unnamed punctuation (trailing commas, semicolons) that smart mode requires
  2. Use ast_grep_search dump=true on a sample snippet to verify the correct node kind
  3. Simplify the pattern and retry once
  4. Fall back to grep or lsp_navigation

Agent task recipes

Use these as starting points, then scope paths tightly.

TaskPattern / params
Find object-literal function dependency by namepattern: { resetLSPService: $FN, $$$REST }
Find empty catchespattern: try { $$$BODY } catch ($ERR) { }
Find fire-and-forget async callspattern: void $CALL

For lifecycle bugs, search first, then use the returned details.matchLocations[].readSlice handle for bounded context.

Metavar captures appear automatically below each match line:

src/foo.ts:1:1: const x = foo(a, b)
  $VAR=x  $$$ARGS=a,b

Named captures ($X, $$$NAME) are shown; unnamed wildcards ($$$) are not.

Pagination — use skip: N when results are truncated (next-page hint appears in output).

Debug: https://ast-grep.github.io/playground.html

© apmantza, MIT. Rendered from Markdown: HTML in the file is shown as text, images as links, and headings moved down two levels. Raw file

Files

Just SKILL.md in skills/pi-lens-ast-grep of apmantza/pi-lens.

Open the folder on GitHubat commit db92612

Compare with similar skills

Pi Lens Ast Grep next to the 5 skills that share the most tags, products or categories with it. Stars are the repository's; “used in” counts other GitHub owners with a copy.

Pi Lens Ast Grep compared with similar skills
SkillStarsUsed inTokensAuto-checkLicenceRepo updated
Pi Lens Ast Grep this skillapmantza/pi-lens466—~2kAutomated safety check: PassMIT
Vercel Composition Patternssupabase/supabase111k58 repos~726Automated safety check: PassMIT
Finishing a Development Branchobra/superpowers297k5 repos~1.9kAutomated safety check: PassMIT
Typescript Advanced Typesrolling-scopes/rsschool-app10k25 repos~4.2kAutomated safety check: PassMPL-2.0
PR Babysitteropeninterpreter/openinterpreter69k3 repos~4.2kAutomated safety check: PassApache-2.0
Code Review ChecklistshareAI-lab/learn-claude-code78k4 repos~1.1kAutomated safety check: PassMIT

Similar skills

  • Official

    React composition patterns that scale. An agent skill from supabase/supabase.

    111k GitHub starsUsed in 58 repos~726 tokens
    DevelopmentAuto-check passed
  • Walks the last step of a branch: confirm tests pass, detect the git environment, ask how to integrate, carry out your choice and clean up the worktree.

    297k GitHub starsUsed in 5 repos~1.9k tokens
    DevelopmentAuto-check passed
  • Typescript Advanced Types

    rolling-scopes/rsschool-app

    Master TypeScript's advanced type system including generics, conditional types, mapped types, template literals, and utility types for building type-safe applications.

    10k GitHub starsUsed in 25 repos~4.2k tokens
    DevelopmentAuto-check passed
  • PR Babysitter

    openinterpreter/openinterpreter

    Watches an open GitHub pull request until it merges, handling review comments, diagnosing CI failures and retrying flaky checks along the way.

    69k GitHub starsUsed in 3 repos~4.2k tokens
    DevelopmentAuto-check passed
  • Code Review Checklist

    shareAI-lab/learn-claude-code

    Reviews code against a five-part checklist covering security, correctness, performance, maintainability and testing, and reports findings in a fixed format.

    78k GitHub starsUsed in 4 repos~1.1k tokens
    DevelopmentAuto-check passed
  • Greploop

    onyx-dot-app/onyx

    Iteratively improves a PR (GitHub), MR (GitLab), or shelved changelist (Perforce) until Greptile gives it a 5/5 confidence score with zero unresolved comments.

    32k GitHub starsUsed in 4 repos~3.3k tokens
    DevelopmentAuto-check passed

More from apmantza/pi-lens

  • A skill your agent uses when writing a new pi-lens ast-grep rule YAML file — covers schema, drop path, gotchas, and NAPI runner constraints

    466 GitHub stars~2.1k tokensUpdated today
    Auto-check passed
  • A skill your agent uses when writing a new pi-lens tree-sitter query rule YAML file — covers schema, S-expression syntax, capture names, predicates, and gotchas

    466 GitHub stars~1.2k tokensUpdated today
    Auto-check passed
  • Pi Lens Lsp Navigation

    apmantza/pi-lens

    Navigate code with IDE features and run proactive LSP diagnostics on files/folders/batches.

    466 GitHub stars~1.6k tokensUpdated today
    Auto-check passed
  • Release QA

    apmantza/pi-lens

    Run the pi-lens release-readiness QA pass — witness the feature × modality matrix against a real pi, count coverage, and issue a ship / ship-with-caveats / don't-ship / blocked line.

    466 GitHub stars~2.6k tokensUpdated today
    Auto-check passed
  • Retro

    apmantza/pi-lens

    Run the pi-lens retrospective — turn a session, an incident, or a merged bug fix into environment changes (checks, hooks, contract lines, deletions), classified mechanical-vs-judgement, each with…

    466 GitHub stars~531 tokensUpdated today
    Auto-check passed

Categories

Questions about Pi Lens Ast Grep

What does Pi Lens Ast Grep do?

A skill your agent uses when searching or replacing code patterns - use ast-grep instead of text search for semantic accuracy. Pi Lens Ast Grep is an agent skill from apmantza/pi-lens.

When should I use Pi Lens Ast Grep?

Pi Lens Ast Grep fits situations like: replacing code patterns - use ast-grep instead of text search for semantic accuracy.

How do I install Pi Lens Ast Grep in Claude Code?

Run `npx skills add apmantza/pi-lens --skill pi-lens-ast-grep -a claude-code`. Or copy the skill folder (skills/pi-lens-ast-grep in apmantza/pi-lens) into .claude/skills/pi-lens-ast-grep in your project. Claude Code loads it when a task matches its description.

How do I install Pi Lens Ast Grep in Codex?

Run `npx skills add apmantza/pi-lens --skill pi-lens-ast-grep -a codex`. Or copy the skill folder (skills/pi-lens-ast-grep in apmantza/pi-lens) into .agents/skills/pi-lens-ast-grep in your project. Codex loads it when a task matches its description.

Can I use Pi Lens Ast Grep in Cursor, Gemini CLI or GitHub Copilot?

Cursor, Gemini CLI, GitHub Copilot and OpenCode also load SKILL.md folders. With the skills CLI, run `npx skills add apmantza/pi-lens --skill pi-lens-ast-grep -a cursor` (or -a gemini-cli, github-copilot or opencode for the others). To copy it by hand, put the folder in .cursor/skills/pi-lens-ast-grep, .gemini/skills/pi-lens-ast-grep, .github/skills/pi-lens-ast-grep and .opencode/skills/pi-lens-ast-grep in your project.

What does Pi Lens Ast Grep need to run?

SKILL.md names no scripts, command-line tools or credentials: Pi Lens Ast Grep is instructions for the agent only.

Does Pi Lens Ast Grep access the network?

SKILL.md names 1 domain. As links in the text: ast-grep.github.io. This is read from the text; nothing was executed.

Is Pi Lens Ast Grep safe to install?

Our automated static check of SKILL.md found no risky patterns, such as piping downloads into a shell, reading credential files or hidden Unicode. It is not a guarantee. Review the folder before installing.

What licence does Pi Lens Ast Grep use?

Pi Lens Ast Grep is published under the MIT licence (the repository's licence). It allows redistribution, so the full SKILL.md is shown on this page.

How many tokens does Pi Lens Ast Grep use?

About 2k tokens (SKILL.md is roughly 7.9k characters). Agents keep only the skill's name and description in context until a task matches; then they load SKILL.md in full.

What are the alternatives to Pi Lens Ast Grep?

Skills that share tags, products or a category with Pi Lens Ast Grep: Vercel Composition Patterns (supabase/supabase, 111k stars), Finishing a Development Branch (obra/superpowers, 297k stars), Typescript Advanced Types (rolling-scopes/rsschool-app, 10k stars) and PR Babysitter (openinterpreter/openinterpreter, 69k stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.

Who maintains Pi Lens Ast Grep?

apmantza (a GitHub user) maintains it in apmantza/pi-lens, which has 466 GitHub stars. The repository holds 6 skills in this directory. The repository was last updated on October 11, 2026.

Source: apmantza/pi-lens on GitHub. Facts on this page come from the repository at the commit we read; the author's words are quoted as theirs.