We’re Chonkie (https://github.com/chonkie-inc/chonkie) — we build open source tools that help split documents into meaningful chunks for use with AI models.
When you use LLMs over large documents or codebases, you often need to break them into smaller parts to fit the model’s context window. Our chunkers do this in a smart way: they preserve structure and meaning, so only the most relevant pieces are passed into the model. This reduces hallucinations, avoids confusion, and improves performance and accuracy.
Today we’re launching our Code Chunker — a fast, structure-aware way to break down source code into high-quality, token-aware chunks.
How it works:
(See the code: https://github.com/chonkie-inc/chonkie/blob/main/src/chonkie...)
Code Chunker uses tree-sitter (https://tree-sitter.github.io/tree-sitter/) to parse your code into an abstract syntax tree (AST). It then recursively merges and groups nodes in a way that respects both code structure and token limits.
It supports all languages that tree-sitter supports, and is designed to preserve formatting and semantics. Large functions or class definitions won’t be split in the middle of a block — instead, we dive recursively into the AST to produce clean, coherent chunks that fit your configured token budget.
What it’s useful for:
- Embedding-based code search
- RAG (retrieval-augmented generation) over codebases
- Long-context analysis of code
- Preparing repos for fine-tuning or pretraining
Try it out: - Open source package: https://docs.chonkie.ai/chunkers/code-chunker
- Hosted playground (free with account): https://cloud.chonkie.ai
Happy Chonking!