clenzer
Enables CLI agents to detect and remove dead code, manage complexity, and enforce hygiene rules in TypeScript/JavaScript projects through tools like scanning, cleansing, and reporting.
README
clenzer
MCP server that hunts dead code and complexity — then cleanses it.
Add it to any CLI agent and your codebase stays lean on every session.
What it does
clenzer is a Model Context Protocol (MCP) server that plugs into any MCP-compatible CLI agent (Claude Code, Antigravity, Cursor, etc.) and gives it five new tools:
| Tool | Description |
|---|---|
register_rules |
Writes hygiene rules into AGENTS.md / CLAUDE.md so the agent re-enforces them every session |
scan_dead_code |
Finds unused imports, unused variables, and exported functions with no cross-file references |
scan_complexity |
Flags long functions, deep nesting, large files, and duplicate code blocks |
cleanse |
Safely auto-removes dead imports and side-effect-free variables; flags riskier items for manual review |
report |
Token-efficient summary of all findings with prioritised action items |
Design principles
- Token-efficient — compact output, no JSON blobs, grouped by file
- Safe —
cleansenever removes code with potential side effects; it skips functions and anything with call expressions in initialisers - Non-destructive — dry-run mode available; skipped items are always explained
- Zero config — works on any TS/JS project with or without
tsconfig.json
Installation
Via npx (no install needed)
npx clenzer
Global install
npm install -g clenzer
Local project install
npm install --save-dev clenzer
Adding to your CLI agent
Claude Code / Antigravity CLI
Add to your mcp_config.json (usually ~/.gemini/antigravity/mcp_config.json or ~/.claude/mcp_config.json):
{
"mcpServers": {
"clenzer": {
"command": "npx",
"args": ["-y", "clenzer"],
"env": {}
}
}
}
Or if installed globally:
{
"mcpServers": {
"clenzer": {
"command": "clenzer",
"args": [],
"env": {}
}
}
}
Cursor / other MCP hosts
Add the same block to your MCP host's server config. Refer to your host's documentation for the exact file location.
Usage
Once clenzer is connected to your agent, use natural language or call the tools directly.
Recommended workflow
1. register_rules — run once per project to lock in hygiene rules
2. scan_dead_code — before any significant editing session
3. scan_complexity — identify hotspots
4. report — get a prioritised action list
5. cleanse — auto-remove safe dead code
Tool reference
register_rules
project_root: string # absolute path to project root
Appends clenzer's hygiene rules to AGENTS.md (or CLAUDE.md if it exists). The agent will re-read this file every session, ensuring the rules are always active.
scan_dead_code
project_root: string # required
include?: string[] # glob patterns, default: all TS/JS files
exclude?: string[] # glob patterns, default: node_modules, dist, tests
Reports unused imports, unused variables, and exported functions with no cross-file references. Results are stored in session state for use by cleanse.
scan_complexity
project_root: string # required
include?: string[]
exclude?: string[]
Thresholds (all configurable via future config file):
- Function length > 60 lines →
long-function - Nesting depth > 4 →
deep-nesting - File size > 600 lines →
large-file - Duplicate block ≥ 6 lines →
duplicate-block
cleanse
project_root: string # required
dry_run?: boolean # default: false
Auto-removes items safe to delete (unused imports, variables with no side effects). Skips functions, exports, and anything with call expressions in the initialiser — those are flagged for manual review.
report
project_root: string # required
top_n?: number # default: 5 — how many issues to surface per category
Returns a compact markdown summary with dead code counts by kind, high-severity complexity hotspots, and recommended next steps.
Hygiene rules enforced
When you run register_rules, the following are appended to your AGENTS.md:
- No unused imports — every import must be referenced in the file body
- No unused variables — variables must be read, not just declared
- Max function length: 60 lines — extract helpers if exceeded
- Max nesting depth: 4 — flatten with early returns
- Max file size: 600 lines — split large files into modules
- No duplicate code blocks — extract shared logic into utilities
- Prefix intentionally unused variables with
_— clenzer skips them
Development
git clone https://github.com/Parth3930/clenzer.git
cd clenzer
npm install
npm run build # compile TypeScript → dist/
npm run dev # run with tsx (no compile step)
Project structure
src/
├── index.ts # MCP server, all 5 tools
├── scanner.ts # AST-based dead code + complexity analysis (ts-morph)
├── cleanser.ts # Safe removal engine
├── rules.ts # AGENTS.md / CLAUDE.md rule injection
└── types.ts # Shared interfaces
Tech stack
@modelcontextprotocol/sdk— MCP server transport and tool registrationts-morph— TypeScript AST analysis and safe code modificationzod— Runtime schema validation for tool inputs
Keywords
mcp, mcp-server, dead-code, unused-imports, code-cleanup, refactor, typescript, javascript, code-quality, static-analysis, ast, ts-morph, claude-code, cursor, antigravity, model-context-protocol, linter, cleaner, unused-variables, complexity
License
ISC © Parth3930
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。