Command Palette

Search for a command to run...

Назад к скиллам
скилл № 63651

topiary

Universal code formatter leveraging Tree-sitter queries. Use when formatting code in languages without dedicated formatters, writing custom .scm query files…

БесплатноБез исполняемых скриптов
vinnie357от vinnie357★ 30 звёзд на GitHub

Установить topiary в Claude Code и Claude Desktop

Зарегайся, чтобы установить скилл

Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.

  • Открой команду установки в одну строку
  • Сохраняй скиллы в синхронизируемую библиотеку
  • Уведомления, когда скиллы обновляются
Зарегаться бесплатноУ меня уже есть аккаунт

Об этом скилле

Topiary

Topiary is a universal code formatter that uses Tree-sitter grammars and queries to define formatting rules. Rather than implementing language-specific formatting logic, Topiary uses declarative Tree-sitter query files (.scm) to specify how code should be formatted.

Key Concepts

Tree-Sitter Queries

Tree-sitter is a parser generator that creates language parsers from grammar definitions. Topiary uses Tree-sitter queries to analyze code structures and apply formatting rules. Queries match patterns in the syntax tree using S-expression syntax and decorate matched nodes with capture names (prefixed with @) that describe formatting actions.

Query Files and Capture Names

Language formatting is defined in .scm (Scheme) query files. Each capture name instructs Topiary how to format the matched node:

  • Line breaks: @prepend_hardline, @append_hardline (always insert newline), @prepend_empty_softline, @append_empty_softline (newline or nothing), @prepend_spaced_softline, @append_spaced_softline (newline or space)
  • Indentation: @prepend_indent_start, @append_indent_start, @prepend_indent_end, @append_indent_end (mark indentation scopes)
  • Spacing: @prepend_space, @append_space (add single space)
  • Control: @delete (remove matched node), @do_nothing (suppress default behavior), @leaf (prevent formatting within node)
  • Input-aware: @prepend_input_softline, @append_input_softline (preserve original line break presence)

Idempotency

Topiary formatting is idempotent—running the formatter repeatedly on already-formatted code produces identical output. This guarantee allows safe integration into version control hooks and CI pipelines.

Author Intent Preservation

Topiary respects the structural intent of code by preserving language-specific semantics. It focuses on whitespace, indentation, and line breaks rather than restructuring code. This approach works especially well with languages whose semantics are simple and whitespace-independent.

Installation

Via Mise

Add Topiary to your mise.toml:

[tools]
topiary = "latest"

[tasks]
fmt = "topiary fmt"
fmt:check = "topiary fmt --check"

Via Cargo

Install directly from crates.io:

cargo install topiary-cli

Verify Installation

Check the installed version and available languages:

topiary --version
topiary config show-sources

CLI Usage

Format Files

Format files in place by detected file extension:

topiary fmt src/main.ml
topiary fmt config.json
topiary fmt *.toml

Add --check to verify formatting without modifications:

topiary fmt --check src/

Format Standard Input

Format piped input by specifying language and optional query file:

echo '{"name":"example"}' | topiary format --language json
cat script.sh | topiary format --language bash

Visualize Parse Trees

Use visualise to debug queries by inspecting the syntax tree:

topiary visualise script.json
topiary visualise --language bash script.sh

This outputs the Tree-sitter parse tree, useful for understanding node structure when writing .scm queries.

Query Configuration

Override the default query file for a language:

topiary fmt --language nickel --query custom.scm script.ncl

Show Current Configuration

Display the active configuration including registered languages and indentation settings:

topiary config show-sources

Configuration

languages.ncl Format

Create a .topiary/languages.ncl file in your project root to customize language registration, indentation, and grammar sources. This file uses Nickel syntax:

{
  languages = {
    json = {
      extensions = ["json"],
      indent = "  ",
    },
    bash = {
      extensions = ["sh", "bash"],
      indent = "  ",
    }
  }
}

Configuration Search Order

Topiary searches for configuration in this order (first found wins):

  1. --configuration CLI argument
  2. .topiary/languages.ncl in current directory or parent directories
  3. User configuration directory (OS-specific): ~/.config/topiary/languages.ncl (Linux), ~/Library/Application Support/topiary/languages.ncl (macOS), %APPDATA%\topiary\languages.ncl (Windows)
  4. Built-in defaults compiled into Topiary

Custom Grammar Sources

Register custom Tree-sitter grammars by specifying Git source or local path:

{
  languages = {
    my-lang = {
      extensions = ["ml"],
      grammar.source.git = {
        git = "https://github.com/example/tree-sitter-my-lang",
        rev = "abc123def456"
      }
    }
  }
}

Or reference a pre-compiled grammar on disk:

{
  languages = {
    my-lang = {
      extensions = ["ml"],
      grammar.source.path = "./grammars/my-lang.so"
    }
  }
}

Adding Custom Languages

Add formatting support for new languages by following these steps:

Step 1: Register the Grammar

Cr

Полный SKILL.md на GitHub

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

Без ограничений — скилл может использовать любой инструмент.

Вложенные файлы

  • references/query-syntax.md
  • templates/languages.ncl

FAQ

Что делает скилл topiary?

Universal code formatter leveraging Tree-sitter queries. Use when formatting code in languages without dedicated formatters, writing custom .scm query files, or configuring Topiary via languages.ncl.

Как установить скилл topiary?

Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.

Скилл topiary запускает скрипты?

Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.

Похожие скиллы

Сравнить topiary с