Help us improve
Share bugs, ideas, or general feedback.
From go-dev
Provides in-depth explanations of Go files, functions, or packages with Mermaid diagrams, key concepts, idiomatic patterns, and dependencies.
npx claudepluginhub gopherguides/gopher-ai --plugin go-devHow this command is triggered — by the user, by Claude, or both
Slash command
/go-dev:explain <file|function|package>This command is limited to the following tools:
The summary Claude sees in its command listing — used to decide when to auto-load this command
**If `$ARGUMENTS` is empty or not provided:** Display usage information and ask for input: **Usage:** `/explain <target>` **Examples:** - `/explain pkg/auth/login.go` - Explain a file - `/explain HandleAuthentication` - Explain a function - `/explain pkg/services/` - Explain a package **Workflow:** 1. Analyze the specified Go code target 2. Extract key concepts, interfaces, dependencies 3. Generate documentation-style explanation 4. Create Mermaid diagrams for complex flows 5. Identify idiomatic Go patterns used Ask the user: "What file, function, or package would you like me to expl...
/code-explainExplains code files, algorithms, design patterns, or architectures with overview, step-by-step breakdowns, Mermaid diagrams, key concepts, gotchas, and common questions.
/explainExplains code files, functions, or concepts with structured breakdown: purpose, step-by-step logic, key concepts, gotchas, and dependencies.
/explain-codeExplains code snippets in depth: mechanics, design rationale, pros/cons, performance/security issues, edge cases, and improvements. Supports focused requests like algorithms or async flows.
/explain-codeExplains pasted code in detail via natural language queries, covering functionality, algorithms, design patterns, performance issues, security risks, async flows, and architecture with insights on implementation choices.
/explain-codeExplains provided code in detail: functionality, flow, design rationale, patterns, performance issues, security risks, edge cases, and improvements.
/explain-codeExplains provided code in detail: functionality, design rationale, advantages, issues, performance, security, async flow, and improvements.
Share bugs, ideas, or general feedback.
If $ARGUMENTS is empty or not provided:
Display usage information and ask for input:
Usage: /explain <target>
Examples:
/explain pkg/auth/login.go - Explain a file/explain HandleAuthentication - Explain a function/explain pkg/services/ - Explain a packageWorkflow:
Ask the user: "What file, function, or package would you like me to explain?"
If $ARGUMENTS is provided:
Generate a comprehensive explanation of the specified Go code. Creates documentation-style output with Mermaid diagrams for complex flows.
$ARGUMENTS (file path, function name, or package)Before loading file content:
Identify Target Scope
Analyze Go Code Structure
For files, extract:
For functions, extract:
For packages, extract:
Generate Explanation
Structure the output as:
# [Target Name]
## Overview
[2-3 sentence summary of what this code does and why it exists]
## Key Concepts
- **[Interface/Type]**: Purpose and usage
- **[Pattern]**: How it's applied
## How It Works
[Step-by-step explanation of the main flow]
## Go Patterns Used
- **Error Handling**: How errors are wrapped/returned
- **Interfaces**: Accept interfaces, return structs
- **Concurrency**: Goroutines, channels, sync primitives
## Dependencies
- `package-a`: Used for X
- `package-b`: Provides Y
## Diagram
[Mermaid diagram - see step 4]
## Important Details
- [Edge cases handled]
- [Performance considerations]
- [Thread safety notes]
Create Mermaid Diagrams
Choose the appropriate diagram type:
Flowchart - For control flow, algorithms:
flowchart TD
A[Request] --> B{Validate}
B -->|Valid| C[Process]
B -->|Invalid| D[Return Error]
C --> E{Success?}
E -->|Yes| F[Return Result]
E -->|No| G[Wrap Error]
Sequence Diagram - For interactions between components:
sequenceDiagram
participant H as Handler
participant S as Service
participant R as Repository
H->>S: ProcessRequest(ctx, req)
S->>R: FindByID(ctx, id)
R-->>S: entity, err
S-->>H: response, err
Class Diagram - For types and interfaces:
classDiagram
class Service {
<<interface>>
+Create(ctx, input) (Output, error)
+Get(ctx, id) (Output, error)
}
class serviceImpl {
-repo Repository
+Create(ctx, input) (Output, error)
}
Service <|.. serviceImpl
Highlight Go Idioms
Point out idiomatic patterns:
fmt.Errorf("%w", err)Add Context
--json)When $ARGUMENTS contains --json, output only valid JSON matching this schema instead of markdown. Do not include any text outside the JSON object.
{
"summary": "string — 2-3 sentence overview of what the code does and why",
"components": [
{
"name": "string — type, function, or interface name",
"purpose": "string — what this component does",
"complexity": "string — 'low', 'medium', or 'high'"
}
],
"call_graph": "string — Mermaid diagram source showing component interactions",
"recommendations": ["string — improvement suggestions or things to watch out for"]
}
Example:
{
"summary": "Package auth provides JWT-based authentication middleware for HTTP handlers. It validates tokens, extracts claims, and injects user context.",
"components": [
{"name": "Middleware", "purpose": "HTTP middleware that validates JWT tokens and sets user context", "complexity": "medium"},
{"name": "Claims", "purpose": "Custom JWT claims struct with user ID and roles", "complexity": "low"},
{"name": "TokenService", "purpose": "Interface for token generation and validation", "complexity": "low"}
],
"call_graph": "sequenceDiagram\n participant H as Handler\n participant M as Middleware\n participant T as TokenService\n M->>T: Validate(token)\n T-->>M: claims, err\n M->>H: next(ctx)",
"recommendations": ["Consider adding token refresh logic", "Add rate limiting to prevent brute-force attempts"]
}
Strip the --json flag from $ARGUMENTS before identifying the target.
If $ARGUMENTS contains --json, strip the flag from the target argument and output only a JSON object (no markdown, no explanation) matching this schema:
{
"summary": "string",
"components": [{"name": "string", "purpose": "string", "complexity": "string"}],
"call_graph": "string (mermaid)",
"recommendations": ["string"]
}
summary: 2-3 sentence overview of the codecomponents: Key types, functions, or interfaces with purpose and complexity level (low/medium/high)call_graph: Mermaid diagram source as a stringrecommendations: Actionable improvement suggestions