tree-sitter

AST parsing, S-expression queries, tag extraction via tree-sitter CLI. Use when parsing code into AST, extracting tags, visualizing syntax trees, or performing structural analysis beyond ast-grep.

9 stars

Best use case

tree-sitter is best used when you need a repeatable AI agent workflow instead of a one-off prompt.

AST parsing, S-expression queries, tag extraction via tree-sitter CLI. Use when parsing code into AST, extracting tags, visualizing syntax trees, or performing structural analysis beyond ast-grep.

Teams using tree-sitter should expect a more consistent output, faster repeated execution, less prompt rewriting.

When to use this skill

  • You want a reusable workflow that can be run more than once with consistent structure.

When not to use this skill

  • You only need a quick one-off answer and do not need a reusable workflow.
  • You cannot install or maintain the underlying files, dependencies, or repository context.

Installation

Claude Code / Cursor / Codex

$curl -o ~/.claude/skills/tree-sitter/SKILL.md --create-dirs "https://raw.githubusercontent.com/ssiumha/dots/main/prompts/skills/tree-sitter/SKILL.md"

Manual Installation

  1. Download SKILL.md from GitHub
  2. Place it in .claude/skills/tree-sitter/SKILL.md inside your project
  3. Restart your AI agent — it will auto-discover the skill

How tree-sitter Compares

Feature / Agenttree-sitterStandard Approach
Platform SupportNot specifiedLimited / Varies
Context Awareness High Baseline
Installation ComplexityUnknownN/A

Frequently Asked Questions

What does this skill do?

AST parsing, S-expression queries, tag extraction via tree-sitter CLI. Use when parsing code into AST, extracting tags, visualizing syntax trees, or performing structural analysis beyond ast-grep.

Where can I find the source code?

You can find the source code on GitHub using the link provided at the top of the page.

SKILL.md Source

# tree-sitter CLI

tree-sitter CLI로 AST 덤프, S-expression 쿼리, 태그 추출을 수행합니다.

**핵심 철학**:
- ast-grep 우선: 검색/대체는 ast-grep, tree-sitter는 분석/이해 목적
- AST 시각화: 코드 구조를 트리로 확인하여 정확한 노드 타입 파악
- S-expression 쿼리: predicates로 정밀한 구조적 검색 (neovim query와 동일 문법)
- 태그 추출: 정의/참조를 구조적으로 추출 (ctags 대체)

## Prerequisites

```bash
tree-sitter dump-languages  # 사용 가능한 파서 목록
```

"not configured" 경고 시 → 워크플로우 1 실행.

## Instructions

### 워크플로우 1: Setup (on-demand 파서 설치)

`dump-languages` 출력에 언어가 없으면 grammar을 설치한다.

```bash
# 초기 설정 (1회)
tree-sitter init-config  # parser-directories: ["~/.local/share/tree-sitter/grammars"]

# 언어별 설치 (필요 시)
cd ~/.local/share/tree-sitter/grammars
git clone --depth 1 https://github.com/tree-sitter/tree-sitter-<언어>
# 일부 언어는 tree-sitter-grammars org: https://github.com/tree-sitter-grammars/tree-sitter-<언어>
```

### 워크플로우 2: Parse (AST 덤프)

쿼리 작성 전 노드 타입 파악에 필수.

```bash
tree-sitter parse --no-ranges file.py   # 간결한 AST
tree-sitter parse --cst file.py         # 정렬된 트리
tree-sitter parse --xml file.py         # XML 출력
tree-sitter parse --scope source.python file.txt  # 언어 지정
```

**출력 예시**:
```
(function_definition
  name: (identifier)
  parameters: (parameters (identifier) (identifier))
  body: (block (return_statement)))
```

노드 타입(`function_definition`)과 필드명(`name:`, `body:`)을 확인하여 query 패턴 작성에 사용.

### 워크플로우 3: Query (S-expression 쿼리)

S-expression 패턴으로 코드를 검색한다. `.scm` 파일에 작성 후 실행.

```scheme
;; queries/find-functions.scm
(function_definition
  name: (identifier) @func.name)
```

```bash
tree-sitter query queries/find-functions.scm file.py
tree-sitter query queries/find-functions.scm src/      # 디렉토리 전체
tree-sitter query --captures queries/q.scm file.py     # 캡처 순서 출력
tree-sitter query --row-range 10-50 queries/q.scm file.py  # 행 범위 제한
```

S-expression 쿼리 문법은 `resources/01-query-syntax.md` 참조.

### 워크플로우 4: Tags (태그 추출)

코드에서 정의(definition)와 참조(reference)를 추출한다.

```bash
tree-sitter tags file.py
tree-sitter tags src/     # 디렉토리 전체
```

## 중요 원칙

