What is tree-sitter-cli?
tree-sitter-cli is the command-line tool for developing Tree-sitter parsers. Tree-sitter is a parser generator and an incremental parsing library: it builds a concrete syntax tree for a source file and updates it cheaply as the file is edited, which is why Neovim, Helix, Zed and GitHub use it for highlighting, folding, text objects and code navigation. The CLI is how grammars get made: it scaffolds a grammar repository, generates a C parser from grammar.js, compiles it to a shared library or to WebAssembly, runs corpus tests, parses, queries, highlights and tags files, and serves a web playground. It is a single Rust binary, and the command you type is tree-sitter.
tree-sitter.json layout that tree-sitter init writes and the built-in QuickJS runtime behind --js-runtime native all arrived after the versions frozen into the archives. A grammar repository generated with a current CLI expects the same or newer on every contributor's machine and in CI. Debian stable's 0.22.6 and Ubuntu 24.04's 0.20.8 predate most of that, and upstream's own Linux binaries need glibc 2.39, so they do not even start on Debian 12 or Ubuntu 22.04.
⚡ Key Features of tree-sitter-cli
🧱 Grammar Repositories in One Command
tree-sitter init asks a few questions and writes grammar.js, tree-sitter.json and the binding and package files, so the grammar is ready to publish for Node.js, Python, Rust, Go, Swift and C from day one.
⚙️ Parser Generation
tree-sitter generate turns grammar.js into a dependency-free C parser in src/ and reports conflicts. It runs the grammar with node, or with the built-in QuickJS runtime via --js-runtime native.
🔨 Native and WebAssembly Builds
tree-sitter build compiles the parser into a shared library that editors load, and --wasm produces a .wasm module for web-tree-sitter and the playground.
🧪 Corpus Tests
tree-sitter test parses the examples under test/corpus, compares the trees with the expected S-expressions and runs highlight and tag tests too. --update rewrites the expectations after an intended change.
🔍 Parse, Query, Highlight, Tag
parse prints the syntax tree, query runs a .scm query and lists its captures, highlight renders to the terminal or to HTML, and tags extracts definitions and references.
🛝 Web Playground
tree-sitter playground serves a local page where you type code, watch the tree update as you edit and run queries against it, which is the fastest way to see why a rule does not match.
apt upgrade keeps you on the latest version.
📦 Installation from deb.griffo.io
Step 1: Add Repository
sudo install -d -m 0755 /etc/apt/keyrings
curl -fsSL https://deb.griffo.io/EA0F721D231FDD3A0A17B9AC7808B4DD62C41256.asc | sudo gpg --dearmor --yes -o /etc/apt/keyrings/deb.griffo.io.gpg
echo "deb [signed-by=/etc/apt/keyrings/deb.griffo.io.gpg] https://deb.griffo.io/apt $(lsb_release -sc 2>/dev/null) main" | sudo tee /etc/apt/sources.list.d/deb.griffo.io.list > /dev/null
sudo apt updateinstall -d -m 0755 /etc/apt/keyrings
curl -fsSL https://deb.griffo.io/EA0F721D231FDD3A0A17B9AC7808B4DD62C41256.asc | gpg --dearmor --yes -o /etc/apt/keyrings/deb.griffo.io.gpg
echo "deb [signed-by=/etc/apt/keyrings/deb.griffo.io.gpg] https://deb.griffo.io/apt $(lsb_release -sc 2>/dev/null) main" | tee /etc/apt/sources.list.d/deb.griffo.io.list > /dev/null
apt update🆓 There is an always-free mirror. deb-free.griffo.io serves packages free forever, no account, no subscription, at most 2 months behind upstream, security fixes immediately. It currently carries cliamp, Ghostty, lazydocker, Oh My Posh, Uncloud and Zed; tree-sitter-cli is not one of them, so the repository above is the only way to get it today, ask and it can be enrolled.
Step 2: Install tree-sitter-cli
# Install latest tree-sitter-cli
sudo apt install tree-sitter-cli
# Verify installation, the command is tree-sitter and not tree-sitter-cli
tree-sitter --version# Install latest tree-sitter-cli
apt install tree-sitter-cli
# Verify installation, the command is tree-sitter and not tree-sitter-cli
tree-sitter --versionStep 3: Create your first grammar
# The command is tree-sitter. Building and testing parsers needs a C compiler,
# and generate runs grammar.js with node unless you pick the built-in runtime
sudo apt install build-essential nodejs
# Scaffold a grammar repository, answering a few questions
mkdir tree-sitter-mylang && cd tree-sitter-mylang
tree-sitter init
# Generate the parser, compile it and run the corpus tests
tree-sitter generate
tree-sitter build
tree-sitter test
# bash, zsh, fish and nushell completions ship with the package
tree-sitter --help# The command is tree-sitter. Building and testing parsers needs a C compiler,
# and generate runs grammar.js with node unless you pick the built-in runtime
apt install build-essential nodejs
# Scaffold a grammar repository, answering a few questions
mkdir tree-sitter-mylang && cd tree-sitter-mylang
tree-sitter init
# Generate the parser, compile it and run the corpus tests
tree-sitter generate
tree-sitter build
tree-sitter test
# bash, zsh, fish and nushell completions ship with the package
tree-sitter --help🎯 Basic Usage Examples
Working on a grammar:
# Regenerate after each grammar.js change, without node, using the built-in QuickJS
tree-sitter generate --js-runtime native
# Run only the tests whose names match, then accept new output as the expectation
tree-sitter test --include 'function'
tree-sitter test --update
# Build a shared library, or a WebAssembly module for web-tree-sitter
tree-sitter build -o mylang.so
tree-sitter build --wasmParsing files:
# Print the syntax tree of a file
tree-sitter parse examples/hello.mylang
# Parse many files quietly and report how many succeeded
tree-sitter parse examples/*.mylang --quiet --stat
# Time a parse, useful when a grammar change slows things down
tree-sitter parse examples/big.mylang --timeQueries, highlighting and tags:
# Run a query against a file and list what it captures
tree-sitter query queries/highlights.scm examples/hello.mylang
# Highlight a file in the terminal, or render a standalone HTML page
tree-sitter highlight examples/hello.mylang
tree-sitter highlight --html examples/hello.mylang > hello.html
# Extract definitions and references with the tags query
tree-sitter tags examples/hello.mylangExisting grammars and the playground:
# Work on an existing grammar
git clone https://github.com/tree-sitter/tree-sitter-json
cd tree-sitter-json
tree-sitter generate && tree-sitter test
# Write a config file, then list your grammar checkouts under parser-directories
tree-sitter init-config
# Build to WebAssembly and open the interactive playground in a browser
tree-sitter build --wasm
tree-sitter playground🔧 Tool Integrations
The Tree-sitter CLI sits between a grammar and the tools that load it:
- Neovim: the main branch of nvim-treesitter compiles parsers with the
tree-sitterCLI and asks for a recent release, newer than Debian stable or Ubuntu LTS ship - Helix: highlighting, indents and text objects are Tree-sitter queries; check a change to
highlights.scmwithtree-sitter querybefore rebuilding grammars withhx --grammar build - Zed: language extensions pin a grammar repository and commit, so generate and test the grammar locally before bumping the pin
- CI:
tree-sitter generatefollowed bygit diff --exit-code src/fails a pull request whose committed parser is stale - Package registries: the bindings
tree-sitter initwrites let one grammar publish to npm, PyPI and crates.io
🚀 Why Choose deb.griffo.io?
- Official Ubuntu: ships tree-sitter-cli in universe, but 24.04 LTS carries 0.20.8, 26.04 is already behind upstream, and 22.04 has no package at all
- Upstream binary: current, but upstream's prebuilt Linux binaries are linked against glibc 2.39, so they do not start on Debian 12 or Ubuntu 22.04, and they live outside apt in
/usr/local/bin - cargo or npm:
cargo install tree-sitter-clineeds a Rust toolchain and a full compile on every upgrade, and the npm package downloads the same prebuilt binary with the same glibc requirement - deb.griffo.io: latest version with automatic updates
- ✅ Same Package, Newer Version: same name as Ubuntu's own
tree-sitter-cliand the same/usr/bin/tree-sitter, so apt treats it as an upgrade and not a second installation - ✅ Built From the Upstream Tag: compiled with cargo from the tagged upstream source on Ubuntu 22.04, because upstream's prebuilt Linux binaries require glibc 2.39; this one runs on every suite from Bookworm and Jammy up
- ✅ Automatic Updates: packages updated within hours of upstream releases
- ✅ Complete Package: the
tree-sitterbinary built from the upstream source tag, bash, zsh, fish and nushell completions, and no dependencies beyondlibc6andlibgcc-s1 - ✅ Four Architectures: amd64, arm64, armhf and i386, so the Raspberry Pi and the old 32-bit laptop get the same tree-sitter
- ✅ Multi-Distribution: works on Ubuntu 22.04, 24.04, 25.10 and 26.04
- ✅ Easy Maintenance: standard apt commands for updates
📦 Package Build Repository
The Ubuntu packages are automatically built and maintained in this GitHub repository:
- 🌲 tree-sitter-cli-debian - Latest release builds
🔗 Related Packages
Also available from deb.griffo.io:
- Neovim - nvim-treesitter builds its parsers with this CLI
- Helix - Editor whose highlighting and text objects are Tree-sitter queries
- Zed - Editor whose language extensions ship Tree-sitter grammars
- difftastic - Structural diff built on Tree-sitter parsers
💝 Support This Project
If this repository saves you time and effort, please consider supporting it!
