# Examples
> End-to-end workflows — from a fresh checkout to an agent reasoning about your code.
[Source](https://open.nxtsoft.io/docs/cgraph/examples)

These are complete workflows, not isolated commands. Each starts from a built
CGraph (see [Installation](/docs/cgraph/installation)) and shows how the pieces
fit together in practice.

## Workflow 1 — Index a repository and ask the first questions

You've just cloned a service you don't know well and want an agent to help.

**1. Build the graph.**

**extract**

```bash
cgraph --root . --out cgraph-out
```

**2. Start the daemon so queries stay warm.**

**serve**

```bash
graphd --root .
```

**3. Ask what a symbol is and where it's used.**

**query + explain**

```bash
cgraph-client query   '{"q":"PaymentProcessor"}'
cgraph-client explain '{"q":"PaymentProcessor"}'
```

Instead of grepping the string `PaymentProcessor` across the tree, you get the
node and its role in the graph.

## Workflow 2 — Check a refactor before you make it

You're about to change a function's signature and want to know the blast radius.

**impact**

```bash
cgraph-client impact '{"q":"parseConfig"}'
```

`impact` returns the transitive set of nodes reachable from `parseConfig` — the
things that could break. You review that set *before* editing, not after the
tests fail.

Pair `impact` with `path` to understand *how* two parts connect:

```bash
cgraph-client path '{"from":"HttpServer","to":"Database"}'
```

## Workflow 3 — Give an agent budgeted context

An agent is working on a task and needs the relevant neighborhood around a node,
fit into its context window.

**adaptive, budgeted context**

```bash
cgraph-client context '{"q":"PaymentProcessor","budget":5000}'
```

With a query present, `context` uses adaptive gather — the full 2-hop core plus a
query-relevant third hop — and packs it to the 5000-token budget. The response's
`reach` counters show what was included and what was gated, so the selection is
auditable. See [Context Packing](/docs/cgraph/context-packing) for the mechanics.

## Workflow 4 — Keep the graph current during a session

While you work, the daemon folds edits in automatically. After a big change —
switching branches, say — it collapses into a single rescan. To force a refresh
or check state:

**update + status**

```bash
cgraph-client update '{"path":"."}'
cgraph-client status
```

`status` reports node and edge counts, cache hit rate, and enrichment state — a
quick way to confirm the graph is current before relying on it.

## The same, from an agent

Every command above has an MCP tool equivalent (`graph_query`, `graph_explain`,
`graph_impact`, `graph_path`, `graph_context`, `graph_update`, `graph_status`).
Once CGraph is registered (see [AI Agent Integration](/docs/cgraph/ai-agents)),
the agent runs these workflows itself — you just describe the goal.
