Skip to content

Refuse exact token claims for Claude under tiktoken cl100k - #5

Open
AshSgDe29071999 wants to merge 1 commit into
AgentPostmortem:mainfrom
AshSgDe29071999:fix/tiktoken-claude-approximate
Open

Refuse exact token claims for Claude under tiktoken cl100k#5
AshSgDe29071999 wants to merge 1 commit into
AgentPostmortem:mainfrom
AshSgDe29071999:fix/tiktoken-claude-approximate

Conversation

@AshSgDe29071999

Copy link
Copy Markdown

Summary

TiktokenTokenizer defaults to OpenAI cl100k_base. Using it on Claude Code sessions produced a number labelled as if it were exact for the wrong tokenizer.

  • token_accuracy is exact only for OpenAI chat / Codex under tiktoken:cl100k_base
  • Claude Code (and heuristic) are approximate, with an accuracy_note
  • Terminal shows (approximate) and a note; CLI warns on stderr
  • Tokenizer name remains tiktoken:cl100k_base (encoding is traceable)
  • README table documents accuracy per tokenizer × source format

Test plan

  • pytest with tiktoken extra
  • Claude + tiktoken → token_accuracy=approximate + warning
  • OpenAI/Codex + tiktoken → exact

Fixes #3

tiktoken defaults to OpenAI's cl100k_base encoding. That is exact for
OpenAI/Codex transcripts and only approximate for Claude Code. Surface
token_accuracy and accuracy_note in analysis/JSON, label the terminal
tokenizer when approximate, warn on the CLI, and document per-format
accuracy in the README. Tokenizer name always includes the encoding id.

Fixes AgentPostmortem#3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

tiktoken cl100k is used to count Claude Code sessions, which is precise about the wrong number

1 participant