Help AI coding agents understand Java dependencies without dumping source
Help an AI agent read Java dependencies with outline, members, and one method body, to reduce token use without a source dump.
An agent that unzips a dependency and reads the source file spends its context on code it did not ask about. jdx answers one question at a time: the type card, the members declared on that type, the callable surface, then one signature and one body. Each line names its symbol canonically, so the next command is a copy-paste. Install with the one-line installer. The flag details live in Reading code. Every command output on this page was produced by running that command when the page was built.
Start with the type card#
jdx show is the class card: kind, modifiers, supertypes, member counts, provenance, and a next: line. A member reference is a usage error (exit 3). A short name that matches several types exits 2 and lists the candidates.
jdx show com.google.gson.Gson --coord com.google.code.gson:gson:2.14.0 --fetch
class com.google.gson.Gson
public final class Gson
extends java.lang.Object
members: 2 constructors, 33 methods, 26 fields
source: gson-2.14.0.jar (bytecode)
next: jdx members com.google.gson.Gson --inherited
warning MULTI_RELEASE_VARIANT: multi-release gson-2.14.0.jar serves version-specific variants for this JDK (21)Real output — this example ran against the current jdx when the page was built.
--coord resolves from ~/.gradle/caches and ~/.m2 first. --fetch allows a download when the coordinate is missing. The running JDK needs no flag: jdx show java.util.HashMap.
Reference: show.
Outline, then members#
jdx outline prints one dense line per member declared on that exact type. Inherited members are never included. This is the file-structure view, and it is the right first list for a dependency the agent does not own.
jdx outline com.google.gson.Gson --kind method --limit 8 --coord com.google.code.gson:gson:2.14.0 --fetch
members of com.google.gson.Gson
methods declared on com.google.gson.Gson:
method public <T> T fromJson(com.google.gson.JsonElement json, com.google.gson.reflect.TypeToken<T> typeOfT) throws com.google.gson.JsonSyntaxException
method public <T> T fromJson(com.google.gson.JsonElement json, java.lang.Class<T> classOfT) throws com.google.gson.JsonSyntaxException
method public <T> T fromJson(com.google.gson.JsonElement json, java.lang.reflect.Type typeOfT) throws com.google.gson.JsonSyntaxException
method public <T> T fromJson(com.google.gson.stream.JsonReader reader, com.google.gson.reflect.TypeToken<T> typeOfT) throws com.google.gson.JsonIOException, com.google.gson.JsonSyntaxException
method public <T> T fromJson(com.google.gson.stream.JsonReader reader, java.lang.reflect.Type typeOfT) throws com.google.gson.JsonIOException, com.google.gson.JsonSyntaxException
method public <T> T fromJson(java.io.Reader json, com.google.gson.reflect.TypeToken<T> typeOfT) throws com.google.gson.JsonIOException, com.google.gson.JsonSyntaxException
method public <T> T fromJson(java.io.Reader json, java.lang.Class<T> classOfT) throws com.google.gson.JsonSyntaxException, com.google.gson.JsonIOException
method public <T> T fromJson(java.io.Reader json, java.lang.reflect.Type typeOfT) throws com.google.gson.JsonIOException, com.google.gson.JsonSyntaxException
8 of 32 members shown (--limit 32 to see more)
source: gson-2.14.0.jar (bytecode)
warning MULTI_RELEASE_VARIANT: multi-release gson-2.14.0.jar serves version-specific variants for this JDK (21)Real output — this example ran against the current jdx when the page was built.
jdx members is the completion list. Inherited members are included by default and grouped by the declaring type, with java.lang.Object collapsed to one line unless --from java.lang.Object expands it. --declared limits the list to the type itself, which is outline with the same filters.
Narrow the list instead of reading more:
| Want | Flag |
|---|---|
| only this type's own members | --declared, or jdx outline |
| methods, fields, constructors, properties | --kind method, --kind field, --kind ctor, --kind property |
| a name regex | --grep '^get' |
| fewer rows | --limit N (default 50; the footer names the flag that shows the rest) |
| less text around the rows | --brief (no group headers, no provenance; text only) |
| a hard line cap | --max-lines N (text only) |
--brief and --with-doc together exit 3. Neither --brief nor --max-lines changes --json output. The envelope is the same information as the text. See Output, JSON & exit codes.
jdx outline com.google.gson.JsonArray --brief --limit 8 --coord com.google.code.gson:gson:2.14.0 --fetch
members of com.google.gson.JsonArray
constructor public JsonArray()
constructor public JsonArray(int capacity)
method public boolean contains(com.google.gson.JsonElement element)
method public boolean equals(java.lang.Object o)
method public boolean getAsBoolean()
method public boolean isEmpty()
method public boolean remove(com.google.gson.JsonElement element)
method public byte getAsByte()
8 of 32 members shown (--limit 32 to see more)
warning MULTI_RELEASE_VARIANT: multi-release gson-2.14.0.jar serves version-specific variants for this JDK (21)
jdx members com.google.gson.Gson --declared --kind method --grep toJson --coord com.google.code.gson:gson:2.14.0 --fetch
members of com.google.gson.Gson
methods declared on com.google.gson.Gson:
method public com.google.gson.JsonElement toJsonTree(java.lang.Object src)
method public com.google.gson.JsonElement toJsonTree(java.lang.Object src, java.lang.reflect.Type typeOfSrc)
method public java.lang.String toJson(com.google.gson.JsonElement jsonElement)
method public java.lang.String toJson(java.lang.Object src)
method public java.lang.String toJson(java.lang.Object src, java.lang.reflect.Type typeOfSrc)
method public void toJson(com.google.gson.JsonElement jsonElement, com.google.gson.stream.JsonWriter writer) throws com.google.gson.JsonIOException
method public void toJson(com.google.gson.JsonElement jsonElement, java.lang.Appendable writer) throws com.google.gson.JsonIOException
method public void toJson(java.lang.Object src, java.lang.Appendable writer) throws com.google.gson.JsonIOException
method public void toJson(java.lang.Object src, java.lang.reflect.Type typeOfSrc, com.google.gson.stream.JsonWriter writer) throws com.google.gson.JsonIOException
method public void toJson(java.lang.Object src, java.lang.reflect.Type typeOfSrc, java.lang.Appendable writer) throws com.google.gson.JsonIOException
source: gson-2.14.0.jar (bytecode)
warning MULTI_RELEASE_VARIANT: multi-release gson-2.14.0.jar serves version-specific variants for this JDK (21)Real output — this example ran against the current jdx when the page was built.
Open one signature, then one body#
jdx signature prints every overload of one member and exits 0. jdx body will not pick one: the same name exits 2 and lists each candidate as a canonical ref. Paste one of those refs into jdx body. Always quote the ref: #, (, and $ are shell syntax.
jdx signature 'com.google.gson.Gson#toJson' --coord com.google.code.gson:gson:2.14.0 --fetch
signatures of com.google.gson.Gson#toJson
public java.lang.String toJson(java.lang.Object src)
public java.lang.String toJson(java.lang.Object src, java.lang.reflect.Type typeOfSrc)
public void toJson(java.lang.Object src, java.lang.Appendable writer) throws com.google.gson.JsonIOException
public void toJson(java.lang.Object src, java.lang.reflect.Type typeOfSrc, java.lang.Appendable writer) throws com.google.gson.JsonIOException
public void toJson(java.lang.Object src, java.lang.reflect.Type typeOfSrc, com.google.gson.stream.JsonWriter writer) throws com.google.gson.JsonIOException
public java.lang.String toJson(com.google.gson.JsonElement jsonElement)
public void toJson(com.google.gson.JsonElement jsonElement, java.lang.Appendable writer) throws com.google.gson.JsonIOException
public void toJson(com.google.gson.JsonElement jsonElement, com.google.gson.stream.JsonWriter writer) throws com.google.gson.JsonIOException
source: gson-2.14.0.jar (bytecode)
next: jdx show com.google.gson.Gson
warning MULTI_RELEASE_VARIANT: multi-release gson-2.14.0.jar serves version-specific variants for this JDK (21)
jdx body 'com.google.gson.Gson#toJson' --coord com.google.code.gson:gson:2.14.0 --fetch
ambiguous: 8 candidates for com.google.gson.Gson#toJson
com.google.gson.Gson#toJson(com.google.gson.JsonElement)
com.google.gson.Gson#toJson(com.google.gson.JsonElement, com.google.gson.stream.JsonWriter)
com.google.gson.Gson#toJson(com.google.gson.JsonElement, java.lang.Appendable)
com.google.gson.Gson#toJson(java.lang.Object)
com.google.gson.Gson#toJson(java.lang.Object, java.lang.Appendable)
com.google.gson.Gson#toJson(java.lang.Object, java.lang.reflect.Type)
com.google.gson.Gson#toJson(java.lang.Object, java.lang.reflect.Type, com.google.gson.stream.JsonWriter)
com.google.gson.Gson#toJson(java.lang.Object, java.lang.reflect.Type, java.lang.Appendable)
hint: re-run with one of the refs above
[exit 2]
jdx body 'com.google.gson.Gson#toJson(Object)' --max-lines 30 --coord com.google.code.gson:gson:2.14.0 --fetch
com.google.gson.Gson#toJson(java.lang.Object)
source: gson-2.14.0-sources.jar · com/google/gson/Gson.java:542-547
public String toJson(Object src) {
if (src == null) {
return toJson(JsonNull.INSTANCE);
}
return toJson(src, src.getClass());
}
next: jdx show com.google.gson.Gson
warning MULTI_RELEASE_VARIANT: multi-release gson-2.14.0.jar serves version-specific variants for this JDK (21)Real output — this example ran against the current jdx when the page was built.
body returns that member. --max-lines caps the slice (default 200). --context N adds lines around it. jdx source is the whole file, so slice it: --lines 120:160 or --around '<canonical ref>' --context 5. Prefer body when one member is the question.
With a paired -sources.jar, the text is the real file. Without one, jdx decompiles with Vineflower and labels the result ⚠ reconstructed. --engine javap prints raw bytecode of that member. Structure (show, outline, members, signature) always comes from bytecode. See Reading code.
Reference: signature, body, source.
One measured task#
The repository measured one task on gson-2.14.0: list Gson's API, then show only toJson(Object). unzip + javap + grep + sed was 5 calls and about 17.5 KB. jdx members plus jdx body was 2 calls and about 4.6 KB. The body alone was 267 bytes, against 60,590 bytes for javap -c of that class and 58,251 bytes for Gson.java. The README states tokens as about bytes/4 for that run (about 4.4k, about 1.2k, and about 67 for the body). That is one task, reproduced with docs/bench-compare.sh, not a rate for every question. See the README benchmark and Read and decompile a JAR.
Name the classpath once#
Typing --coord on every call is the expensive part for an agent. A workspace stores the jars:
jdx ws create gson --coord com.google.code.gson:gson:2.14.0
jdx -w gson outline com.google.gson.Gson --kind method --limit 20jdx mcp answers from a stored workspace and does not auto-discover a project. The config for Claude Code, Cursor, and Codex is An MCP server for Java and Kotlin bytecode. Wiring and the cheat sheet are in Use with AI agents. Classpath rules are in Classpath & workspaces.
Mapped jars#
jdx reads the names stored in the file. v1 does not read mapping files and does not rename classes. Pass the jar Fabric Loom or NeoForge ModDevGradle already wrote with --jars. diff compares two artifacts that already share one mapping namespace. A Yarn jar against a Mojmap jar looks like nearly every member was removed and re-added. See Minecraft mods.
Bytecode is parsed with ASM. Inspected classes are never loaded, so no static initialiser from a dependency runs.
Where next#
- Reading code —
doc, search, and Kotlin@Metadata. - A javap alternative — class-file signatures, callers, and implementors.
- Read and decompile a JAR — list a jar, then one method.
- Output, JSON & exit codes —
--json, truncation, and exit 2. - Command catalogue — every flag.