Skip to main content
Tree-sitter provides bindings for multiple languages and platforms. Choose the installation method that matches your project’s needs.

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.
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.
1

Add Tree-sitter dependency

Add to your Cargo.toml:
2

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.
3

Import in your code

The Rust bindings require Rust version 1.90 or higher.

Features

The Rust bindings support optional features:
Available features:
  • std (enabled by default) - Allows Tree-sitter to use the standard library. Error types implement std::error::Error, regex performance optimizations are enabled, and DOT graph methods are available.
  • wasm - Enables Wasm language support using the wasmtime-c-api crate. Allows loading language grammars compiled to WebAssembly.

JavaScript/TypeScript (Web)

Use Tree-sitter in browser and Node.js environments with WebAssembly bindings.
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:
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.
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:
Expected output:

Next steps

Quick start

Parse your first code file with Tree-sitter

Using parsers

Learn to work with syntax trees and nodes