Skip to content

Set budget and detail

The budget covers the complete output, including paths, code fences, escaping, and format framing. ContextCraft starts from available tiers and lowers detail until the serialized artifact fits the selected tokenizer's count.

Shell
contextcraft . --budget 8000 --encoding cl100k_base --stats -o context.md

cl100k_base is the default, with o200k_base also available. Both vocabularies are embedded in native code, and successful generation uses exact counts rather than estimated totals.

Choose a budget

Reserve space for your instructions, conversation, and expected model response before deciding how many tokens to allocate to repository context. The count is specific to the selected vocabulary, so changing the encoding can change both the selected content and the total.

A larger budget permits more detail without guaranteeing that every file receives FULL. --tier can cap the maximum detail, while a sufficiently small budget may also shorten the path listing. If even empty output framing cannot fit, generation returns BudgetTooSmall.

Limit detail

Use --tier to cap how much source a file can contribute:

Shell
contextcraft . --budget 4000 --tier sigs --stats -o interfaces.md

The cap sets the highest allowed tier. Relevant files may still receive less when the budget is tight. See read the result for tier examples and how it works for allocation.

Count text from Python

Python
from contextcraft import TokenCounter

with TokenCounter("o200k_base") as counter:
    total = counter.count("your prompt here")
    counts = counter.count_batch(["hello", "world"])

Special-token markers are ordinary text, and strings are counted as UTF-8. See TokenCounter for the API.