---
title: Command Examples
description: General command, environment, and entrypoint patterns.
---

# Command Examples

The [`@os@1` package](../packages/os.md) can express project tasks even when no language package is involved.

## Run a Project Script

Paths containing a slash are resolved from project root:

```python
load("@os@1", "run")

run(("tools/check", "--all"))
```

On Windows, use forward slashes in build definitions when practical:

```python
run(("tools/check.exe", "--all"))
```

## Add a Project Tool Directory

Prepend a relative directory to virtual `PATH`, then use a bare command name:

```python
load("@os@1", "env_prepend", "run")

run(
    ("project-linter", "check"),
    deps=[env_prepend("PATH", "tools/bin", unique=True)],
)
```

xx resolves relative `PATH` entries from project root.

## Reuse an Environment

Combine dependencies into a named value:

```python
load("@os@1", "env_set", "env_unset", "run")

ci_env = (
    env_set("CI", "true") +
    env_set("MODE", "check") +
    env_unset("LOCAL_CONFIG")
)

run(("tools/lint",), deps=[ci_env])
run(("tools/verify",), deps=[ci_env])
```

Each command gets a separate environment clone. Applying `ci_env` to one task does not mutate another task or xx itself.

## Share Rules Between Entrypoints

Move repeated Starlark definitions into another file:

`.xx/rules.star`:

```python
load("@os@1", "env_set")

ci_env = env_set("CI", "true") + env_set("MODE", "check")
```

`.xx/check.star`:

```python
load("@os@1", "run")
load("rules.star", "ci_env")

run(("tools/check",), deps=[ci_env])
```

Loaded files must import their own built-in symbols. See [Loading files](../load.md) for relative imports, project-root imports, aliases, caching, and safety rules.

<!--
Sitemap

URL: https://withxx.dev/index.md
Title: xx
Description: Practical, reproducible builds without build-system ceremony

URL: https://withxx.dev/examples/commands.md
Title: Command Examples
Description: General command, environment, and entrypoint patterns.

URL: https://withxx.dev/examples/go.md
Title: Go Examples
Description: Common Go build patterns with managed SDKs.

URL: https://withxx.dev/examples/index.md
Title: Examples
Description: Common xx build and task patterns.

URL: https://withxx.dev/examples/nodejs.md
Title: Node.js Examples
Description: Common Node.js task patterns with a managed distribution.

URL: https://withxx.dev/load.md
Title: Loading Files
Description: Split xx configuration into local Starlark modules.

URL: https://withxx.dev/packages/go.md
Title: Go Package
Description: Provision an official Go SDK, run or install Go tools, and build Go binaries.

URL: https://withxx.dev/packages/nodejs.md
Title: Node.js Package
Description: Provision official Node.js distributions and run npm and npx tasks.

URL: https://withxx.dev/packages/os.md
Title: OS Package
Description: Run commands and construct isolated task environments.
-->
