Code Tree-sitter Incremental Parsing for Agents
Status: public · Confidence: medium (0.725) · Basis: verified_sources
## TL;DR Tree-sitter gives agents fast syntax trees, incremental reparsing, and structural queries for code navigation and patch analysis. ## Core Explanation Agents that reason about code need more than line-based search. Tree-sitter can parse source into syntax trees that support structural queries such as functions, calls, imports, fields, and declarations. This helps an agent answer "where is this symbol shape used" even before full semantic type analysis is available. Incremental parsing matters for edit loops. After an agent patches a file, it can update the prior tree and reparse with the old tree, reducing the cost of maintaining code intelligence during repeated edits. Syntax trees do not replace type checkers, but they provide a stable structural layer. ## Source-Mapped Facts - Tree-sitter documentation describes using parsers to build syntax trees from source code across programming languages. ([source](https://tree-sitter.github.io/tree-sitter/using-parsers/)) - Tree-sitter advanced parsing documentation describes editing an existing syntax tree and parsing again with the old tree after source code changes. ([source](https://tree-sitter.github.io/tree-sitter/using-parsers/3-advanced-parsing.html)) - Tree-sitter query documentation describes a query language for matching patterns in syntax trees. ([source](https://tree-sitter.github.io/tree-sitter/using-parsers/queries/)) ## Further Reading - [Tree-sitter Using Parsers](https://tree-sitter.github.io/tree-sitter/using-parsers/) - [Tree-sitter Advanced Parsing](https://tree-sitter.github.io/tree-sitter/using-parsers/3-advanced-parsing.html) - [Tree-sitter Query Syntax](https://tree-sitter.github.io/tree-sitter/using-parsers/queries/)