/install d2-diagram-creator
D2 Diagram Creator
Three-agent pipeline for high-quality diagram generation:
AskUserQuestion → Agent 1 (Analyzer) → Agent 2 (Generator) → Agent 3 (Validator)
Each agent is a general-purpose subagent with its own focused instructions. You (the main agent) orchestrate the pipeline — ask the user questions, then spawn agents in sequence, passing outputs forward.
Step 1: Ask Requirements
Use AskUserQuestion to ask all questions at once. Do not split into multiple rounds, do not skip any.
First round (always required)
{
"questions": [
{
"question": "How detailed should the diagram be?",
"header": "Detail Level",
"options": [
{ "label": "Core Flow", "description": "5-8 nodes" },
{ "label": "Moderate", "description": "10-15 nodes" },
{ "label": "Full Detail", "description": "Include all details and exception branches" }
]
},
{
"question": "What is the layout direction of the diagram?",
"header": "Layout Direction",
"options": [
{ "label": "Horizontal", "description": "direction: right, left to right" },
{ "label": "Vertical", "description": "direction: down, top to bottom" }
]
},
{
"question": "What format to export as?",
"header": "Export Format",
"options": [
{ "label": "D2 Code Only", "description": "No image export" },
{ "label": "SVG", "description": "Vector graphics (recommended)" },
{ "label": "PNG", "description": "Bitmap" },
{ "label": "Preview", "description": "ASCII text" }
]
}
]
}
Second round (only when SVG/PNG is selected)
{
"questions": [
{
"question": "Which theme to use?",
"header": "Theme",
"options": [
{ "label": "Light Theme", "description": "--theme 0, white background (default)" },
{ "label": "Dark Theme", "description": "--theme 200, dark background" }
]
},
{
"question": "Enable hand-drawn sketch style?",
"header": "Sketch",
"options": [
{ "label": "No", "description": "Normal style (default)" },
{ "label": "Yes", "description": "--sketch, hand-drawn effect" }
]
},
{
"question": "Choose layout engine?",
"header": "Layout Engine",
"options": [
{ "label": "dagre", "description": "Default, fast and efficient" },
{ "label": "elk", "description": "Complex diagrams, 100+ nodes" },
{ "label": "tala", "description": "Most powerful, SVG only, requires installation" }
]
}
]
}
Only provide 2 theme options (Light/Dark). Do not add colorful, terminal, or other themes.
Step 2: Spawn Analyzer Agent
Use the Agent tool to spawn the requirements analyzer. This agent deeply analyzes the user's request and produces a structured JSON document.
- subagent_type:
general-purpose - description:
Analyze diagram requirements
The prompt should be:
Read the file at \x3Cskill-base-path>/agents/analyzer.md for your instructions.
Analyze this diagram request:
User request: \x3Cuser's original description>
User preferences:
- Detail level: \x3Canswer>
- Layout direction: \x3Canswer>
- Export format: \x3Canswer>
- Theme: \x3Canswer, or "not selected">
- Sketch: \x3Canswer, or "not selected">
- Layout engine: \x3Canswer, or "not selected">
Return the structured requirements JSON.
Save the returned JSON — you will pass it to the generator agent.
Step 3: Spawn Generator Agent
Use the Agent tool to spawn the D2 code generator.
- subagent_type:
general-purpose - description:
Generate D2 diagram code
The prompt should be:
Read the file at \x3Cskill-base-path>/agents/generator.md for your instructions.
Generate D2 code based on these requirements:
\x3Cthe requirements JSON from Step 2>
Read the diagram type guide at:
\x3Cskill-base-path>/references/diagram-types/\x3Cdiagram_type>.md
Save the D2 code to a .d2 file (use a descriptive filename).
Return the file path.
Save the returned file path — you will pass it to the validator agent.
Step 4: Spawn Validator Agent
Use the Agent tool to spawn the validator.
- subagent_type:
general-purpose - description:
Validate and export diagram
The prompt should be:
Read the file at \x3Cskill-base-path>/agents/validator.md for your instructions.
Your skill base directory is: \x3Cskill-base-path>
The watermark removal script is at: \x3Cskill-base-path>/scripts/remove_watermark.py
Validate and export:
D2 file: \x3Cpath from Step 3>
Requirements: \x3Cthe requirements JSON>
Export preferences:
- Format: \x3Cexport_format>
- Theme: \x3Ctheme or "default">
- Sketch: \x3Csketch or false>
- Layout engine: \x3Cengine or "dagre">
Fix any issues and export the final diagram.
Report the validator's summary to the user.
Diagram Types Reference
| Type | Use Case |
|---|---|
| Flowchart | Business processes, decision trees, algorithm flows |
| System Architecture | Component relationships, infrastructure, service interactions |
| Organizational Chart | Hierarchical structures, reporting relationships |
| Service Topology | Cloud architecture, network topology |
| State Machine | State transitions, workflow states, lifecycles |
| Swimlane Diagram | Cross-functional processes, multi-role workflows |
| Sequence Diagram | Time-based interactions, protocol flows |
| SQL Table Diagram | Database schemas, ER diagrams |
| Grid Diagram | Dashboard layouts, UI prototypes |
Prohibitions
- Do not skip requirement questions — always ask first
- Do not add visual styles unless the user explicitly requests them
- Do not add a diagram title unless the user explicitly requests one
- Do not skip any of the three agents — the pipeline must run to completion
- 确保已安装 OpenClaw(本地或 Docker 部署)
- 在对话框中输入安装命令:
/install d2-diagram-creator - 安装完成后,直接呼叫该 Skill 的名称或使用
/d2-diagram-creator触发 - 根据 Skill 的参数说明提供必要输入,即可获得结构化输出
D2 Diagram Creator 是什么?
Generate D2 diagram code supporting flowcharts, system architecture diagrams, organizational charts, service topology diagrams, state machine diagrams, swiml... 它是一个面向 Claude Code / OpenClaw 的 AI Agent Skill 插件,目前累计下载 84 次。
如何安装 D2 Diagram Creator?
在 OpenClaw 或 Claude Code 对话框中运行命令「/install d2-diagram-creator」即可一键安装,无需额外配置。
D2 Diagram Creator 是免费的吗?
是的,D2 Diagram Creator 完全免费,采用 MIT-0 许可证,可自由下载、安装和使用。
D2 Diagram Creator 支持哪些平台?
D2 Diagram Creator 跨平台运行,可在任意部署了 OpenClaw / Claude Code 的环境中使用(cross-platform)。
谁开发了 D2 Diagram Creator?
由 HuTa0kj(@huta0kj)开发并维护,当前版本 v1.0.0。