Skip to content

Quality Analysis

CodexA provides a full code quality pipeline with metrics tracking, hotspot detection, impact analysis, and CI-ready quality gates.

Quality Analysis

Run a comprehensive scan with:

bash
codex quality src/
codex quality --json            # JSON output
codex quality --safety-only     # Security-only (fast)

What Gets Analyzed

CategoryToolDescription
ComplexityRadonCyclomatic complexity per function
SecurityBanditCommon vulnerability patterns
Dead CodeBuilt-inUnused functions, unreachable code
DuplicationBuilt-inCopy-paste detection
MaintainabilityBuilt-inComposite MI score (0–100)

Maintainability Index

A per-file and project-wide score (0–100) based on:

  • Lines of code — penalizes overly large files
  • Cyclomatic complexity — penalizes deeply nested logic
  • Comment ratio — rewards well-documented code
MI RangeRating
65–100Good (easy to maintain)
40–64Moderate
0–39Poor (difficult to maintain)

Hotspot Detection

Find the riskiest code in your project:

bash
codex hotspots
codex hotspots --top-n 10 --json
codex hotspots --no-git       # Skip git churn data

Risk Factors

FactorWeightSource
Complexity0.30Cyclomatic complexity
Duplication0.20Duplicate line density
Fan-in0.15Number of callers
Fan-out0.15Number of callees
Churn0.20Git change frequency

When git data is unavailable, churn weight is redistributed across the other factors.

Impact Analysis

Predict the blast radius of changes:

bash
codex impact parse_file          # Analyze a function
codex impact src/parser.py       # Analyze a file
codex impact MyClass --max-depth 3 --json

Impact analysis uses BFS over the call graph and dependency map to find:

  • Direct dependents — Functions that call the target
  • Transitive dependents — Functions affected indirectly
  • Affected modules — Files that import the target
  • Dependency chains — Full paths from target to affected code

Symbol Trace

Trace execution flow through the codebase:

bash
codex trace parse_file
codex trace MyClass.process --json

Shows upstream callers and downstream callees to map how execution flows.

Track quality over time:

bash
codex metrics                  # Current metrics
codex metrics --snapshot       # Save a snapshot
codex metrics --history 10     # Last 10 snapshots
codex metrics --trend          # Direction analysis

Trends report: improving, stable, or degrading for each metric.

Quality Gates

Enforce quality policies in CI:

bash
codex gate --strict            # Exit code 1 on failure
codex gate --min-maintainability 60 --max-complexity 15
PolicyDefaultDescription
min_maintainability40.0Minimum MI score
max_complexity25Maximum cyclomatic complexity
max_issues20Maximum total issues
max_dead_code15Maximum dead code symbols
max_duplicates10Maximum duplicate pairs
require_safety_passtrueSafety check must pass

CI Integration

Generate CI workflow templates:

bash
codex ci-gen analysis           # Full analysis workflow
codex ci-gen safety             # Lightweight safety-only
codex ci-gen precommit          # Pre-commit hook config

Plugin Hooks

Quality analysis fires these hooks for customization:

HookWhen
PRE_HOTSPOT_ANALYSISBefore hotspot scoring
POST_HOTSPOT_ANALYSISAfter hotspot report
PRE_IMPACT_ANALYSISBefore impact BFS
POST_IMPACT_ANALYSISAfter impact report
PRE_TRACEBefore symbol trace
POST_TRACEAfter trace result

Released under the MIT License.