.opencode/commands/explain.md
Explain: $ARGUMENTS
This command produces reference documentation, structured like a man page. Be exhaustive for narrow targets (a single class, function, or file). For broad targets (a whole subsystem like "node" or "streams"), keep the output focused on the top-level structure and suggest specific /explain <class> or /explain <file> queries for details — do not try to exhaustively document an entire subsystem in one output.
Locate the target. If the argument is a file path, read it. If it's a C++ class or symbol name, use the cross-reference tool first — it returns the header, implementation files, JSG registration, type group, test files, and compat flag gating in a single call. If the target is a Rust symbol or .rs file (under src/rust/), skip the cross-reference tool and search manually — it is C++-specific.
Read the definition. Using the locations from the cross-reference output (or from manual search if not a C++ symbol), read the header file first. For functions, read the declaration and implementation. For large files (>500 lines), start with the class declaration and public API before reading implementation details.
For Rust code: Read the relevant lib.rs or module file. Look for #[jsg_resource], #[jsg_method], #[jsg_struct], and #[jsg_oneof] proc macro annotations to understand the JS-visible API surface. Check #[cxx::bridge] blocks to understand the FFI boundary with C++. Also check the CXX bridge companion files (ffi.c++/ffi.h) and the C++ code that calls into or is called from Rust. Consult the crate's README.md (if present) and src/rust/AGENTS.md for crate-level context. If the type uses proc macros, the <crate>@expand Bazel target can be used to inspect macro expansion.
Check for local documentation. Look for:
AGENTS.md in the same directory or nearest parentREADME.md in the same directoryGet the full API surface. For JSG-registered types, use the jsg-interface tool to get the complete structured JS API (methods, properties, constants, nested types, inheritance, TypeScript overrides). For header files, identify all public members. For config schemas (.capnp), list all fields.
Find build and test targets. Check the BUILD.bazel in the same directory for the relevant Bazel target. Note how to build and test it (e.g., just test //src/workerd/api/tests:some-test@).
Find real code examples. Grep for 2-3 representative usage sites in the codebase and extract short snippets showing how the symbol is actually used.
Check recent history. Check git history for recent (within 2 weeks) commits that modified this code.
Structure the output using these sections. Omit any section that doesn't apply to the target (e.g., skip CONFIGURATION if there are no compat flags).
api/, io/, jsg/, server/, util/). Keep it factual./explain <specific> queries for each.just test //src/workerd/api/tests:crypto-test@)./explain <target> suggestions), plus /trace or /deps pointers where relevant.dad-jokes skill). Don't overdo it, but don't avoid them either. When summarizing, always preserve any jokes from the subagent output, and always including the intro prefix ("Here's a dad joke for you:", etc.) so the user knows it's intentional.