KotlinLLM: JVM Code That Rewrites Itself at Runtime

Every time your Kotlin app hits an edge case your LLM call did not anticipate, someone pays in latency, inference cost, and a broken user experience that never gets a postmortem.

Wiring LLM output into typed Kotlin by hand is where velocity goes to die

Kotlin developers integrating language models today write glue code manually: prompt construction, response parsing, type coercion, and error handling for every new call site. That is four layers of fragile code that breaks whenever the model output shifts.

The JVM finally has a runtime that edits its own source

JetBrains Open is an IntelliJ IDEA plugin that introduces Smart macros, two function calls that replace all that glue. You annotate a call with KotlinLLM‘s asLlm<F, T>(input, hint) to convert any input into a typed output like a data class, enum, or list, or use mockLlm<T>() to generate a stateful interface implementation. When a runtime scenario the generated code does not cover is hit, KotlinLLM suspends execution through JDI, captures the live frame values, sends them to an LLM agent, compiles the updated class, and redefines it in the running JVM before retrying, no restart required.

Backend engineers hit this problem hardest

  • Kotlin backend engineers who hand-parse LLM JSON responses into domain types on every new feature get typed outputs generated and hot-reloaded instead.
  • Platform engineers managing inference costs who need repeated call paths to stop burning tokens get a coverage model where solved scenarios skip the LLM entirely.
  • Developer tooling teams building IntelliJ plugins who prototype interface mocks manually get stateful, behavior-aware mocks generated from a single macro call.

The JVM-specific constraint here is the actual differentiator. JDI class redefinition is not available in most runtimes, which is why this pattern has not shipped anywhere else.

JetBrains is betting the agentic loop belongs inside the compiler, not outside it

GitHub Copilot and competitors operate at the editor suggestion layer, leaving runtime adaptation entirely to the developer. KotlinLLM pushes the agent into the execution loop itself, which means the tool gets smarter with every production invocation rather than every keystroke.

What you can build with it today

  • Convert raw API responses into typed Kotlin data classes without a parser.
  • Generate stateful mock implementations of any interface for testing.
  • Hot-reload updated class logic into a live JVM session without restarting.
  • Reduce inference calls on covered runtime paths automatically over time.

Pricing not listed, the project is open-source, check our directory for current details.

KotlinLLM only works on Kotlin/JVM projects and depends on JDI, so teams on Kotlin/Native or Kotlin/JS are out of scope for now.

GitHub Copilot generates code at edit time but has no mechanism to evolve it against live runtime state. Cursor operates similarly, giving suggestions before execution rather than responding to what happens during it.

The line between compiler and AI agent is dissolving faster than most teams expected

Tools that close the loop between model output and running production code are compressing a workflow that used to take days into a single annotated function call. We cover tools like this every Friday — subscribe here and we’ll send the best ones straight to you.