1. **Parse 먼저**: 쿼리 작성 전 반드시 `parse`로 노드 타입 확인
2. **쿼리 파일 사용**: `.scm` 파일 작성 (재사용, 가독성)
3. **언어별 노드 차이**: 같은 개념이라도 언어마다 노드 타입이 다름

## Examples

### AST 구조 파악
```
User: "이 Python 파일의 AST 구조 보여줘"
→ tree-sitter parse --no-ranges file.py → 노드 타입과 필드 구조 보고
```

### 복잡한 쿼리
```
User: "데코레이터가 붙은 async 함수만 찾아줘"
→ parse로 노드 타입 확인 → .scm 쿼리 작성 → tree-sitter query query.scm src/
```

## References

- S-expression 쿼리 문법: `resources/01-query-syntax.md`
- 공식 문서: https://tree-sitter.github.io/tree-sitter/
- Grammar 목록: https://github.com/tree-sitter
- 설정 파일: `~/.config/tree-sitter/config.json`
- Grammar 경로: `~/.local/share/tree-sitter/grammars/`

Related Skills

tidy

9
from ssiumha/dots

Performs small structural code cleanups (tidyings). Use when preparing code changes, removing dead code, reducing nesting, or cleaning up before feature work.

task-naming

9
from ssiumha/dots

CLI command naming convention for Justfile and Makefile. Enforces GAT (group-action-target) word order, grouped listing, mandatory descriptions. Use when creating Justfile recipes, Makefile targets, or reviewing task runner configs for naming consistency. Also use when asking "what should I name this command?" for task runners. Do NOT use for npm scripts, mise tasks, or Claude Code skill naming.

strategic-thinking

9
from ssiumha/dots

체계적 의사결정 프레임워크. First Principles, Trade-off 분석, Cognitive Bias 점검

security

9
from ssiumha/dots

Security expert hub. Code security review (OWASP Top 10, injection, XSS, credentials), vulnerability assessment (KISA 292 items, Unix/Windows server, web pentest, network, DBMS, cloud), ISMS-P certification (101 items, checklist, implementation plan), EFSR financial regulation compliance (전자금융감독규정, 12 articles). 보안 리뷰, 취약점 점검, 인증 준비, 금융규정 준수.

reflect

9
from ssiumha/dots

방향 수정 신호 감지 및 세션 전체 회고. Use when detecting course correction signals ("아니/잠깐/근데"), session retrospective, or reviewing overall progress. /reflect 또는 "회고해줘"로 수동 호출.

refactoring

9
from ssiumha/dots

기존 코드의 안전한 리팩토링. Characterization Test로 동작 보존하며 구조 개선

recall

9
from ssiumha/dots

Load context from Obsidian vault (journals, session pages) and JSONL session history. Vault 위치/구조는 `documentation` skill 참조. Temporal queries scan JSONL by date, topic queries use ir BM25. Use when "recall", "어제 뭐 했지", "what did we work on", "이전 작업", "session history".

qmd

9
from ssiumha/dots

Searches local markdown notes and documents using ir CLI. Use when searching notes, querying documents, managing collections, or retrieving document content.

qa

9
from ssiumha/dots

기능별 QA 체크리스트 생성, 수동 테스트 실행, 결과 기록. Use when QA 테스트, 체크리스트 만들기, 수동 검증, 기능 확인, qa 진행, checklist. Do NOT use for automated test code (use plan-review tdd / code-review instead) or BDD spec (use plan-review bdd instead).

principles

9
from ssiumha/dots

소프트웨어 공학 원칙 바스켓. 원칙 카탈로그 열람, 코드/설계/프로세스/테스트의 원칙 준수도 평가, 위반 식별 및 개선 가이드. Use when 원칙 평가, 원칙 점검, 원칙 검증, principles check, 코드 품질 근본 진단, 설계 원칙 리뷰, 아키텍처 원칙 점검, 프로세스 원칙 점검, 테스트 원칙 점검, 테스트 설계, or when other review skills need a principled foundation. Do NOT use for specific code review (use code-review), security audit (use security), or strategic decisions (use strategic-thinking).

ppt

9
from ssiumha/dots

Generates PowerPoint architecture diagrams with auto-layout and orthogonal routing using PPTXGenJS. Use when creating AWS architecture diagrams, infrastructure layouts, system design slides, IDC 구성도, or any diagram that needs boxes with right-angle connectors in .pptx format. Also use when 아키텍처 다이어그램, 인프라 구성도, PPT 생성, 구성도 만들기, 슬라이드 자동 생성. Do NOT use for simple text-only presentations (use PowerPoint directly), data charts (use data-investigation), or ASCII/Mermaid diagrams (use diagram skill).

plan-review

9
from ssiumha/dots

Reviews execution plans for scope, codebase validity, risk, and completeness before implementation. Use when reviewing a plan, 계획 리뷰, 계획 검증, checking plan quality before execution, or "리뷰해줘" after plan mode. Includes TDD, BDD, DDD methodology domains.