Most AI coding tools today wrap an external Node or Python CLI around your editor and interact with Java code via regex and raw text diffs. Over the past year we built Anahata ASI (Apache 2.0), a pure-Java agent container that runs directly inside the target JVM—primarily as an Apache NetBeans plugin (Plugin Portal #135, NetBeans 28–35+, Java 21+), with a standalone desktop build and early IntelliJ support.

Instead of bridging out to a separate Python runtime, embedding the agent directly inside the IDE JVM unlocks a few interesting JVM-native patterns:

1. In-JVM Compilation & Child-First Classloading (NbJava)#

Rather than constraining the model strictly to pre-baked JSON tool schemas, the agent can write Java snippets, compile them in memory against the active project classpath (including resolving Maven Central dependencies on the fly), and load them through a child-first AgiClassLoader inside the running JVM.

In practice, this turns the agent loop into a compiler-in-the-loop workflow: it hooks directly into NetBeans javac diagnostics so compilation errors feed back into the loop automatically until edits build cleanly.

2. AST-Guided Refactoring Instead of Line Patches#

String-based diff patching routinely mangles formatting and comments in large Java classes. Inside NetBeans, the agent delegates structural edits to NetBeans' own AST and Refactoring APIs so batch refactors preserve exact indentation and inline comments.

3. Context Window Garbage Collection (CwGC)#

Long multi-turn sessions normally hit token walls or degrade via naive sliding-window truncation. We modeled context management a bit like generational GC: tracking part-level depth decay across turns, pruning stale tool outputs, and compacting older history into compact "Semantic Ghosts," paired with Kryo session persistence and plain .md history backups.

4. Models, Local Execution & Honest Tradeoffs#

It works with Ollama / vLLM on localhost (no tunnels required) as well as Gemini, Claude, OpenAI, DeepSeek, and OpenRouter. Because running dynamic Java compilation and OS/WebDriver tools inside an IDE JVM is inherently high-privilege, every tool execution stages in a PENDING human-in-the-loop state so you inspect and edit arguments or diffs before anything runs.

The biggest practical tradeoff right now is footprint and version coupling: bundling Swing/JavaFX multimodal tooling, browser automation, and provider SDKs makes the full Studio .nbm around 140 MB and targets recent NetBeans releases (NB 30–31+ for the full Studio bundle).

If you want to see what the loop looks like in practice—like building a live 3D JavaFX ADS-B flight tracker inside NetBeans—the full 13-module Maven reactor is on GitHub. Curious how other JVM devs feel about in-IDE agents vs. external CLI harnesses like Claude Code or MCP servers.