Code Token Counter
Estimates the tokens in pasted code or in source files you load, with tokens per line and bytes per token broken down by file extension.
Nothing is uploaded. Your source is read with FileReader inside this tab and never leaves it — there is no server call on this page, and the text is kept out of the URL as well, so the link you share carries your settings and not your content.
1 file, 17 lines, 709 bytes. Sending this once at $3.00 per 1M costs $0.00064.
- Files
- 1
- Lines
- 17
- UTF-8 bytes
- 709
- Estimated tokens, as written
- 212
- Estimated tokens, comments stripped
- 164
- Comments and blank lines
- 48 tokens (22.6%)
- Tokens per line
- 12.47
- Bytes per token
- 3.34
- Cost to send once
- $0.00064
Estimated, not tokenized. Token figures here come from an approximation running in your browser: no tokenizer vocabulary is downloaded, because a real one is megabytes and nothing on this page fetches anything. It imitates how a byte-level BPE splits text — words, digit groups, punctuation runs, whitespace runs — but it has no merge table, so treat it as a planning number. The authoritative count is the usage object on a real API response.
Density in the files you loaded
| Extension | Files | Est. tokens | Tokens / line | Bytes / token | |
|---|---|---|---|---|---|
| .ts | 1 | 212 | 12.47 | 3.34 |
These are your files, not a published table of language densities. Two repositories in the same language will not agree, which is the reason this measures yours instead of quoting someone else's.
// and /* … */ comments, # comments, -- comments and HTML comments by shape, so it will also remove a double slash that lives inside a string or a URL, such as the one in an https:// link. Treat the stripped figure as a floor on what you would save, not a promise. Files over 1 MB and anything past the first 200 selected are skipped. Language is guessed from the extension only.Code is denser in tokens than prose and the reason is visible in the pre-tokenizer. Every bracket, dot, colon and arrow is its own piece before any merging happens, camelCase and snake_case identifiers split into their parts, and indentation is charged for on every line. Where English lands near four characters per token, source files usually land lower — the bytes-per-token figure above is the one to watch, and it is measured on your files rather than assumed.
That matters because "paste the file into the prompt" is the default move in every AI coding workflow, and it is where budgets go. A 200-line module is not 200 units of anything; it is a few thousand tokens, and the same file included in twenty agent steps is that number twenty times. This is also the argument for sending a symbol outline or a diff rather than whole files: the token count is the thing that scales, and it scales with what you paste, not with what changed.
The comment toggle exists to settle an argument, not to recommend anything. Stripping comments does save real tokens, and the number above tells you how many. It also removes exactly the part of the file that explains why the code is the way it is — which is the part a model most needs when you are asking it to change something safely. Strip comments when you are asking for a mechanical transformation over a lot of files; keep them when you are asking for judgement. And if the saving turns out to be six percent, that is your answer: the expensive thing was never the comments.