Automate Ghidra reverse engineering from the command line — headless analysis, decompilation, and structured JSON output for AI agents like Claude Code
Automate Ghidra reverse engineering from the command line — headless analysis, decompilation, and structured JSON output for AI agents like Claude Code
A Rust CLI for automating Ghidra reverse engineering tasks. Usable directly by hand or driven by an AI coding agent like Claude Code.
ping, status, jobs, and cancel stay live on a separate control planesize > 100 AND name ~ 'crypt')┌─────────────────┐ ┌──────────────────────────────────────┐
│ CLI Command │──TCP──▶ │ GhidraCliBridge.java │
│ ghidra ... │ │ (GhidraScript in analyzeHeadless) │
│ --project X │ │ ServerSocket on localhost:dynamic │
└─────────────────┘ └──────────────────────────────────────┘The CLI connects directly to a Java bridge running inside Ghidra's JVM. Ghidra loads once and stays resident, so one process holds all state: a rename or an applied type sticks for the next command instead of resetting each invocation, and queries return in-process with no per-command JVM startup. The bridge auto-starts on demand — any command brings it up, so you never launch it by hand.
Each project gets its own bridge process and port file, so you can analyze several binaries at once. The only runtime dependencies are Ghidra and a JDK — no Python/PyGhidra.
git clone https://github.com/akiselev/ghidra-cli
cd ghidra-cli
cargo install --path .ghidra setup to fetch itjavac and the jdk.compiler module. Ghidra 12.x wants JDK 21; older releases accept JDK 17. ghidra doctor finds a suitable JDK and compiles the bridge as a health check.Point the CLI at your Ghidra install (skip this if you used ghidra setup):
export GHIDRA_INSTALL_DIR=/path/to/ghidra
# Or store it in config:
ghidra config set ghidra_install_dir /path/to/ghidraghidra-cli picks the JDK itself and passes it to Ghidra, so you don't have to
juggle PATH. Override the choice with the global --java-home flag, the
java_home config key, or GHIDRA_CLI_JAVA_HOME.
# Check installation
ghidra doctor
# Import a binary. This starts the bridge and runs auto-analysis in one step.
ghidra import ./binary --project myproject --program mybinary
# Query functions (uses the running bridge)
ghidra function list
# Decompile a function
ghidra decompile main
# Find interesting strings
ghidra find string "password"
# Get cross-references
ghidra x-ref to 0x401000
# Generate call graph
ghidra graph callers main --depth 3These work before any subcommand, so you can set them once for a whole invocation:
ghidra --project P --program bin function list # --project/--program are global| Flag | Effect |
|---|---|
| `--project | |
| ` | Project name or path |
--program |
Program within the project |
--projects-dir |
Where Ghidra projects live (default: a cache dir; overrides ghidra_project_dir) |
--java-home |
Full JDK for Ghidra to use (must be a JDK, not a JRE) |
--json |
Compact JSON output |
--pretty |
Pretty-printed JSON |
-v / -vv / -vvv |
Log verbosity: warn / info / debug |
-q / --quiet |
Suppress non-essential output |
Ghidra 12.1+ rejects project directories that contain a dot-prefixed component
(such as ~/.cache), so on Linux the default falls back to
~/ghidra-cli-projects. Use --projects-dir to put projects wherever you like.
ghidra project create # Create project
ghidra project list # List projects
ghidra project info [] # Show project info
ghidra project delete # Delete project (removes .gpr/.rep, stops its bridge)
ghidra import --project
# Import + auto-analyze (bridge auto-starts)
ghidra import --no-analyze # Import only, skip analysis (still persisted)
ghidra import --detach # Return immediately; bridge keeps importing
ghidra analyze --project
# (Re)run analysis on an imported programghidra function list # List all functions
ghidra function list --filter "size > 100" # Filter by size
ghidra decompile # Decompile function
ghidra decompile main --with-vars --with-params # Include variable/param details
ghidra disasm --instructions 20 # Disassemble instructions
ghidra function set-signature --signature "int foo(int x, char *y)"
ghidra function set-return-type --type void
ghidra function set-calling-convention --convention __cdecl
ghidra function set-var-type --var local_10 --type "MyStruct *"Decompilation has no native time limit by default, so large valid functions are
not aborted after 30 seconds. Set GHIDRA_CLI_DECOMPILE_TIMEOUT to a positive
number of seconds to impose a Ghidra-side limit; 0 means unbounded. The socket
wait follows the long-operation policy controlled by GHIDRA_CLI_OP_TIMEOUT,
which is also unbounded by default.
……Tag names are case-sensitive. tag add/remove are idempotent (already-present
and not-present tags are reported, not errors). Function rows include a sorted
tags array, so --fields name,address,tags and --filter "tags ~ 'crypto'"
work too.
ghidra x-ref to # References TO address
ghidra x-ref from # References FROM addressghidra find string "pattern" # Find strings
ghidra find bytes "90 90 90" # Find byte patterns
ghidra find function "*crypt*" # Find functions by name
ghidra find crypto # Find crypto constants
ghidra find interesting # Find interesting patternsghidra graph calls # Full call graph
ghidra graph callers # Who calls this? (--depth optional)
ghidra graph callees # What does this call? (--depth optional)
ghidra graph export dot # Export to DOT formatghidra patch bytes "90 90" # Patch bytes
ghidra patch nop --count 5 # NOP out instructions
ghidra patch export -o patched.bin # Export patched binarypatch nop --count N NOPs N consecutive instructions starting at the address
(default 1), walking instruction by instruction so variable-length ISAs work. If
any address in the run has no instruction, the whole patch rolls back untouched.
ghidra comment get # Get comment
ghidra comment set "note" --comment-type EOL # Set comment
ghidra comment list # List all comments--comment-type accepts EOL (default), PRE, POST, or PLATE.
ghidra script list # List available scripts
ghidra script run myscript.py # Run a script file
ghidra script run report.py -- arg1 arg2 # Pass positional args after --
ghidra script run dump.py --expect out.csv:10 # Fail unless out.csv has >=10 rows
ghidra script python "print(currentProgram)" # Inline Python
ghidra script java "println(currentProgram);" # Inline Javascript run resolves the path to an absolute location, forwards the args after
-- to the script, and captures its stdout in the response. Use --expect PATH[:MIN_ROWS] (repeatable) to make the job fail when an output artifact is
missing, empty, or short, and --allow-empty to permit an expected-but-empty
file.
ghidra batch commands.txt # Run commands from fileghidra stats # Program statistics
ghidra summary # Program summaryThe bridge keeps Ghidra loaded in memory. It starts automatically when needed, but you can also control it manually:
…The bridge handles networking and lifecycle controls independently from Ghidra
program access. Program operations remain serialized on one Ghidra-owned thread,
but ping, status, jobs, cancel, and drain requests remain responsive while
analysis or another long operation is running. Queued program operations receive
job IDs and wait in an explicit bounded FIFO rather than an invisible socket
backlog.
Each project gets its own bridge process and port file, allowing concurrent analysis:
# Work on multiple projects simultaneously
ghidra import ./binary_a --project projA
ghidra analyze --project projA --program binary_a
ghidra import ./binary_b --project projB
ghidra analyze --project projB --program binary_b
# Query each independently
ghidra function list --project projA
ghidra function list --project projBDefault output is human-readable when connected to a terminal. When piped (non-TTY), output auto-detects to compact JSON for machine consumption. Use flags to override:
Override with flags:
# Force JSON output (compact, single-line)
ghidra function list --json
# Force pretty JSON (indented, multi-line)
ghidra function list --pretty
# Select specific fields
ghidra function list --fields "name,address,size"The bridge always emits compact JSON over the socket. The CLI decides the human-facing format at its own output boundary — human-readable when attached to a TTY, compact JSON when piped, or forced with --json/--pretty/-o. Doing it CLI-side keeps the wire protocol one stable shape with a single place that decides formatting.
Use expressions to filter results:
ghidra function list --filter "size > 100"
ghidra function list --filter "name ~ 'main'"
ghidra strings list --filter "length > 20"Paths and defaults:
| Variable | Purpose |
|---|---|
GHIDRA_INSTALL_DIR |
Ghidra installation path |
GHIDRA_PROJECT_DIR |
Base directory for projects |
GHIDRA_CLI_JAVA_HOME |
Full JDK for Ghidra (overrides auto-detection) |
GHIDRA_CLI_CONFIG |
Override the config file path |
GHIDRA_DEFAULT_PROJECT |
Default --project for ghidra query |
GHIDRA_DEFAULT_PROGRAM |
Default --program for ghidra query and auto-selection |
Timeouts. Most default to unbounded so that a legitimately long analysis or decompile isn't cut off. Set them when you'd rather fail fast:
| Variable | Purpose (default) |
|---|---|
| `GHIDRA_CLI_ |
No open issues yet, or sync has not completed.