.ai/guidelines.md
This file provides guidance for AI agents working with code in this repository.
This is the Kotlin programming language repository containing:
Note: The IntelliJ Kotlin plugin is in a separate repository (JetBrains/intellij-community).
# Generate test sources (run after adding new test data files)
./gradlew generateTests
*Generated.java test files directly - regenerate them with generateTests Gradle taskBEFORE running tests, modifying, or investigating code — identify the area and READ its docs.
| Area | Prefixes | Location | Docs |
|---|---|---|---|
| Analysis API | Ka*, KaFir*, LL* | analysis/ | AGENTS.md |
| Backend: JVM | compiler/ir/backend.jvm/ | AGENTS.md | |
| Backend: JS | compiler/ir/backend.js/ | AGENTS.md | |
| Backend: Native | kotlin-native/ | AGENTS.md | |
| Backend: WASM | compiler/ir/backend.wasm/ | AGENTS.md | |
| Compiler plugins | plugins/ | — | |
| FIR (K2 frontend) | Fir* | compiler/fir/ | AGENTS.md |
| FIR Analysis Tests | compiler/fir/analysis-tests/ | AGENTS.md | |
| IR | Ir* | compiler/ir/ | AGENTS.md |
| K1 (legacy frontend) | compiler/frontend/ | — | |
| Kotlin Gradle Plugin | libraries/tools/kotlin-gradle-plugin/ | AGENTS.md | |
| Kotlin Gradle Plugin API | libraries/tools/kotlin-gradle-plugin-api/ | AGENTS.md | |
| KGP Integration Tests | libraries/tools/kotlin-gradle-plugin-integration-tests/ | AGENTS.md | |
| PSI | Kt* | compiler/psi/ | AGENTS.md |
| Standard library | libraries/stdlib/ | — | |
| Test infrastructure | compiler/test-infrastructure/, compiler/tests-common-new/ | testing.md |
Adding new area docs: Create
AGENTS.mdwith content andCLAUDE.mdcontaining only@AGENTS.md
MANDATORY: First check the Areas table above — some areas have specialized test tooling.
Use -q (quiet) flag to reduce output noise. Example of commands for areas WITHOUT specialized tooling:
# Run a specific test class
./gradlew :compiler:test --tests "org.jetbrains.kotlin.codegen.BlackBoxCodegenTestGenerated" -q
# Run a specific test method
./gradlew :compiler:test --tests "org.jetbrains.kotlin.codegen.BlackBoxCodegenTestGenerated.testSomeTest"
# Run FIR compiler tests
./gradlew :compiler:fir:fir2ir:test --tests "org.jetbrains.kotlin.test.runners.ir.FirLightTreeJvmIrTextTestGenerated"
# Update test data files (when format changes)
./gradlew :compiler:test --tests "TestClassName" -Pkotlin.test.update.test.data=true --continue
BEFORE creating any commit, you MUST read docs/code_authoring_and_core_review.md — it contains essential rules for commit messages, code review process, and MR structure.
Key points (not exhaustive):
^KT-XXXXX Fixed in body to auto-close issuesNEVER use these tools: Grep, Glob, Read, Edit, Write, Task(Explore).
ALWAYS use JetBrains MCP equivalents instead.
Exception: for paths outside the project (e.g., ~/.claude/), use standard tools — MCP only works with project-relative paths.
NEVER use execute_terminal_command tool.
ALWAYS use default Bash instead.
Use other similar tools only if it is not possible to use the JetBrains IDE MCP, and you together with the user can't manage to make it work.
Synchronization with IDE:
Read sees the old disk version, while MCP sees current IDE bufferWrite/Edit may conflict with IDE's buffer or not be picked up immediatelyIDE capabilities:
search_in_files_by_text uses IntelliJ indexes — faster than grep on large codebasesrename_refactoring understands code structure and updates all references correctlyget_symbol_info provides type info, documentation, and declarationsget_file_problems runs IntelliJ inspections beyond syntax checkingThe JetBrains IDE MCP server can be called as jetbrains, idea, my-idea, my-idea-dev, etc.
If there are many options for the JetBrains IDE MCP server, ask the user what MCP server to use.
| Instead of | Use JetBrains MCP |
|---|---|
Read | get_file_text_by_path |
Edit, Write | replace_text_in_file, create_new_file |
Grep | search_in_files_by_text, search_in_files_by_regex |
Glob | find_files_by_name_keyword, find_files_by_glob |
Task(Explore) | list_directory_tree, search_in_files_by_text |
get_symbol_info, get_file_problems for understanding coderename_refactoring for symbol renaming (safer than text replacement)get_run_configurations() to discover, or execute_run_configuration(name="...") if name is knownUse JetBrains MCP get_file_problems with errorsOnly=false to check files for warnings. FIX any warnings related to the code changes made. You may ignore unrelated warnings.