docs/ClaudeExplain.md
Claude Explain uses Claude AI to provide natural language explanations of assembly code generation, helping users understand how their source code is translated into assembly and what compiler optimizations are applied.
no-ai directive shows a special messageAdd the API endpoint URL to compiler-explorer.*.properties:
explainApiEndpoint=https://api.compiler-explorer.com/explain
The explain button appears automatically when configured.
no-ai (case-insensitive) is never sent to the APIServer-side: Single property configuration (API endpoint). Server code: https://github.com/compiler-explorer/explain
Client-side:
ExplainView class (static/panes/explain-view.ts) handles UI, consent, API requests, and cachingexplain-view-utils.ts contains testable business logic (validation, formatting, request building)marked library for markdown rendering with syntax highlightingFeatures:
Testing:
GET / - Fetch available options:
{
"audience": [
{"value": "beginner", "description": "Simple language, explains technical terms"},
{"value": "intermediate", "description": "Focuses on compiler behavior and choices"},
{"value": "expert", "description": "Technical terminology, advanced optimizations"}
],
"explanation": [
{"value": "assembly", "description": "Explains assembly instructions and purpose"},
{"value": "source", "description": "Maps source code constructs to assembly"},
{"value": "optimization", "description": "Explains compiler optimizations and transformations"}
]
}
POST / - Generate explanation:
{
"language": "c++",
"compiler": "GCC 13.2",
"code": "Source code",
"compilationOptions": ["-O2", "-std=c++20"],
"instructionSet": "amd64",
"asm": ["Assembly output lines"],
"audience": "intermediate",
"explanation": "optimization",
"bypassCache": false
}
Optional fields: audience (default: "beginner"), explanation (default: "assembly"), bypassCache (default: false)
Response:
{
"status": "success",
"explanation": "Markdown-formatted explanation",
"model": "claude-3-sonnet",
"usage": {"inputTokens": 500, "outputTokens": 300, "totalTokens": 800},
"cost": {"inputCost": 0.0015, "outputCost": 0.0045, "totalCost": 0.006},
"cached": false
}
Multi-level caching reduces API costs and improves response times:
cached: true in responsebypassCache: true for fresh generation