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.

The tags command runs symbol tagging on an arbitrary file and outputs a list of tags. This is useful for code navigation features.
tree-sitter tags [OPTIONS] [PATHS]...
For more information, see Code Navigation - Tagging and Captures.

Input Sources

File Paths

Pass file paths directly:
tree-sitter tags example.js

Paths File

Use --paths to provide a file containing paths:
tree-sitter tags --paths file-list.txt

Standard Input

If no paths are provided, input is read from stdin:
echo "function hello() {}" | tree-sitter tags --scope source.js

Output Format

The command outputs tags in a format suitable for code navigation tools. Each tag includes:
  • Symbol name
  • Symbol kind (e.g., function, class, variable)
  • Location (file, line, column)
  • Scope information

Options

Input Options

--paths
file
The path to a file that contains paths to source files to tag.
-p, --grammar-path
path
The path to the directory containing the grammar. Implies --rebuild.
--scope
scope
The language scope to use for symbol tagging. Useful when the language is ambiguous.
-n, --test-number
number
Generate tags from the contents of a specific test.

Output Options

-q, --quiet
flag
Suppress main output.
-t, --time
flag
Print the time taken to generate tags for the file.

Build Options

-r, --rebuild
flag
Force a rebuild of the parser before running tags.
--config-path
path
The path to an alternative configuration (config.json) file. See init-config.

Examples

Generate Tags for a File

tree-sitter tags example.js

Generate Tags for Multiple Files

tree-sitter tags src/**/*.js

Generate Tags with Performance Measurement

tree-sitter tags --time example.js

Generate Tags from File List

tree-sitter tags --paths file-list.txt

Generate Tags with Specific Scope

tree-sitter tags --scope source.typescript example.ts

Tag Queries

Tags are generated using the queries/tags.scm query file in your grammar repository. This file defines patterns for extracting symbols. Example tag query:
(function_declaration
  name: (identifier) @name) @definition.function

(class_declaration
  name: (type_identifier) @name) @definition.class
For more information on writing tag queries, see the Code Navigation documentation.