Platform

AST-aware code chunking with tree-sitter

Updated 3 min read

SeaShell chunks code by parsing it. Using tree-sitter, it emits 1 chunk per right-sized declaration, a function, class, or method, and falls back to line windows only for the gaps between them. The result is that a search hit is a complete unit of code with a name, instead of 40 lines that happen to start and end in the middle of two different functions.

What fixed line windows get wrong

Splitting a file every 40 lines is 1 rule applied to code that does not follow it. Boundaries land mid-function, so a single function becomes 2 partial chunks and neither one contains the whole behavior a query is looking for.

The damage shows up as retrieval that is technically correct and practically useless. A search matches the half of a function containing the keyword, and the half containing the logic that answers the question sits in an adjacent chunk that did not score high enough to be returned. You get a citation to a fragment and have to go read the file anyway.

Parsing instead of counting

SeaShell runs tree-sitter over a file and emits 1 chunk per declaration that is a sensible size, naming each chunk after the symbol it contains. A 200-line class and a 6-line helper each become their own unit rather than being cut to a common length.

Because the boundaries follow the language's own structure, a retrieved chunk is something a developer would recognize as a thing: this function, that class. That makes results readable on their own, and it makes the symbol name available as an additional signal for both ranking and display.

The fallback that keeps coverage complete

Not everything in a file sits inside a declaration. Imports, top-level constants, and configuration blocks are line-windowed instead, so AST chunking adds structure where structure exists without leaving the other 100 percent of the file unindexed.

This is why the fallback matters as much as the parser. A purely AST-based index quietly drops whatever the grammar does not model, and the omissions are invisible until a search for a constant returns nothing. Covering the gaps means the index never regresses against a simpler approach.

Frequently asked questions

How does SeaShell split code for indexing?
SeaShell uses tree-sitter to emit one chunk per declaration, such as a function, class, or method, and line-windows the gaps between declarations.
Why is AST chunking better than fixed line windows?
Line windows cut through the middle of functions, so a match often lands in a fragment. AST chunks are complete, named units of code.
Does anything in a file go unindexed?
No. Code outside declarations, such as imports and top-level constants, is covered by a line-window fallback.
Do chunks keep the symbol name?
Yes. Each declaration chunk is named after the symbol it contains, which makes results identifiable and gives ranking an extra signal.

Try SeaShell in your terminal

The terminal-native AI coding agent. Free core, single binary.

Install SeaShell

Related guides

Atlas with OpenAI o3-pro in 2026

Explore OpenAI o3-pro with Atlas in 2026. This model offers a 200K context window and enhanced reasoning for complex coding tasks, balancing cost and capability for developers.

Atlas with Kimi K2.6 in 2026

Explore Atlas with Kimi K2.6, a general-purpose reasoning model from Moonshot AI. Ideal for mixed workloads, it offers a 256K token context window and competitive pricing for developers in 2026.

Atlas with NVIDIA Nemotron 3 Nano 30B A3B in 2026

Drive Atlas with NVIDIA Nemotron 3 Nano 30B A3B in 2026. This 3B-active model offers low latency and cost, with context windows up to 1,048,576 tokens, ideal for coding tasks.

Atlas with IBM Granite 4.1 8B in 2026

Explore Atlas with IBM Granite 4.1 8B, an 8B open-weights model ideal for enterprise code generation and large file rewrites. Benefit from its 131,072 token context window and cost-effective output pricing.

Atlas for Flutter in 2026

Discover Atlas for Flutter in 2026. This terminal-native AI coding agent helps Flutter developers build apps faster and safer, integrating with widgets, state, and the Dart toolchain.

Atlas for FastAPI in 2026

Atlas is a terminal-native AI coding agent for FastAPI in 2026. It reads Pydantic v2 models and Depends(), then runs pytest behind a permission prompt.

Atlas for Polars: Terminal-Native AI Coding in 2026

Atlas is a terminal-native AI coding agent for Polars. Build LazyFrame chains, push scan_csv predicates into the reader, and read explain() plans in 2026.

Atlas with Command R in 2026

In 2026, Atlas developers leverage Command R for cost-effective, retrieval-augmented coding. With a 128K token context and $0.15/Mtok input, it excels in background tasks and tool use.

Browse this resource hub