Optimize Codebase

Run Ruff-based optimization routines to reduce codebase complexity and remove dead code.

Updated Jan 21, 2026
One-click install
npx skills add https://github.com/Row0902/agents --skill optimize-codebase
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: Optimize Codebase
Source: https://github.com/Row0902/agents/tree/main/.agent/skills/optimize_codebase
Command: npx skills add https://github.com/Row0902/agents --skill optimize-codebase

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Codebases accumulate complexity and dead code over time, hindering maintainability and slowing development. This skill proactively reduces entropy by identifying hotspots, guiding refactors, and enforcing healthier type health.

Core Features & Use Cases

  • Complexity Scan: Detects cyclomatic complexity using Ruff (mccabe) or manual checks; if nesting > 3 levels, triggers refactor recommendations.
  • Dead Code Removal: Finds unused imports/variables and stale code; suggests removal or renaming to underscores.
  • Type Health: Spots Any usage and suggests TypedDict/Protocol alternatives for stricter typing.
  • Optimization Routine (Run this): Executes a routine to sort imports, fix formatting, and reassess complexity with Ruff.

Quick Start

Run the optimization routine to sort imports, fix formatting, and reduce complexity in your codebase.

Frequently Asked Questions about Optimize Codebase

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I reduce codebase complexity and remove dead code automatically?

To reduce codebase complexity and remove dead code, you can run an optimization routine that uses Ruff to detect unused imports, identify stale variables, and trigger refactor recommendations for deeply nested code blocks.

What is cyclomatic complexity and when do I need a refactor?

Cyclomatic complexity measures the number of linearly independent paths through code. You need a refactor when complexity checks identify nesting greater than three levels, which hinders maintainability and slows development.

How do I find and clean up unused imports and variables in my project?

To find and clean up unused imports and variables, run a dead code removal scan that detects stale code and suggests removal or renaming to underscores to proactively reduce entropy in the codebase.

How can I fix typing health issues and replace Any usage in Python?

To fix typing health issues and replace Any usage, run a type health analysis that spots loose typing and suggests stricter alternatives like TypedDict or Protocol for better codebase maintainability.

Can I use Ruff to sort imports and fix formatting in a legacy codebase?

Yes, you can use Ruff to sort imports and fix formatting in a legacy codebase by executing a defined optimization routine that automatically reassesses complexity after applying formatting fixes.

What is the best way to maintain an aging code repository with large imports?

The best way to maintain an aging code repository with large imports is to apply an automated optimization routine that enforces type health, prunes dead code, and reduces cyclomatic complexity.