Add Anthropic Claude tokenizer support#52
Merged
dmitry-brazhenko merged 1 commit intodmitry-brazhenko:mainfrom Mar 25, 2026
Merged
Add Anthropic Claude tokenizer support#52dmitry-brazhenko merged 1 commit intodmitry-brazhenko:mainfrom
dmitry-brazhenko merged 1 commit intodmitry-brazhenko:mainfrom
Conversation
Add a new "claude" encoding based on Anthropic's official tokenizer data, enabling token counting and encoding/decoding for Claude models. - Convert and embed BPE vocabulary from Anthropic's @anthropic-ai/tokenizer package (~65K tokens) as claude.tiktoken - Add NFKC text normalization support to ModelParams and GptEncoding, matching Anthropic's tokenizer behavior - Add Claude model name mappings (claude-instant-1 through claude-4-sonnet) with prefix matching for dated variants - Reuse existing Regex50KBase pattern (identical to Claude's pat_str) - Add tests for roundtrip encoding, model mappings, NFKC normalization, and special token handling Note: This tokenizer is accurate for pre-Claude 3 models and serves as a rough approximation for Claude 3+, per Anthropic's documentation. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
dmitry-brazhenko
approved these changes
Mar 25, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #32
"claude"encoding based on Anthropic's official@anthropic-ai/tokenizerBPE vocabulary (~65K tokens)Regex50KBasepattern (identical to Claude'spat_str)Note: Per Anthropic's documentation, this tokenizer is accurate for pre-Claude 3 models and serves as a rough approximation for Claude 3+.
Usage
Test plan
🤖 Generated with Claude Code