TLDRocket
Sign in

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

MarkTechPost Michal Sutter

JetBrains open-sourced KotlinLLM, a plugin that writes Kotlin code on the fly and hot-swaps it into a running app. Once a scenario's covered, it never needs the LLM again - so it's fast and cheap after the first pass.

JetBrains Research just dropped something genuinely odd into the open-source world: a plugin that lets your Kotlin program write its own code while it's running, then swaps that code into the live JVM process without a restart. It's called KotlinLLM, and the core idea is a new concept called a "Smart macro" — a function call like asLlm() or mockLlm() that looks completely ordinary in your source but has no real implementation until the program actually needs one.

Here's how it plays out in practice. You call something like asLlm<String, ApiUrl>(repoInput, hint = "GitHub API URL: get all issues, including closed"), and the plugin, watching the process through the JDI debugging interface, notices there's no generated logic yet for that call site. It freezes at a breakpoint, grabs the runtime values and types from the suspended stack frame, ships that context to an LLM agent, gets back actual Kotlin code, compiles it, and redefines the loaded class on the spot. Then execution just... continues, as if the code had been there all along. JetBrains counted nine steps in this loop, and they built an interactive explainer just to walk through it because describing it in prose undersells how strange it is.

The numbers they published are modest in scale but pretty clean. On a Kotlin fork of Spring Petclinic with 18 asLlm call sites, all 24 tested application scenarios completed successfully after the macros evolved, hot-reload worked 100% of the time, and the whole compile-and-redefine dance added about 1% runtime overhead. A separate test — a

My take

This is a clever hack dressed up as a language feature, and I mean that as a compliment: the trick isn't the LLM, it's that once code is generated you never pay for inference again, you just ship plain Kotlin. That's the opposite of the subscription-everything model most AI tooling is pushing, and it's the kind of design choice I wish more vendors made instead of quietly metering every keystroke through an API.

Read more about this at: MarkTechPost

Related stories

The daily briefing

Every AI story that matters, in your inbox by 8am.

TLDRocket reads 60+ sources, removes duplicate coverage, and summarises the day in two minutes. Follow companies and topics for alerts, or get the briefing in Slack. Free, no spam, unsubscribe anytime.