Provides inlay indicators based on a customizable complexity calculation for Java and Kotlin files.
This plugin is based on the original CodeMetrics by Tamas Kisst (MIT License) and has been extended to support Kotlin with updated UI compatibility for modern IntelliJ versions.
The plugin calculates cyclomatic complexity by parsing the AST and walking through each node, displaying scores inline with customizable thresholds and color coding.
- Real-time cyclomatic complexity calculation for Java and Kotlin
- Inline complexity hints in the editor with color-coded severity
- AI-powered refactoring suggestions via Claude, OpenAI, Gemini, or Codex (ChatGPT OAuth)
- Project-wide complexity analysis tool window with batch refactoring support
- Refactoring diff viewer with side-by-side comparison and one-click apply
- Customizable thresholds and colors with automatic validation
- Click on hints to see detailed breakdowns
- Full Kotlin K2 compiler mode support
- Supports classes, methods, control flow statements, properties, and lambda expressions
- Granular Kotlin visibility controls - toggle metrics for individual constructs (if, when, for, while, try, properties)
- Specialized handling for Kotlin constructs (Elvis operator, when expressions, etc.)
- Robust error handling with user-friendly validation messages
- Using IDE built-in plugin system: Settings/Preferences > Plugins > Marketplace > Search for "CodeMetrics With Kotlin" > Install
Settings/Preferences > Code Metrics With Kotlin to customize:
- Complexity thresholds for different colors (low/normal/high/extreme)
- Which elements to measure (methods, classes, lambda expressions, properties)
- Granular Kotlin visibility controls (classes, functions, properties, lambdas, if/when/for/while/try)
- Calculation weights for different constructs
- Kotlin-specific settings (Elvis operator, when expressions)
Note: The plugin automatically validates configuration to prevent invalid threshold combinations.
Settings/Preferences > Code Metrics With Kotlin > AI Refactoring tab:
- Provider: Choose from Claude, OpenAI, Gemini, or Codex (ChatGPT OAuth login)
- Credentials:
- Claude, OpenAI, and Gemini use API keys stored securely via IntelliJ PasswordSafe.
- Codex uses ChatGPT OAuth login; stored OAuth tokens are kept in IntelliJ PasswordSafe. If browser automation is unavailable, the OAuth flow prompts for the callback URL.
- Model: Select model per provider (editable dropdown with current defaults)
- Claude defaults to
claude-opus-4-7; OpenAI defaults togpt-5.5; Gemini defaults togemini-3-pro-preview; Codex defaults togpt-5.3-codex.
- Claude defaults to
- Custom Prompt: Add custom instructions appended to the auto-generated prompt
- Provider parameters:
- OpenAI / Codex reasoning effort: none / minimal / low / medium / high / xhigh (unsupported levels are omitted or normalized per selected model)
- OpenAI text verbosity for GPT-5 models: low / medium / high
- Claude effort: default / low / medium / high / xhigh / max
- Gemini thinking level for Gemini 3 models: default / minimal / low / medium / high (Gemini 3 Pro sends low/high only; unsupported lower levels are normalized)
- Inline Hints: Complexity scores appear as inlay hints next to methods and classes
- Tool Window: Access project-wide complexity analysis via View > Tool Windows > CodeMetrics
- Sortable by complexity score
- Click to navigate to code
- Suggest Refactoring for single methods, Batch Refactoring for multiple
- AI Refactoring: Right-click on a complexity hint > Suggest AI Refactoring, or use the lightbulb (Alt+Enter) on complex methods
- Interactive: Click on any complexity hint to see detailed breakdown
- Configuration: Fine-tune visibility, thresholds, and AI provider settings
- IntelliJ IDEA 2024.3+
- Kotlin K1 and K2 compiler modes
- Java and Kotlin languages
The complexity-test-samples/ directory is a standalone Gradle project with comprehensive test cases:
- Java: Simple to extreme complexity (1-25+), lambda expressions, anonymous classes, nested conditions
- Kotlin: when/if/for/while/try expressions, Elvis operator, properties, sealed classes
Open complexity-test-samples as a separate project in IntelliJ IDEA to test the plugin.
Contributions are welcome! Please see CONTRIBUTING.md for guidelines.
Prerequisites:
- Java 17+ (required for building)
- Java 21 recommended for Gradle JVM to avoid validation warnings with newer JDK versions
Quick start:
git clone https://github.com/YOUR_USERNAME/codemetrics-idea.git
cd codemetrics-idea
./gradlew runIdeSee CONTRIBUTING.md for full setup instructions and development tips.
Licensed under the MIT License.
./gradlew build./gradlew runIdeMaintainer release steps are tracked in CONTRIBUTING.md.

