← Work

zatsu

Tool Rust · tree-sitter View source

A fork of the single-file outline CLI zat, extended into a deterministic code-outline tool for taking a rough look at a whole repository's structure and public symbols.

I built zatsu, a fork of zat — a CLI that outlines a single file’s code — extended to work on a whole repository. Give it a repo and it prints a compact, .gitignore-aware tree with an outline of each file’s public symbols.

Why I built it

zat is a nice tool: it uses tree-sitter to extract and outline a file’s public symbols — but it works on one file at a time. When you open an unfamiliar repository, what you want first is the whole picture: where things live and what public API they expose. Clicking through files in an editor is slow, and tree only shows you file names. So I forked zat and extended its outline view to cover an entire repository.

The other motivation is coding agents. When you hand an agent an overview of a repository, you want output that doesn’t shift between runs. zatsu is deterministic by design, so it works both for a human taking a rough look and as stable context for an agent.

What it does

  • Directory mode: a tree view where files in supported languages get a symbol outline (function signatures, struct fields, enum variants) with line numbers
  • File mode: an outline of a single file
  • .gitignore-aware traversal, with --max-depth / --max-lines to bound the output

Running it on zatsu’s own repository looks like this:

src/
├── lib.rs
│   ├── mod outline; // L1
│   ├── mod repository; // L2
│   └── fn lang_for_ext(ext: &str) -> Option<(Language, &'static str)> // L6-L70
├── outline.rs
│   ├── struct VisibleRange<'a> { // L12-L18
│   │       node: Node<'a>
│   │       start_byte: usize
│   │       ...
│   ├── fn write_outline(...) -> io::Result<()> // L41-L137
│   └── fn parse(source: &str, language: &Language) -> Option<Tree> // L150-L156
...

How it’s built

Written in Rust, with parsing delegated to tree-sitter. Per-language symbol extraction is defined in .scm query files, currently covering JavaScript / TypeScript / Rust / Python / Go / Java / C / C++ / C# / Swift / Kotlin / Haskell / Ruby / Markdown.

The tree-sitter outline engine and per-language queries come from the upstream zat; what zatsu adds is .gitignore-aware traversal, output limits, and deterministic whole-repository output.

Try it

brew install shohei81/tap/zatsu

Cargo and Nix work too. Then just run it in a repository:

zatsu .
zatsu --max-depth 2 --max-lines 100 .
zatsu src/lib.rs   # file mode

Source is at github.com/shohei81/zatsu (GPL-3.0 licensed).