Count Tokens in Code
Code is not prose: symbols, indentation, and punctuation push it to more tokens per character. This counts a real snippet so the difference is visible.
Overview
Pasting a file into a model costs more than its character count suggests, because code tokenizes denser than prose — every brace, semicolon, and indent is tokens. This loads a real JavaScript function, detects it as code, and applies the denser ratio, so the estimate reflects what the model will actually see. If you budget code context as if it were prose, you will undercount; this tool counts it as code.
Workflow
-
Paste the code
A snippet, file, or diff — detected as code automatically.
-
Get the dense ratio
Symbols and indentation push tokens per character up.
-
Budget honestly
Use the code-aware count, not a prose approximation.
Why This Works
- Content-type detection flags code and applies a denser ratio
- Symbols, indentation, and punctuation are counted, not ignored
- The estimate reflects what the model actually tokenizes
Best for
- Budgeting code pasted into a model
- Estimating context for a codebase prompt
- Anyone undercounting code as if it were prose
Not for
- Optimizing the SQL itself — that's the SQL Optimization Prompt
- Fitting a whole repo into context — use the Context Window Estimator
Use cases
- Budgeting code pasted into a model
- Estimating context for a codebase prompt
- Anyone undercounting code as if it were prose