Agent-skill enables AI agents to search codebases using Abstract Syntax Tree (AST) patterns. It benefits developers and operations teams by allowing structural code search beyond simple text matching. The skill integrates with Claude Code plugin marketplace and is applied in code analysis, refactoring, and maintenance tasks.
git clone https://github.com/ast-grep/agent-skill.githttps://ast-grep.github.io/
1. **Install the skill:** Ensure you have the Claude Code plugin installed and the agent-skill is enabled in your workspace. Run `claude code install agent-skill` if not already installed. 2. **Prepare your query:** Use the prompt template above, replacing [DIRECTORY_PATH] with your target directory (e.g., `./src`), [AST_PATTERN] with your specific pattern (e.g., 'function calls to `axios.get()` with a URL variable as the first argument'), and [LANGUAGE] with your language (e.g., 'JavaScript'). 3. **Execute the search:** Run the query in your terminal or IDE. The skill will parse the codebase using AST and return structured results with file paths, line numbers, and code snippets. 4. **Refine your query:** If results are too broad, narrow the AST pattern (e.g., add constraints like 'only in production code' or 'excluding test files'). Use specific function names, variable types, or structural constraints. 5. **Integrate findings:** Use the results to drive refactoring, debugging, or documentation updates. Export the output to a file for further analysis if needed (e.g., `> findings.txt`).
Find all async functions that do not implement error handling.
Locate React components that utilize a specific custom hook.
Identify functions with more than three parameters for potential refactoring.
Search for console.log calls within class methods to improve logging practices.
No install command available. Check the GitHub repository for manual installation instructions.
git clone https://github.com/ast-grep/agent-skillCopy the install command above and run it in your terminal.
Launch Claude Code, Cursor, or your preferred AI coding agent.
Use the prompt template or examples below to test the skill.
Adapt the skill to your specific use case and workflow.
Search the codebase in [DIRECTORY_PATH] for all instances where [AST_PATTERN] is used. Return the file paths, line numbers, and the exact code snippets for each match. Focus on [LANGUAGE] files and ignore test directories. Example AST pattern: 'function calls to `logger.error()` with a string literal as the first argument'.
I analyzed the `src/` directory in the `acme-payments` repository (Node.js codebase) for all instances where `try-catch` blocks contain a `console.error()` call with a string literal as the first argument. Here are the findings:
1. **File:** `src/services/payment-processor.js` (Line 42)
```javascript
try {
await processPayment(request);
} catch (error) {
console.error("Payment processing failed", error); // Match
}
```
2. **File:** `src/utils/logger.js` (Line 18)
```javascript
function logError(error) {
try {
throw error;
} catch (err) {
console.error("Error occurred:", err.message); // Match
}
}
```
3. **File:** `src/controllers/order-controller.js` (Line 89)
```javascript
try {
await validateOrder(order);
} catch (validationError) {
console.error("Invalid order data", validationError); // Match
}
```
**Summary:** Found 3 matches across 2 files. All instances follow the pattern of a `try-catch` block containing a `console.error()` call with a string literal as the first argument. This pattern is commonly used for error logging but may benefit from structured logging (e.g., using `winston` or `pino`) for better error tracking in production environments.
**Recommendation:** Consider refactoring these to use a centralized logging utility to ensure consistent error formatting and metadata inclusion.Your one-stop shop for church and ministry supplies.
Automate your browser workflows effortlessly
IronCalc is a spreadsheet engine and ecosystem
Customer feedback management made simple
Enterprise workflow automation and service management platform
Automate your spreadsheet tasks with AI power
Take a free 3-minute scan and get personalized AI skill recommendations.
Take free scan