> ## Documentation Index
> Fetch the complete documentation index at: https://docs.automate.ax/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> Automate.ax automations are TypeScript programs.
> Use Bun for installation and command examples.
> Use Automate.ax for the product name and automate.ax for the package, CLI, and domain.
> Treat documented public APIs as current; do not invent transitional or deprecated names.

# Route and scope work

> Conditionally materialize signals and make durable work wait for dependencies.

Routing operators choose which values and declarations can materialize in one context. They do not coordinate separate occurrences across contexts.

## `gate()`

`gate(value, condition)` emits `value` when `condition` emits `true` and closes when it emits `false` or closes. A failed condition fails the gate. The runtime decides the condition before materializing `value`, so a closed path does not wait for it.

```ts theme={null}
import { gate } from "automate.ax"

const isApiRequest = request.path.transform((path) => path.startsWith("/api/"))
const apiRequest = gate(request, isApiRequest)
```

`gate` preserves a keyed or global partition carried by `value`.

## `filter()`

`filter(signal, predicate)` emits the original value when the predicate returns `true` and closes otherwise. Type-guard predicates narrow the output type.

```ts theme={null}
import { filter } from "automate.ax"

const apiRequest = filter(request, ({ path }) => path.startsWith("/api/"))
```

`filter` is a value-preserving gate and retains the source's keyed or global partition.

## `partition()`

`partition(signal, predicate)` returns complementary paths. Exactly one emits the original value; the other closes.

```ts theme={null}
import { partition } from "automate.ax"

const [apiRequest, otherRequest] = partition(request, ({ path }) =>
  path.startsWith("/api/"),
)
```

Both outputs retain the source's keyed or global partition. Use `filter` when only one path matters and `branch` when each path declares different work.

## `scope()`

`scope(dependencies, section, options?)` makes every durable operation declared synchronously in `section` wait for one signal or a non-empty signal tuple. A directly returned signal also inherits the dependencies. Other return values pass through unchanged.

```ts theme={null}
import { scope } from "automate.ax"

scope(archived, () => {
  sendEmail({
    subject: "Message archived",
    text: "The message was archived successfully.",
  })
})
```

Use `scope(section, options?)` when only an isolated durable hook namespace is needed. Options accept `name` and `presentation: "collapsed" | "expanded" | "hidden"`. Named scopes default to collapsed; unnamed scopes default to hidden.

## `branch()`

`branch(condition, whenTrue, whenFalse?)` traverses complementary synchronous sections while making only the selected section ready.

```ts theme={null}
import { branch } from "automate.ax"

branch(
  isApiRequest,
  () => sendEmail({ subject: "API request", text: "Received." }),
  () => sendEmail({ subject: "Other request", text: "Received." }),
)
```

When both sections return signals, `branch` returns the selected result. With only a true section, its returned signal closes when the condition is false. `branch` composes complementary gates, scopes, and declaration-order fallback.

See [`fallback`](/reference/signals/select-and-time#fallback) for direct declaration-order selection and [cross-context coordination](/reference/signals/coordinate-occurrences) for joining separate occurrences.
