Generates interactive code flow diagrams (.cgraph files). Invoke when users ask: "how does X work", "show me the flow of Y", "visualize the architecture", "diagram the data flow", "create a graph of the codebase", or similar queries about understanding code structure and relationships.
Generate .cgraph files that visualize code architecture and flow.
These files can be viewed in VS Code with the Codetographer extension.
Generate a .cgraph JSON file with this structure:
{
"version": "1.0",
"metadata": {
"title": "Feature Name",
"description": "Brief explanation of what this graph shows",
"generated": "2025-11-25T14:30:00Z",
"scope": "src/relevant/path"
},
"nodes": [
{
"id": "unique-node-id",
"label": "functionName()",
"type": "function",
"description": "What this function does in 1-2 sentences",
"location": {
"file": "src/path/to/file.ts",
"startLine": 42,
"endLine": 67
},
"group": "optional-group-id"
}
],
"edges": [
{
"id": "edge-1",
"source": "source-node-id",
"target": "target-node-id",
"type": "calls"
}
],
"groups": [
{
"id": "group-id",
"label": "Group Label",
"description": "What this section represents"
}
],
"layout": {
"direction": "TB"
}
}
Identify what the user wants to visualize:
Ask clarifying questions if the scope is unclear.
Use Glob and Grep to locate:
CRITICAL: Keep it focused! Only include 5-15 nodes maximum. Pick the most important functions/classes that explain the flow. Don't try to show everything.
For each node, record:
file: Relative path from workspace root (e.g., src/auth/service.ts)startLine: First line of function/class definitionendLine: Last line (recommended)IMPORTANT: Verify line numbers are accurate by reading the actual files.
Create edges that show the PRIMARY flow. Rules:
Every node MUST have a description field that explains:
Format tip: Write descriptions where the first sentence (~60 chars) works as a standalone summary.
Example:
Create {feature-name}.cgraph in project root with properly formatted JSON.
function: Named functions and arrow functionsmethod: Class methodsclass: Class definitionsmodule: Files treated as logical unitsfile: File-level groupingcalls: Direct function/method invocation (most common)imports: Module import relationshipextends: Class inheritanceimplements: Interface implementationuses: General dependency or data flowEach edge type is color-coded in the visualization:
calls → Blue (shows active invocations)extends → Green (inheritance)implements → Purple (interface implementation)imports/uses → Gray (dependencies)Use the optional importance field to control visual weight of edges:
primary: Thick line, full opacity - for the main/critical flow pathsecondary (default): Normal line - for standard relationshipstertiary: Thin line, reduced opacity - for minor/optional connections{
"id": "e1",
"source": "login-route",
"target": "auth-service",
"type": "calls",
"importance": "primary"
}
primary (e.g., the main success flow)secondary (default)tertiary for error handlers, logging, or optional dependenciesThis helps readers instantly see which paths matter most.
You can override the default edge type colors with custom colors:
{
"id": "e1",
"source": "api-handler",
"target": "database",
"type": "calls",
"color": "#ff6b6b"
}
Use custom colors when:
Add a legend to explain custom colors or categories in your graph:
"legend": {
"title": "Data Flow",
"items": [
{ "color": "#ff6b6b", "label": "Write operations" },
{ "color": "#4ecdc4", "label": "Read operations" },
{ "color": "#ffe66d", "label": "Cache access" }
]
}
The legend appears in the bottom-left corner of the graph. Use it when:
{
"version": "1.0",
"metadata": { "title": "Database Operations" },
"nodes": [...],
"edges": [
{ "id": "e1", "source": "api", "target": "db", "type": "calls", "color": "#ff6b6b" },
{ "id": "e2", "source": "cache", "target": "api", "type": "calls", "color": "#4ecdc4" }
],
"legend": {
"title": "Operation Types",
"items": [
{ "color": "#ff6b6b", "label": "Database write" },
{ "color": "#4ecdc4", "label": "Cache read" }
]
}
}
The layout.type field controls the overall layout algorithm:
layered (default): Hierarchical tree layout, good for call flows and linear processesforce: Compact web-like layout using physics simulation, good for interconnected systemsstress: Balanced even-spacing layout, good for general relationship graphsUse layered (default) when:
Use force when:
Use stress when:
"layout": {
"type": "force"
}
Or with direction (only applies to layered):
"layout": {
"type": "layered",
"direction": "LR"
}
TB: Top to bottom (default - use this for most flows)LR: Left to right (use for linear pipelines)BT: Bottom to top (rarely needed)RL: Right to left (rarely needed)Use groups to visually organize related nodes into labeled sections. This is useful when:
"groups": [
{
"id": "api-layer",
"label": "API Layer",
"description": "HTTP request handlers"
},
{
"id": "service-layer",
"label": "Service Layer",
"description": "Business logic"
}
]
Add a group field to each node that should be in a group:
{
"id": "login-handler",
"label": "handleLogin()",
"type": "function",
"group": "api-layer",
...
}
handleLogin() or UserService.authenticate()type is sufficient context.❌ Don't do this:
✅ Do this instead:
For a request like "Show me how user authentication works":
{
"version": "1.0",
"metadata": {
"title": "User Authentication Flow",
"description": "How login, token generation, and session management work",
"generated": "2025-11-25T14:30:00Z",
"scope": "src/auth"
},
"nodes": [
{
"id": "login-route",
"label": "POST /api/login",
"type": "function",
"description": "API endpoint that receives login credentials from the client. Validates input format before delegating to the auth service.",
"location": {
"file": "src/routes/auth.ts",
"startLine": 15,
"endLine": 35
}
},
{
"id": "auth-service-login",
"label": "AuthService.login()",
"type": "method",
"description": "Core authentication logic. Looks up the user, verifies password hash, and generates a JWT token on success.",
"location": {
"file": "src/services/auth.ts",
"startLine": 42,
"endLine": 78
}
},
{
"id": "user-repo-find",
"label": "UserRepository.findByEmail()",
"type": "method",
"description": "Queries the database for a user record matching the provided email address.",
"location": {
"file": "src/repositories/user.ts",
"startLine": 23,
"endLine": 31
}
},
{
"id": "token-generate",
"label": "generateToken()",
"type": "function",
"description": "Creates a signed JWT containing user ID and roles. Token expires in 24 hours by default.",
"location": {
"file": "src/utils/jwt.ts",
"startLine": 8,
"endLine": 22
}
}
],
"edges": [
{
"id": "e1",
"source": "login-route",
"target": "auth-service-login",
"type": "calls"
},
{
"id": "e2",
"source": "auth-service-login",
"target": "user-repo-find",
"type": "calls"
},
{
"id": "e3",
"source": "auth-service-login",
"target": "token-generate",
"type": "calls"
}
],
"layout": {
"direction": "TB"
}
}
Tell the user:
{filename}.cgraph+ button on a node to expand its descriptionSearch for places (restaurants, cafes, etc.) via Google Places API proxy on localhost.
Interact with GitHub using the `gh` CLI. Use `gh issue`, `gh pr`, `gh run`, and `gh api` for issues, PRs, CI runs, and advanced queries.
Create or update AgentSkills. Use when designing, structuring, or packaging skills with scripts, references, and assets.
Start voice calls via the OpenClaw voice-call plugin.
Notion API for creating and managing pages, databases, and blocks.
Gemini CLI for one-shot Q&A, summaries, and generation.
Category:developer