Interactive CLI tool to find and selectively remove console statements from your codebase.
Think git add -p but for cleaning up debug logs.
# Run directly with npx
npx console-clean
# Or install globally
npm install -g console-clean
# Or install as dev dependency
npm install --save-dev console-cleanScan your codebase and interactively select which console statements to remove:
console-clean
# or
console-clean ./srcThis will:
- Scan all JS/TS files
- Show each console statement with context
- Let you choose: Remove, Keep, Remove all of type, etc.
- Preview changes before applying
List all console statements without removing them:
# Table output
console-clean scan
# JSON output (for CI/tooling)
console-clean scan --json
# Scan specific directory
console-clean scan --path ./srcRemove all console statements without interaction:
# Remove all (with confirmation)
console-clean clean
# Skip confirmation
console-clean clean --force
# Dry run (show what would be removed)
console-clean clean --dry-runCreate a config file in your project root:
{
"include": ["src/**/*", "lib/**/*"],
"exclude": ["**/*.test.*", "**/*.spec.*"],
"types": ["log", "debug", "info"],
"keep": ["error", "warn"],
"respectGitignore": true,
"ignoreComments": ["console-clean-ignore", "keep-console"]
}export default {
include: ['src/**/*'],
exclude: ['**/*.test.*'],
types: ['log', 'debug'],
keep: ['error', 'warn'],
};{
"consoleclean": {
"types": ["log", "debug"],
"keep": ["error", "warn"]
}
}Mark console statements to preserve:
// console-clean-ignore
console.log('This will be skipped');
console.log('This too'); // console-clean-ignore
/* console-clean-ignore */
console.warn('Block comment works too');--path, -p- Directory to scan (default:.)--config, -c- Path to config file
--no-preview- Skip diff preview before applying
--json- Output as JSON
--force, -f- Skip confirmation prompt--dry-run- Show changes without applying
# Interactive mode in src directory
console-clean ./src
# Scan and output JSON
console-clean scan --json > console-report.json
# Remove all console.log and console.debug (keep errors/warnings)
console-clean clean
# Dry run to preview changes
console-clean clean --dry-run
# Force remove without confirmation
console-clean clean --force- Scanner: Uses
fast-globto find JS/TS files, respects.gitignore - Parser: Uses Babel to parse files and detect console statements
- Modifier: Uses
magic-stringfor surgical removal without breaking code - Interactive: Uses inquirer for smooth terminal UI
- ✓ Detects all console.* methods (log, warn, error, info, debug, etc.)
- ✓ Interactive selection with context preview
- ✓ Safe removal preserving code structure
- ✓ Respects .gitignore patterns
- ✓ Supports ignore comments
- ✓ TypeScript and JSX support
- ✓ Dry run mode
- ✓ JSON output for CI/tooling
All standard console methods:
log,warn,error,info,debug,tracetable,dir,group,groupEnd,groupCollapsedtime,timeEnd,timeLogassert,count,countResetclear,profile,profileEnd
MIT
Nabil Benhamou
Issues and PRs welcome at https://github.com/thebiltheory/console-clean