## Article: KotlinLLM — Smart Macros for Kotlin/JVM
JetBrains Research has open-sourced **KotlinLLM**, an IntelliJ IDEA plugin for Kotlin/JVM projects that introduces a language feature called **Smart macros**. A Smart macro is essentially a regular Kotlin function call whose body is generated on-demand by an LLM rather than written manually. Instead of maintaining hand-written boilerplate or test doubles, developers describe what they want in natural language, and KotlinLLM produces the corresponding Kotlin code directly in the project.
The public API is intentionally minimal. The core functions are:
– `asLlm
– `mockLlm
For example, parsing semi-structured data can look like this:
“`kotlin
val issuesApiUrl: String = asLlm(repoInput, hint = “GitHub API URL: get all issues, including closed”)
val issues: List
“`
### The Runtime Loop
When a project runs with the KotlinLLM run configuration, the plugin performs the following steps:
1. Scans for `asLlm` and `mockLlm` calls.
2. Updates generated bootstrap, provider, parser, and mock files.
3. Launches the original run configuration under JDI (Java Debug Interface).
4. Registers breakpoints on generated “regenerate” hooks.
5. If the generated logic does not match a runtime scenario, execution reaches a hook. The plugin captures runtime values and type information, sends them to an LLM agent, and applies a code update.
6. The plugin compiles the update and redefines the loaded class before retrying the original call.
KotlinLLM targets Kotlin/JVM specifically because this runtime evolution loop depends on JVM class redefinition via JDI.
### How a Smart Macro Evolves
Smart macros begin as LLM-generated stubs. As the application runs, the plugin observes real inputs and outputs. When a scenario is not covered, the developer can trigger regeneration, and the LLM proposes an updated implementation. Over time, the macro evolves from a simple placeholder into robust, production-grade Kotlin code.
### Reported Results
In an adapted Spring Petclinic Kotlin project with 18 `asLlm` call sites:
– All 24 application scenarios completed successfully.
– Hot-reload success rate was 100%.
– Compilation and redefinition added roughly 1% runtime overhead.
– A synthetic “GitHub Beginner Issue Radar” parsing 30,000+ issues across 20 repositories achieved about 0.89 recall on beginner-level labels.
### Setup Requirements
To use KotlinLLM, you need:
– IntelliJ IDEA 2025.2.x
– JDK 21
– An OpenAI API key stored in the target project’s `.kotlinllm` file via **Tools > KotlinLLM Settings**
The project is released under the Apache License 2.0 and includes runnable examples, a thesis write-up, and a KotlinConf 2026 talk recording.
### Is It Deployable?
KotlinLLM is currently a **research prototype**, labeled as an experimental IntelliJ IDEA plugin. However, its output is deployable: once behavior has been generated, the target project can compile and run that behavior without the plugin or any further LLM calls. The generated code is stored as ordinary Kotlin source, ready for review, testing, and integration.
Ideal users today include:
– R&D groups and platform teams in mid-size to large Kotlin/JVM organizations
– Startups with tolerance for prototype tooling
– Industries such as fintech, e-commerce, logistics, and developer tooling
Applications include normalizing API responses, creating evolving test doubles, adapting to schema drift, and classifying noisy text fields.
### Key Takeaways
– KotlinLLM is a JetBrains Research prototype, not yet a production runtime.
– Smart macros generate Kotlin source that is committed, reviewed, and executed without the plugin.
– Covered scenarios trigger no additional LLM calls, so there is no added latency or cost.
– The Petclinic evaluation showed 24/24 scenarios passing with ~1% overhead.
– The project is Apache 2.0 licensed and targets Kotlin/JVM on IntelliJ IDEA 202.2.x + JDK 21.
—
## FAQ
**What is KotlinLLM?**
KotlinLLM is an open-source IntelliJ IDEA plugin for Kotlin/JVM that uses LLMs to generate Smart macro code at runtime. These macros start as placeholders and evolve into concrete Kotlin functions based on observed usage.
**What is a Smart macro?**
A Smart macro is a Kotlin function call whose body is generated by an LLM. It behaves like regular Kotlin code after generation and can be committed, reviewed, and executed without the plugin.
**How does the runtime loop work?**
The plugin scans for macro calls, updates generated code, runs the program under JDI, and registers breakpoints on regeneration hooks. When a scenario is uncovered, runtime values are captured, sent to an LLM, and the macro is regenerated and reloaded.
**Which languages and platforms does KotlinLLM support?**
It supports Kotlin/JVM only, because runtime class redefinition depends on JVM capabilities via JDI.
**Do covered scenarios incur LLM costs?**
No. Once a macro has been generated for a scenario, it executes as plain Kotlin with no further LLM calls, latency, or cost.
**What are the prerequisites?**
IntelliJ IDEA 2025.2.x, JDK 21, and an OpenAI API key stored in a `.kotlinllm` file via Tools > KotlinLLM Settings.
**Is KotlinLLM production-ready?**
Not yet. JetBrains labels it a research prototype. However, the generated output is deployable as ordinary Kotlin source code.
**Which industries can benefit?**
Fintech, banking, developer tooling, e-commerce, logistics, and any team that parses semi-structured or third-party API data.
—
## Conclusion
KotlinLLM represents an innovative step toward integrating LLMs into the development lifecycle in a safe, inspectable way. By generating and evolving Kotlin code from minimal LLM interactions, it reduces repetitive coding and accelerates adaptation to changing schemas. While still a research prototype, its ability to produce production-ready Kotlin that runs without ongoing model dependencies makes it a promising tool for Kotlin/JVM teams looking to experiment with AI-assisted development. As with any prototype, cautious adoption with thorough code review is recommended, especially in regulated environments.



