clenzer

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.

Category
Visit Server

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.

npm version npm downloads License: ISC TypeScript MCP


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 — cleanse never 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:

  1. No unused imports — every import must be referenced in the file body
  2. No unused variables — variables must be read, not just declared
  3. Max function length: 60 lines — extract helpers if exceeded
  4. Max nesting depth: 4 — flatten with early returns
  5. Max file size: 600 lines — split large files into modules
  6. No duplicate code blocks — extract shared logic into utilities
  7. 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 registration
  • ts-morph — TypeScript AST analysis and safe code modification
  • zod — 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

Recommended Servers

playwright-mcp

playwright-mcp

A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.

Official
Featured
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.

Official
Featured
Local
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.

Official
Featured
Local
TypeScript
VeyraX MCP

VeyraX MCP

Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.

Official
Featured
Local
graphlit-mcp-server

graphlit-mcp-server

The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.

Official
Featured
TypeScript
Kagi MCP Server

Kagi MCP Server

An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.

Official
Featured
Python
E2B

E2B

Using MCP to run code via e2b.

Official
Featured
Neon Database

Neon Database

MCP server for interacting with Neon Management API and databases

Official
Featured
Exa Search

Exa Search

A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.

Official
Featured
Qdrant Server

Qdrant Server

This repository is an example of how to create a MCP server for Qdrant, a vector search engine.

Official
Featured