Code Comment Extractor

Paste a source snippet and pull out line, block and documentation comments — or return the same code with comments stripped. Handles common comment syntaxes, ignores markers inside strings, and runs entirely in your browser.

Try:
Comments / stripped code

About this tool

Paste a source snippet and extract the comments as a plain list, JSON records, a Markdown table, or a statistics summary. You can also choose Source with comments removed to strip the matched comments while preserving newlines so code line numbers stay recognizable.

The scanner covers common comment syntaxes used by JavaScript, TypeScript, Python, Java, C#, C, C++, Go, Rust, PHP, Ruby, shell, SQL, HTML/XML, CSS, Lua and YAML-style files. It is string-aware, so //, /* */ and # inside ordinary strings, Go backtick strings, Rust raw strings and Python triple-quoted strings are not treated as comments.

Worked example

Input:

// File header
const url = "https://example.com//path"; // Real trailing comment
/* Multi-line
   block note */
console.log(url);

With language = javascript, output = comments, strip_markers = true, and line_numbers = true, the result is:

[L1] File header
[L2] Real trailing comment
[L3] Multi-line
block note

Use kind = doc to keep only documentation comments such as /** ... */, ///, //!, ## and Python docstrings. Use min_length to drop short noise comments before listing or stripping.

Limits and edge cases

This is a deterministic tokenizer, not a full language parser. Unterminated block comments run to the end of the input, shell here-doc bodies are not parsed as a separate grammar, and custom comment syntaxes are not configurable. Output is capped at 50,000 comments to keep browser and CLI runs bounded.

FAQ

Can it remove comments as well as list them?

Yes. Set output to stripped to return the original source with the selected comment kind removed. Newlines inside removed comments are kept so remaining code stays close to its original line numbers.

Will URLs or comment markers inside strings be extracted by mistake?

No for the supported string forms. The tokenizer skips quoted strings, character literals, JavaScript template strings, Go backtick strings and Rust raw strings before looking for comment openers, so "https://example.com//path" is left alone.

How does Python docstring handling work?

When docstrings is enabled, a triple-quoted Python string that starts its own line is classified as a documentation comment. Turn docstrings off if you only want real # comments from Python code.

Why not scan a whole repository?

This block runs in the browser and CLI on one pasted input at a time. Repository traversal, git revisions and per-file rollups belong in a filesystem-aware tool; this one focuses on a portable single-snippet workflow.

Developer & Automation Access

Run it from the terminal

Same engine as this page, headless — via the gizza CLI:

gizza tool code-comment-extractor "function total(items) {
  // Add every price.
  return items.reduce((sum, item) => sum + item.price, 0); /* cents */
}"

New to the CLI? Get gizza →

Open it by URL

Pre-fill and auto-run this tool with query parameters — the names match the API/CLI:

https://gizza.ai/tools/code-comment-extractor/?code=function%20total%28items%29%20%7B%0A%20%20%2F%2F%20Add%20every%20price.%0A%20%20return%20items.reduce%28%28sum%2C%20item%29%20%3D%3E%20sum%20%2B%20item.price%2C%200%29%3B%20%2F%2A%20cents%20%2A%2F%0A%7D&language=auto&output=comments&kind=all&strip_markers=true&line_numbers=true&min_length=0&docstrings=true

Machine-readable descriptor: tool.json — title + parameters JSON Schema for agents.