# Sub-flow

> A flow that never starts by itself, run by other flows with values, handing values back.

Source: https://docs.buildcord.dev/nodes/triggers/sub-flow/

`trigger.subflow` runs when another flow calls it with [Run another flow](https://docs.buildcord.dev/nodes/flow-control/run-flow).

## Settings

| Setting | What it does |
| --- | --- |
| Inputs | What flows that run it give it, each with a name and what it is. Steps inside read each as `{input.name}`, and **Run another flow** offers them. |

## Ways out

`out`.

## Produces

`{input.name}` for each input it's given.

## Notes

- Use a sub-flow for steps that several flows share, such as logging a moderation action or charging a balance.
- End it with [Hand back](https://docs.buildcord.dev/nodes/flow-control/hand-back) to give values to the flow that ran it, read there as `{result.name}`.
- It also shares the run's values with whichever flow runs it: `{user.id}`, `{option.name}`, and anything set with `{temp.name}`.
- The caller continues when the sub-flow finishes.
- A sub-flow that no flow calls never runs, and the checker warns you.

## Example

A `Log moderation` sub-flow takes `action` and `reason`, adds a row to a collection and posts to a log channel. Each moderation command runs it as its last step, giving it `action: ban` and `reason: {option.reason}`.

## Related

- [Run another flow](https://docs.buildcord.dev/nodes/flow-control/run-flow)
- [Hand back](https://docs.buildcord.dev/nodes/flow-control/hand-back)
