Skip to main content

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.

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:
cargo install --locked tree-sitter-cli
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:
[dependencies]
tree-sitter = "0.27"
2

Add a language grammar

Add a language parser you want to use:
[dependencies]
tree-sitter = "0.27"
tree-sitter-rust = "0.23"
Available language packages include tree-sitter-javascript, tree-sitter-python, tree-sitter-typescript, and many more on crates.io.
3

Import in your code

use tree_sitter::{Parser, Language};
The Rust bindings require Rust version 1.90 or higher.

Features

The Rust bindings support optional features:
[dependencies]
tree-sitter = "0.27"
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:
npm install web-tree-sitter
Then import in your code:
const { Parser } = require('web-tree-sitter');
await Parser.init();
Or with ES modules:
import { Parser } from 'web-tree-sitter';
await Parser.init();
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:
npm install tree-sitter-javascript
The .wasm file will be in node_modules/tree-sitter-javascript/.

Debug version

To use the debug version with symbols and assertions:
import { Parser } from 'web-tree-sitter/debug';

await Parser.init();

C/C++ integration

Embed Tree-sitter directly in C or C++ applications.
Clone the repository and build:
git clone https://github.com/tree-sitter/tree-sitter.git
cd tree-sitter
make
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:
clang \
  -I tree-sitter/lib/include \
  your-program.c \
  tree-sitter-json/src/parser.c \
  tree-sitter/libtree-sitter.a \
  -o your-program
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:
tree-sitter --version
Expected output:
tree-sitter 0.27.0

Next steps

Quick start

Parse your first code file with Tree-sitter

Using parsers

Learn to work with syntax trees and nodes