website/client/src/en/guide/code-compress.md
Code compression is a powerful feature that intelligently extracts essential code structures while removing implementation details. This is particularly useful for reducing token count while maintaining important structural information about your codebase.
[!NOTE]
This is an experimental feature that we'll be actively improving based on user feedback and real-world usage
Enable code compression using the --compress flag:
repomix --compress
You can also use it with remote repositories:
repomix --remote user/repo --compress
The compression algorithm processes code using tree-sitter parsing to extract and preserve essential structural elements while removing implementation details.
The compression preserves:
While removing:
Original TypeScript code:
import { ShoppingItem } from './shopping-item';
/**
* Calculate the total price of shopping items
*/
const calculateTotal = (
items: ShoppingItem[]
) => {
let total = 0;
for (const item of items) {
total += item.price * item.quantity;
}
return total;
}
// Shopping item interface
interface Item {
name: string;
price: number;
quantity: number;
}
After compression:
import { ShoppingItem } from './shopping-item';
⋮----
/**
* Calculate the total price of shopping items
*/
const calculateTotal = (
items: ShoppingItem[]
) => {
⋮----
// Shopping item interface
interface Item {
name: string;
price: number;
quantity: number;
}
You can enable compression in your configuration file:
{
"output": {
"compress": true
}
}
Code compression is particularly useful when:
You can combine compression with other options:
--remove-comments: Remove code comments (see Comment Removal)--remove-empty-lines: Remove empty lines--output-show-line-numbers: Add line numbers to outputoutput.compress in your config file