Watch: compact code for AI
No sound. Each step is captioned on screen and also written out in the guide below.
AI Tools
Send code to ChatGPT, Claude, or Gemini in fewer tokens. Remove comments and docstrings, or keep only the signatures, and see exactly what you saved.
Strings are never changed. The language is detected from the code or the file name.
Your compacted code will appear here.
Paste code to compact it.
| Code | o200k_base GPT-5, GPT-4.1, GPT-4o | cl100k_base GPT-4, GPT-3.5 | Saved |
|---|
Exact counts with OpenAI's tokenizers. For Claude and Gemini estimates, use the AI Token Counter.
No sound. Each step is captioned on screen and also written out in the guide below.
A file, a function, or several files one after another.
Remove comments for code the AI should edit. Keep only signatures to show it the shape of a codebase.
See the tokens before and after, then paste it into your prompt.
// @ts-ignore or # type: ignore, are kept.{ … } (or ... in Python); types, classes, and signatures stay.Comment-heavy code, like Python with docstrings, often shrinks by a third or more. Signatures alone are often 60–85% smaller.
With comments, docstrings, blank lines, and spaces removed, yes: only text the language ignores is removed, and strings are never changed. A Python body left empty by a removed docstring gets pass. "Signatures only" is for reading, not running: function bodies are replaced.
When the AI needs to know what exists (classes, functions, their parameters and types) but not how each one works. For example, to plan a change across files, or to write code that calls them.
Tokenizers already pack runs of spaces and line breaks into very few tokens. Removing them makes code shorter to read, but saves little. Comments and function bodies are where the tokens are.
JavaScript, TypeScript, Python, Java, Kotlin, C, C++, C#, Go, Rust, Swift, PHP, Ruby, shell, SQL, CSS, HTML, and YAML. "Signatures only" works for the languages with braces, and for Python.
No. Compacting and counting tokens both run in your browser.