Expand description
Claude-compatible token counting.
WCGW counts tokens with the Xenova/claude-tokenizer (Hugging Face tokenizers).
We embed that same tokenizer definition in the binary and load it lazily, so token
budgets and truncation match the model that actually runs the agent. Small inputs
use a byte-length upper bound and never initialize it; if loading fails for a larger
input we fall back to a cheap character/word estimate.
Functions§
- budget_
from_ env - Read a token-budget override from env var
var(e.g.WINX_CODING_TOKEN_BUDGET), falling back todefaultwhen unset, zero, or unparseable. Lets large-context clients tune how much of each file is pulled into context — and how much saved memory is kept — without a rebuild. - count_
tokens - Count tokens the way Claude does. Falls back to
estimate_tokenson failure. - decode_
ids - Decode Claude token ids back into text. Returns
Noneon failure. - definitely_
fits_ token_ budget - Return
truewhen byte length alone provestextfits the token budget. - encode_
ids - Encode
textinto Claude token ids. ReturnsNoneif the tokenizer is unavailable so callers can pick a byte-based fallback. - estimate_
tokens - Cheap fallback estimate used only when the tokenizer is unavailable.