CodeCommentRemover is a CLI tool that strips source-code comments & blocks from individual files or entire directory trees. It understands both line and block comment syntax, skips binary files automatically, and preserves sequences that appear inside strings or raw string literals. It also respects pre-existing file encodings/editor settings.
Author: Barrixar
CodeCommentRemover is available at: https://github.com/Barrixar/CodeCommentRemover
- Concurrent processing: Parallel file processing using Go 1.25's sync.WaitGroup.Go() for optimal performance
- Built-in language aliases: Predefined patterns for common languages (cpp, go, shell, doxygen, and more)
- Quote-aware parsing: Preserves comment-like sequences inside strings, raw strings, and backticks
- Binary detection: Automatically skips binary files to avoid corruption
- Informative output: Reports which files were updated and provides summary statistics
- Windows shell-friendly: Clear documentation for quoting patterns on Windows
Requirements: Go 1.25 or later
Clone the repository and compile:
powershell go build -o CodeCommentRemover.exe CodeCommentRemover.go
This produces CodeCommentRemover.exe (or CodeCommentRemover on Unix-like systems).
CodeCommentRemover.exe [-workers=N] <pattern> <file-or-directory> CodeCommentRemover.exe [-workers=N] AliasMode <alias> [file-or-directory]
-
- A comma-separated list of comment definitions:
- Line prefixes: //, #, etc.
- Block patterns: /|/, /**|*/ (use start|end format)
- Windows users: Quote patterns containing special characters: "/|/"
-
- Target file or folder (processes recursively for directories)
-
AliasMode - Use a predefined language pattern (see Built-in Aliases below)
- Optional path argument (defaults to current directory if omitted)
- -workers=N - Max files to process concurrently (default: GOMAXPROCS)
Aliases are case-insensitive and expand to the patterns shown:
| Alias | Pattern | Description |
|---|---|---|
| standard | // | Single-line comments starting with // |
| �lock | /* | */ |
| doxygen | //,/** | /,/ |
| cpp | //,/* | */ |
| c | //,/* | */ |
| csharp | //,/* | */ |
| go | //,/* | */ |
| ypescript | //,/* | */ |
| shell | # | Shell script comments |
| hash | # | Hash-style comments (same as shell) |
Remove C++ comments from a directory:
powershell CodeCommentRemover.exe AliasMode cpp C:\path\to\project
Remove Doxygen comments from current directory:
powershell CodeCommentRemover.exe AliasMode doxygen .
Remove C-style block comments (Windows - note the quotes):
powershell CodeCommentRemover.exe "/*|*/" C:\path\to\file.c
Remove both // and # comments:
powershell CodeCommentRemover.exe "//,#" C:\path\to\src
Remove line comments only:
powershell CodeCommentRemover.exe "//" C:\path\to\project
When files are updated:
Updated C:\path\to\file1.cpp Updated C:\path\to\file2.cpp Completed: 2 file(s) updated, 3 file(s) unchanged.
When no changes are needed:
No changes needed. Checked 5 file(s), no comments matched the pattern.
- Binary files (containing null bytes) are automatically skipped
- Only files with matching comments are modified
- File encoding/your editor's settings are universally respected (Not modified). CodeCommentRemover won't mess with it.
- Line endings (CRLF/LF) are preserved
- File permissions aren't modified
Nothing can or will go wrong with your file or its properties, but as usual, make a backup just in case.
- Comments inside strings ("...", '...',
...) are preserved - Escape sequences are handled correctly
- Shebang lines (#!/...) are always preserved, even when # is targeted
- Files are processed concurrently for maximum speed
- Default concurrency matches GOMAXPROCS (typically CPU count)
- Use -workers flag to adjust parallelism for I/O-bound workloads
- Patterns are automatically deduplicated
- Block patterns are processed before line patterns
- Partial line comments (trailing //) are trimmed while preserving code
This tool requires Go 1.25 or later and uses modern features including:
- sync.WaitGroup.Go() for cleaner goroutine management
- strings.SplitSeq() for efficient string iteration
- slices and maps standard library packages
- cmp.Or() for value defaulting
The test suite is still under development and will be added later. The codebase was matured over a course of weeks, and saw a lot of personal use bebfore publishing it. I have accounted for all edge-cases and niche requirements that i could think of, but suggestions and PR's are very much welcome!
Don't be surprised to see low activity after initial publishing, because the codebase is already very polished and stable. I don't tend to skate one night's ice.
See LICENSE file for details.