Inspiration
Dead JavaScript bloats bundles, slows load times, and increases maintenance. Static analysis misses conditionally executed code. We needed a way to find truly unused code by exercising the UI—so we built CodeReaper.
What it does
CodeReaper is an MCP tool for Cursor that finds and removes dead JavaScript. It launches an AI browser agent (powered by Gemini 3) that autonomously explores websites—clicking buttons, navigating routes, opening modals, filling forms, and triggering shortcuts. While the agent explores, V8 precise coverage tracks which functions execute. Functions with zero executions are flagged as dead-code candidates with risk scores and removal recommendations.
How we built it
CodeReaper uses Gemini 3 via the Index browser agent framework. The pipeline has three phases:
- Scanning: Launch Chromium with Playwright, enable V8 coverage via CDP, and run multiple exploration passes where Gemini 3 autonomously interacts with the UI.
- Analysis: Merge coverage across passes, identify zero-execution functions, resolve source maps, and calculate risk scores (LOW/MEDIUM/HIGH).
- Patching: Generate unified diffs with safety modes (conservative/balanced/aggressive), apply patches with rollback snapshots, and verify by replaying interactions to detect regressions.
Challenges we ran into
- Coverage accuracy: Ensuring V8 captures all execution paths required careful CDP session management and handling dynamic script loading.
- Agent exploration: Getting Gemini 3 to explore comprehensively without loops required prompt engineering and multi-pass strategies.
- Source mapping: Mapping script URLs to local file paths across various build configurations.
- MCP integration: Making the tool seamlessly available in Cursor with proper async handling across the browser automation stack.
Accomplishments that we're proud of
- V8 function-level coverage provides execution-based detection that static analysis can't match.
- Gemini 3 explores complex UIs without manual test cases, discovering interactions we wouldn't have thought to test.
- Risk scoring and verification replay give confidence when removing code, with rollback if issues arise.
- Successfully identified 31 dead functions (7KB reclaimable) in a test application.
What we learned
- AI agents enable autonomous UI exploration covering more scenarios than manual or scripted tests.
- Chrome DevTools Protocol provides precise function-level coverage beyond static analysis.
- Dead code removal needs careful risk assessment and verification to avoid breaking production.
- MCP enables powerful IDE integrations that feel native to developer workflows.
What's next for CodeReaper
- Multi-language support: Extend to TypeScript, Python, and other languages.
- CI/CD integration: GitHub Actions and GitLab CI plugins for dead code detection in PRs.
- Coverage visualization: Dashboard with coverage heatmaps and dead code hotspots.
- Smart suggestions: Use Gemini 3 to suggest refactoring beyond simple removal.
- Performance optimization: Incremental scanning and parallel exploration for large codebases.
Gemini Integration
CodeReaper uses Gemini 3 as the core intelligence for autonomous browser exploration via the Index browser agent framework. Gemini 3 drives Chromium to interact with websites like a human—clicking, filling forms, navigating routes, and triggering shortcuts. Its reasoning capabilities understand page structure, identify interactive elements, and decide what to explore next across multiple passes, maximizing V8 coverage.
Without Gemini 3, CodeReaper would require manual test writing or brittle scripted interactions. Gemini 3's ability to reason about UI structure and adapt to different layouts makes CodeReaper a truly intelligent dead code detection tool that works across diverse web applications without configuration.
Log in or sign up for Devpost to join the conversation.