Skip to main content
The moon task-graph [target] (or moon tg) command generates and serves a visual graph of all configured tasks as nodes, with dependencies between them as edges. The graph can be viewed in a browser or exported to Graphviz DOT format or JSON.
$ moon task-graph
This command is essential for understanding task execution order, identifying bottlenecks, optimizing parallel execution, and debugging dependency issues.

Synopsis

moon task-graph [target] [OPTIONS]

Arguments

  • [target] - Optional task target to focus the graph on (e.g., app:build). When specified, only shows the focused task and its dependencies.

Options

OptionTypeDefaultDescription
--dependentsbooleanfalseInclude direct dependents of the focused task
--dotbooleanfalsePrint the graph in DOT format
--jsonbooleanfalsePrint the graph in JSON format
--hoststring127.0.0.1The host address for the web server
--portnumber0The port to bind to (0 = random available port)
--host and --port options

Example output

Interactive visualization

By default, the command starts a local web server that displays an interactive graph:
$ moon task-graph
Task graph server started at http://127.0.0.1:58234
Press Ctrl+C to stop the server
Open the URL in your browser to view the interactive graph with features like:
  • Zoom and pan
  • Click nodes to see task details
  • Hover to see dependency information
  • Color coding by task type
  • Critical path highlighting
  • Execution time estimates

DOT format output

Export the graph in Graphviz DOT format for external visualization:
$ moon task-graph --dot
digraph {
    0 [ label="types:build" style=filled, shape=oval, fillcolor=lightblue, fontcolor=black]
    1 [ label="types:typecheck" style=filled, shape=oval, fillcolor=lightgreen, fontcolor=black]
    2 [ label="runtime:build" style=filled, shape=oval, fillcolor=lightblue, fontcolor=black]
    3 [ label="runtime:typecheck" style=filled, shape=oval, fillcolor=lightgreen, fontcolor=black]
    4 [ label="website:build" style=filled, shape=oval, fillcolor=lightblue, fontcolor=black]
    5 [ label="website:typecheck" style=filled, shape=oval, fillcolor=lightgreen, fontcolor=black]
    2 -> 0 [ label="required" arrowhead=box, arrowtail=box]
    3 -> 1 [ label="required" arrowhead=box, arrowtail=box]
    4 -> 2 [ label="required" arrowhead=box, arrowtail=box]
    5 -> 3 [ label="required" arrowhead=box, arrowtail=box]
}

JSON format output

Export the graph structure as JSON:
$ moon task-graph --json
{
  "nodes": [
    {
      "id": "runtime:build",
      "label": "runtime:build",
      "type": "build",
      "project": "runtime",
      "task": "build"
    },
    {
      "id": "types:build",
      "label": "types:build",
      "type": "build",
      "project": "types",
      "task": "build"
    }
  ],
  "edges": [
    {
      "source": "runtime:build",
      "target": "types:build",
      "type": "required"
    }
  ]
}

Usage examples

View full task graph

Show all tasks and their dependencies:
$ moon task-graph

Focus on a specific task

Show only the dependencies of a specific task:
$ moon task-graph app:build
This is extremely useful for understanding what needs to run before a specific task.

Include dependents

Show both dependencies and dependents (tasks that depend on it):
$ moon task-graph app:build --dependents

Export to DOT file

Export and render with Graphviz:
$ moon task-graph --dot > graph.dot
$ dot -Tpng graph.dot -o graph.png
$ dot -Tsvg graph.dot -o graph.svg

Export to JSON for analysis

Analyze the graph structure programmatically:
# Count total tasks
$ moon task-graph --json | jq '.nodes | length'

# Find tasks with most dependencies
$ moon task-graph --json | jq '.edges | group_by(.source) | map({task: .[0].source, deps: length}) | sort_by(.deps) | reverse'

# Find tasks with no dependencies (can run first)
$ moon task-graph --json | jq '.nodes[] | select(.id as $id | [.edges[].target] | contains([$id]) | not) | .id'

Serve on custom host and port

$ moon task-graph --host 0.0.0.0 --port 8080
This makes the graph accessible from other machines on your network.

Understanding the graph

Node types

Nodes represent tasks and are color-coded by type:
  • Build tasks - Blue (compilation, bundling)
  • Test tasks - Green (unit tests, integration tests)
  • Run tasks - Yellow (general execution)
  • Setup tasks - Purple (initialization)

Edge types

Edges represent dependencies between tasks:
  • required - Task must complete before dependent can start
  • optional - Dependency runs if available but isn’t blocking
Edge labels indicate the dependency type.

Execution order

The graph visualization shows:
  • Serial execution - Tasks connected in a chain
  • Parallel execution - Tasks at the same depth without dependencies
  • Critical path - Longest chain determining total execution time

Focus mode

When focusing on a specific task:
  • The focused task is highlighted
  • Only its dependencies are shown by default
  • Use --dependents to also show tasks that depend on it
  • Useful for debugging “why does this task run?”

Common use cases

Debug task execution order

Understand why a task runs or doesn’t run:
$ moon task-graph app:deploy
This shows all tasks that must complete before deployment.

Identify bottlenecks

Find tasks that block parallel execution:
$ moon task-graph --json | jq '.edges | group_by(.target) | map({task: .[0].target, dependents: length}) | sort_by(.dependents) | reverse | .[0:5]'

Optimize CI pipelines

Visualize which tasks can run in parallel:
$ moon task-graph
Tasks at the same depth (level) in the graph can potentially run concurrently.

Verify task dependencies

Ensure tasks have the correct dependencies configured:
$ moon task-graph app:build
If expected dependencies are missing, update your task configuration.

Find circular dependencies

Circular dependencies will cause the command to fail with an error:
$ moon task-graph
Error: Circular dependency detected: app:build -> lib:build -> app:build

Performance insights

The interactive visualization provides:
  • Execution time estimates - Based on historical runs
  • Critical path analysis - Longest chain of dependent tasks
  • Parallelization opportunities - Tasks that could run concurrently
  • Cache hit rates - For tasks that have run before

Configuration

  • tasks in .moon/tasks/*
  • tasks in moon.*
  • Task dependencies defined via deps field in task configuration

Build docs developers (and LLMs) love