/clojure-libraries:clj-java-decompilerfrom clojure-libraries
REPL-integrated decompiler that shows the Java source or JVM bytecode the Clojure compiler produces for a form — for checking reflection, boxing, primitive math, direct linking and interop codegen
Ships in clojure-libraries. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Decompiles Clojure forms, from the REPL, into the Java source (via Procyon) or javap-style JVM bytecode that the Clojure compiler generates for them. Use it to see what your code compiles to: whether it reflects, boxes numbers, uses primitive math, links directly, or what reify/deftype/proxy expand into.
Repository: https://github.com/clojure-goes-fast/clj-java-decompiler
Article: https://clojure-goes-fast.com/blog/introspection-tools-java-decompilers/
Latest version: 0.3.7 (2025-01-28)
License: EPL-1.0
Backend: Procyon procyon-compilertools 0.6.0 (supports JDK 9+)
;; deps.edn — a dev alias is the usual place
{:aliases
{:dev {:extra-deps {com.clojure-goes-fast/clj-java-decompiler {:mvn/version "0.3.7"}}}}}
;; Leiningen project.clj
:profiles {:dev {:dependencies [[com.clojure-goes-fast/clj-java-decompiler "0.3.7"]]}}
Ad-hoc:
clj -Sdeps '{:deps {com.clojure-goes-fast/clj-java-decompiler {:mvn/version "0.3.7"}}}'
| Requirement | Detail |
|---|---|
| Clojure | 1.10+ (tested 1.10–1.12) |
| JVM | JDK 8+; works on JDK 25 |
| JVM flags | None |
| Babashka | Not supported — needs the real Clojure compiler to emit bytecode |
| ClojureScript | Not applicable |
.class files.Compiler/compile, which loads the form. (decompile (defn foo ...)) defines foo in the current namespace, and top-level side effects (e.g. (println ...)) run.fn, reify, deftype, etc. becomes its own class, each printed under a // Decompiling class: <name> header. Top-level expressions also produce a cjd__init class (the namespace loader). For defn/defmacro with several classes, cjd__init is hidden.user$sum. Anonymous fns get the line number embedded: user$fn_line_2__254.:disable-locals-clearing true is bound unless you set it yourself).ClassName.member → member, and const__N Var fields → __ns_name, with ((IFn)const__0.getRawRoot()).invoke(...) shortened to __ns_name.invoke(...). The real bytecode still dereferences the var root.*out*. Capture with with-out-str.Namespace: clj-java-decompiler.core
(require '[clj-java-decompiler.core :refer [decompile disassemble]])
decompile (macro)(decompile form) — compile form and print the equivalent Java source. Don't quote the form.
(decompile (fn [] (println "Hello")))
// Decompiling class: user$fn_line_2__254
import clojure.lang.*;
public final class user$fn_line_2__254 extends AFunction
{
public static final Var __println;
public static Object invokeStatic() {
return __println.invoke("Hello");
}
@Override
public Object invoke() {
return invokeStatic();
}
static {
__println = RT.var("clojure.core", "println");
}
}
disassemble (macro)(disassemble form) — print JVM bytecode, analogous to javap -c. Don't quote the form.
(disassemble (fn [x] (inc x)))
// Decompiling class: user$fn_line_7__283
class user$fn_line_7__283
Minor version: 0
Major version: 52
Flags: PUBLIC, FINAL, SUPER
...
public static java.lang.Object invokeStatic(java.lang.Object x);
Flags: PUBLIC, STATIC
Code:
linenumber 7
0: aload_0 /* x */
1: invokestatic clojure/lang/Numbers.inc:(Ljava/lang/Object;)Ljava/lang/Number;
4: areturn
Use disassemble when you need exact instructions: checkcast, boxing calls (Numbers.num, Long.valueOf), invokevirtual vs invokestatic, locals clearing (aconst_null/astore).
decompile-form (function)(decompile-form opts quoted-form) — the function behind both macros. Use it when the form is data (built programmatically, read from a file).
| Option | Values | Default |
|---|---|---|
:decompiler | :java or :bytecode | :java |
(require '[clj-java-decompiler.core :as d])
(d/decompile-form {} '(defn x [] 1))
(d/decompile-form {:decompiler :bytecode} '(fn [a] (* a a)))
;; Decompile a form built at runtime
(let [hint 'long]
(d/decompile-form {} `(fn [~(with-meta 'a {:tag hint})] (inc ~'a))))
postprocessing-enabled (atom)Default true. Set to false to see raw Procyon output (with const__N fields and full class prefixes).
(reset! d/postprocessing-enabled false)
(decompile (defn caller [] (helper 1)))
;; return ((IFn)user$caller.const__0.getRawRoot()).invoke(user$caller.const__1);
(reset! d/postprocessing-enabled true)
;; return __user_helper.invoke(const__1);
Note: the README misspells the ns as clj-java-decompier.core; the correct name is clj-java-decompiler.core.
*compiler-options*)The standard Clojure *compiler-options* var is respected. Bind it around the call:
| Key | Effect on output |
|---|---|
:disable-locals-clearing | Default forced to true by the library. Set false to see x = null clearing as in real builds |
:direct-linking | true → calls to other fns become ns$fn.invokeStatic(...) instead of going through the Var |
:elide-meta | Vector of metadata keys to drop, e.g. [:doc :file :line :added] |
(binding [*compiler-options* {:direct-linking true}]
(decompile (defn caller [] (helper 1))))
Remember binding is dynamic — it must wrap the macro call itself.
(decompile (fn [s] (.length s)))
;; return Reflector.invokeNoArgInstanceMember(s, "length", false);
(decompile (fn [^String s] (.length s)))
;; return ((String)s).length();
Any Reflector.invoke* call means a missing type hint. Cross-check with (set! *warn-on-reflection* true).
(decompile (defn add [a b] (+ a b)))
;; public static Object invokeStatic(final Object a, final Object b) {
;; return Numbers.add(a, b); ; boxed, Object path
(decompile (defn sum ^long [^long a ^long b] (+ a b)))
public final class user$sum extends AFunction implements LLL
{
public static long invokeStatic(final long a, final long y) {
return Numbers.add(a, y); // primitive long overload
}
@Override
public Object invoke(final Object o, final Object o2) {
return invokeStatic(RT.longCast(o), RT.longCast(o2));
}
@Override
public final long invokePrim(final long a, final long n) {
return invokeStatic(a, n);
}
}
Signs of boxing: Object params/returns, Numbers.num(...), RT.box, Long.valueOf. Signs of primitive paths: long/double locals, implements LL, LLL, DD, etc. (IFn$LLL primitive interfaces), invokePrim.
loop compiles to a primitive loop(decompile (loop [i 0 acc 0]
(if (< i 10) (recur (inc i) (+ acc i)) acc)))
long i = 0L;
long acc = 0L;
while (i < 10L) {
final long inc = Numbers.inc(i);
acc = Numbers.add(acc, i);
i = inc;
}
return Numbers.num(acc); // boxed only once, at the end
If you see Object i or Numbers.inc(Object) in the loop body, a loop local got boxed (often because an initial value or a recur arg is not primitive — e.g. (recur (inc i) (+ acc (get m i)))).
(defn helper [x] x)
(decompile (defn caller [] (helper 1)))
;; return __user_helper.invoke(const__1); ; via Var root
(binding [*compiler-options* {:direct-linking true}]
(decompile (defn caller [] (helper 1))))
;; return user$helper.invokeStatic(const__1); ; static call, no Var
(decompile (defn r [] (reify Runnable (run [_] (println "hi")))))
;; user$r and user$r$reify__270 implements Runnable, IObj
(decompile (deftype P [^long x] Object (toString [_] (str x))))
;; public final class P implements IType { public final long x; ... }
Works for reify, deftype, defrecord, proxy, gen-class, definterface, letfn, protocols, macros' expansions.
Bytecode of already-loaded fns is gone; re-evaluate the source:
(require '[clojure.repl :refer [source-fn]])
(source-fn 'clojure.core/frequencies) ; get the source string
;; paste it into (decompile (defn frequencies ...)) — beware this redefines
;; the var in the *current* namespace, not in clojure.core
Do it in a scratch namespace ((in-ns 'scratch), (clojure.core/refer-clojure)) so you don't shadow real fns.
(def java-src (with-out-str (decompile (fn [] 1))))
(spit "/tmp/out.java" java-src)
(binding [*compiler-options* {:disable-locals-clearing false}]
(decompile (defn lc [a] (let [b (inc a)] (str b b)))))
;; final Object x = a; a = null; ... b = null; return fn.invoke(o, o2);
M-x clj-decompiler-decompile on the form before point; can inject the dependency at cider-jack-in.(decompile ...) and eval.| You see | Meaning |
|---|---|
extends AFunction | Ordinary fn; RestFn = variadic |
invokeStatic + invoke delegating | Fn with no closed-over locals (can be direct-linked) |
| Instance fields + constructor | Closure over locals |
__ns_name.invoke(...) | Call through the Var (post-processed getRawRoot()) |
ns$fn.invokeStatic(...) | Direct-linked call |
Reflector.invoke* | Reflection — add type hints |
RT.longCast, RT.intCast | Coercion from Object to primitive |
Numbers.num(long) | Boxing a primitive result |
implements LL, OL, DDD... | Primitive fn interface (IFn$LL...): arg/return types L=long, D=double, O=Object |
RT.var("ns","name") in static {} | Var lookup at class init |
const__N | Constant (literal, keyword, metadata map) |
cjd__init | Wrapper class for the temp "namespace"; ignore |
this = null; | Procyon artifact of locals clearing this — not valid Java |
The output is a decompilation: approximate, not always compilable Java. Use disassemble when precision matters.
clojure.lang.Compiler$CompilerException with location cjd.clj:<line>:<col> (the temp file name), e.g. unresolved symbols.
(try (decompile (fn [] (undefined-sym)))
(catch clojure.lang.Compiler$CompilerException e (ex-message e)))
;; "Syntax error compiling at (cjd.clj:7:24)."
decompile evaluates the form. Don't decompile a defn named like a production var in a live namespace, or forms with side effects (DB writes, HTTP calls) at top level — wrap in (fn [] ...) so only the fn body is compiled, not run..class files / jars.java.io.tmpdir) and decompiles; expect tens to hundreds of ms. Fine for REPL use; not for hot paths.:direct-linking, :elide-meta, locals clearing on) to see production codegen.clojure.core/*warn-on-reflection*, *unchecked-math* :warn-on-boxed — compiler warnings for reflection/boxing.javap -c -p — disassemble AOT-compiled .class files from target/classes.What SKILL.md sets; muted values are Claude Code's defaults
Other plugins' skills for the same job
npx claudepluginhub hugoduncan/library-skills --plugin clojure-libraries10 skills in this plugin
/babashka.cliCommand-line argument parsing for turning Clojure functions into CLIs/babashka.fsA guide to using babashka.fs./babashka.processClojure library for spawning sub-processes and shell operations/clayREPL-friendly data visualization and literate programming for Clojure with Kindly convention/clj-async-profilerLow-overhead sampling profiler for Clojure/JVM, built on async-profiler, that produces interactive flamegraphs and diffgraphs/clj-kondoA guide to using clj-kondo for Clojure code linting, including configuration, built-in linters, and writing custom hooks.