JetBrains Open-Sources KotlinLLM: Smart Macros That Generate Kotlin Source Code at Runtime and Hot-Reload It Through JDI

Disclosure: Some links in this article are affiliate links. AI Maestro may earn a commission if you make a purchase, at no…

By Vane July 31, 2026 3 min read
JetBrains Open-Sources KotlinLLM: Smart Macros That Generate Kotlin Source Code at Runtime and Hot-Reload It Through JDI

JetBrains Research has open-sourced KotlinLLM, an IntelliJ IDEA plugin designed for Kotlin/JVM projects. It introduces a language feature called Smart macros, which are standard function calls that generate Kotlin code at runtime. The public API is minimal. The asLlm function converts an input of type F into a typed value T, such as a data class or list. The mockLlm function creates a stateful implementation of an interface T, where the behaviour depends on which methods are invoked.

Consider this example where a developer defines a function call to fetch issues from a GitHub API:

val issuesApiUrl: String = asLlm(repoInput, hint = "GitHub API URL: get all issues, including closed")
val issues: List<Issue> = asLlm(response, hint = "Return all beginner-friendly issues for this repository")

The runtime loop

When a project launches via the KotlinLLM run configuration, the plugin scans for asLlm and mockLlm calls. It updates the generated bootstrap, provider, parser, or mock files and launches the run configuration under JDI. The system registers breakpoints on generated regenerate hooks. If the generated logic does not match a runtime scenario, execution hits a hook. The plugin captures runtime values and type information from the suspended frame. The LLM agent submits a code update, the plugin compiles it, and redefines the loaded class before retrying the original call.

KotlinLLM targets Kotlin/JVM specifically because the runtime evolution loop depends on JVM class redefinition through JDI.

Explainer: how a Smart macro evolves

The embedded video walks through the macro API, animates the nine-step runtime loop, and models why covered scenarios stop costing inference calls.

Reported results

Testing on an adapted Spring Petclinic Kotlin project with 18 asLlm call sites yielded 24 of 24 application scenarios completed after Smart macro evolution. The hot-reload success rate was 100%, with compilation and redefinition adding roughly 1% of total runtime overhead. A synthetic “GitHub Beginner Issue Radar” parsed real issue data across 20 repositories and 30,000+ issues, reaching about 0.89 recall on ground-truth beginner labels.

Setup requirements

The plugin requires IntelliJ IDEA 2025.2.x, JDK 21, and an OpenAI API key stored in the target project’s .kotlinllm file via Tools > KotlinLLM Settings. It is released under the Apache License 2.0. Runnable examples, the thesis write-up, and the KotlinConf 2026 talk recording are available in the repository.

Is it deployable?

Not as a production runtime, at least not yet. JetBrains labels KotlinLLM a research prototype and describes it as an experimental IntelliJ IDEA plugin. The plugin itself is experimental, but its output is deployable. Once behaviour has been generated, the target project can compile and run that behaviour without another LLM request for the same scenario. Developers ship plain Kotlin, not a model dependency.

Who can use it

At the company level, the best fit today is R&D groups, platform teams at mid-size to large Kotlin/JVM entities, and startups with tolerance for prototype tooling. Regulated enterprises should treat generated sources as reviewable code, which is exactly how KotlinLLM stores them.

Industries include fintech and banking with heavy JVM/Kotlin estates, developer tooling, e-commerce, logistics, and any team parsing messy third-party API payloads.

Applications cover normalising semi-structured API responses into typed values, building evolving test doubles, adapting to upstream schema drift, and classification over noisy text fields.

What it means

For developers working with Kotlin, this tool changes the workflow of building and testing APIs. Instead of writing boilerplate code by hand or relying on static mocks that break when schemas change, the system writes the code, compiles it, and updates it while the application runs. The generated code becomes part of the project. Once the scenario works, the LLM is no longer involved. The cost is a one-time inference request per scenario, followed by standard compilation times. This removes the need to maintain fragile mock objects and allows teams to iterate on API handling without rewriting code manually.

Scroll to Top