DevTools Logo

Code Comment Remover

Code Comment Remover

Strip comments from JS, TS, CSS, Python or SQL while strings, regexes and formatting stay intact.

Runs in your browser
Try an example

Code with comments

Cleaned code

no output

No cleaned code yet

Paste code above or load an example.

Examples

URL in a string

Input
const url = "https://example.com"; // note
Output
const url = "https://example.com";

A regex-only stripper would corrupt the URL; the scanner treats it as a string.

License banner

Input
/*! @license MIT */ const x = 1; /* note */
Output
/*! @license MIT */ const x = 1;

License comments survive by default and are removed only when keep-license is off.

SQL quote escaping

Input
SELECT 'it''s -- fine' FROM t; -- note
Output
SELECT 'it''s -- fine' FROM t;

The doubled quote keeps the string open until its real terminator.

About this tool

Code Comment Remover strips comments from JavaScript, TypeScript, CSS, Python and SQL without rewriting your code. A small state machine per language tracks strings, template literals, regex literals and quoting rules, so a URL inside a string or a hash inside a Python literal is never mistaken for a comment.

Options cover the practical details: keep license banners such as /*! and @license, collapse the blank lines left behind, trim trailing whitespace and remove Python docstrings. A unified-lite diff view shows exactly what changed, and a verifier compares brace, parenthesis and quote balance before and after to warn when an unusual construct may have confused the scanner.

This is extraction, not compression. Nothing is renamed, reformatted or minified, and no source leaves the browser tab. It is designed for trimming snippets for AI context windows, exercise skeletons and shareable code samples.

What this tool does not do

  • Not a syntax validator; malformed input is handled best-effort.
  • Template-literal ${} expressions are not parsed as full JavaScript sub-programs.
  • SQL q'[…]' quote constructs are not supported.
  • No minification, renaming or whitespace collapsing beyond the explicit options.

How to use this tool

  1. Pick a language

    Choose JS/TS, CSS, Python or SQL manually, or use auto-detect and override the badge if it guesses wrong.

  2. Set removal options

    Keep license banners by default; enable docstring removal, blank-line collapse or trailing-space trimming as needed.

  3. Review the output

    Check the counts and any verifier warning, then switch to diff view to see precisely which lines changed.

  4. Copy or download

    Copy the cleaned code or save it with the matching file extension.

Use cases

LLM context prep

Remove explanatory comments to fit more code into a prompt without changing behavior.

Exercise skeletons

Hand students code without the internal notes embedded in the original.

Sharing snippets

Post a clean sample in issues or chat without leaking TODO notes.

Comment syntax per language

LanguageLine comment
JS / TS//
CSSnone
Python#
SQL--

A verifier flags changed brace, parenthesis or quote balance after stripping.

Common mistakes

Mistake:Using a regex such as //.* on JavaScript.

Fix:It deletes https:// inside strings and comment-like text in regex literals.

Mistake:Expecting minification.

Fix:Formatting and identifiers are preserved; use a minifier for size reduction.

Mistake:Removing a license banner by accident.

Fix:Keep-license is on by default; check the option before stripping.

Mistake:Ignoring a verifier warning.

Fix:It means a construct may be unsupported; inspect the diff before using the output.

Frequently asked questions

Why not just use a regex?

A regex like //.* cannot tell code from a URL inside a string, a regex literal such as /https?:\/\//, or a comment marker inside a CSS string. The tool uses a per-language scanner that tracks strings and quoting states, so code outside comments stays byte-for-byte intact.

Does it keep license headers?

Yes. Comments starting with /*!, or containing @license or @preserve, are preserved by default. Turn off the keep-license option if you really want them removed.

What happens to blank lines after removal?

By default the newline that ended a line comment stays, so line positions remain close to the original. Turn on collapse blank lines to squeeze runs of empty lines down to one.

Is my code uploaded?

No. Scanning, options, diff generation and download all happen in your browser tab. Nothing is sent to a server.

Does it minify code?

No. Identifiers, whitespace inside lines and formatting are untouched. The tool removes comments only; use a minifier if smaller output is your goal.

What if the scanner is unsure?

A verifier compares brace, parenthesis and quote balance before and after. If any invariant changes, it shows a warning and you can inspect the diff before copying the result.

References & standards