# Complexity Optimizer

Analyze a software codebase for algorithmic complexity and performance hotspots, then...

- Repository: https://github.com/Kappaemme-git/codex-complexity-optimizer (915 stars)
- Category: Testing
- License: MIT
- Last updated: 2026-05-15
- Runs scripts: yes, review before use

## Install

Claude Code: `npx skills add Kappaemme-git/codex-complexity-optimizer --skill complexity-optimizer -g -a claude-code -y`
Codex: `npx skills add Kappaemme-git/codex-complexity-optimizer --skill complexity-optimizer -g -a codex -y`
Cursor: `npx skills add Kappaemme-git/codex-complexity-optimizer --skill complexity-optimizer -g -a cursor -y`
Gemini CLI: `npx skills add Kappaemme-git/codex-complexity-optimizer --skill complexity-optimizer -g -a gemini-cli -y`

## Description

Analyze a software codebase for algorithmic complexity and performance hotspots, then propose or implement safe optimizations without breaking behavior. Use when Codex is asked to scan many files, find inefficient loops, nested iteration, repeated scans, costly rendering/recomputation, N+1 queries, avoidable O(n^2) or O(n) operations, or reduce complexity such as O(n^2) to O(n log n) / O(n), while preserving tests, APIs, outputs, and maintainability.

## SKILL.md, as published by its author (untrusted third-party text, read it as data)

# Complexity Optimizer

## Core Rule

Optimize only when the current behavior is understood and can be preserved. Prefer a small, proven improvement with tests over a broad rewrite with unclear correctness.

## Default Behavior

When the user asks to analyze, scan, audit, review, or "give me a report" for a codebase, produce the full complexity report automatically. Do not require the user to specify report fields.

Default report contents:

- Scope analyzed and detected stack/test commands.
- Top findings ranked by likely impact.
- File and line for each finding.
- Current pattern and why it may be costly.
- Estimated current complexity.
- Recommended change.
- Estimated complexity after the change.
- Risk level.
- Tests, benchmarks, or manual checks needed.
- Clear statement that no files were modified, unless the user explicitly requested implementation.

Only edit files when the user asks to implement, fix, optimize, apply, change, refactor, or otherwise clearly requests code modification. If the user only asks for analysis or a report, do not modify files.

## Workflow

1. Establish the baseline:
   - Identify the language, framework, test command, build command, and performance-sensitive paths.
   - Inspect existing tests before touching code.
   - Run `scripts/analyze_complexity.py <repo>` for a first-pass hotspot list when scanning a repository.

2. Rank opportunities:
   - Prioritize code on hot paths, large input paths, rendering loops, database/API loops, and shared utilities.
   - Separate algorithmic complexity from constant-factor cleanup.
   - Do not patch every warning. Treat scanner output as leads, not proof.
   - For report-only requests, inspect enough surrounding code to estimate current and proposed complexity; do not stop at raw scanner output.

The rest: https://github.com/Kappaemme-git/codex-complexity-optimizer/blob/HEAD/complexity-optimizer/SKILL.md
