Tree-sitter provides bindings for multiple languages and platforms. Choose the installation method that matches your project’s needs.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/tree-sitter/tree-sitter/llms.txt
Use this file to discover all available pages before exploring further.
CLI installation
The Tree-sitter CLI allows you to develop, test, and use Tree-sitter grammars from the command line. It works on macOS, Linux, and Windows.- Cargo
- npm
- Pre-built binary
Install using Rust’s package manager:The
--locked flag ensures you get the exact dependency versions that the CLI was tested with.The
tree-sitter binary itself has no dependencies, but specific commands have runtime requirements:- To generate a parser from a grammar, you must have Node.js on your PATH
- To run and test parsers, you must have a C and C++ compiler on your system
Rust bindings
Add Tree-sitter to your Rust project with a language grammar.Add a language grammar
Add a language parser you want to use:Available language packages include
tree-sitter-javascript, tree-sitter-python, tree-sitter-typescript, and many more on crates.io.Features
The Rust bindings support optional features:std(enabled by default) - Allows Tree-sitter to use the standard library. Error types implementstd::error::Error, regex performance optimizations are enabled, and DOT graph methods are available.wasm- Enables Wasm language support using thewasmtime-c-apicrate. Allows loading language grammars compiled to WebAssembly.
JavaScript/TypeScript (Web)
Use Tree-sitter in browser and Node.js environments with WebAssembly bindings.- npm
- Vite
- Deno
- Standalone script
Install the web-tree-sitter package:Then import in your code:Or with ES modules:
For CommonJS environments like Electron, use
web-tree-sitter.cjs instead of the ES6 module version.Installing language grammars
After installing web-tree-sitter, you need language grammar files compiled to WebAssembly:- From npm
- From GitHub releases
- Build with CLI
Install the language package:The
.wasm file will be in node_modules/tree-sitter-javascript/.Debug version
To use the debug version with symbols and assertions:C/C++ integration
Embed Tree-sitter directly in C or C++ applications.- Build from source
- Include in build system
Clone the repository and build:This creates:
- Static library:
libtree-sitter.a - Dynamic libraries (platform-specific)
Compiling with a language
To parse a specific language, include the language’s parser:When using dynamic linking, ensure the shared library is discoverable through
LD_LIBRARY_PATH or your system’s equivalent environment variable.Verify installation
After installation, verify that Tree-sitter is working:- CLI
- Rust
- JavaScript
Next steps
Quick start
Parse your first code file with Tree-sitter
Using parsers
Learn to work with syntax trees and nodes