Skip to content

Variables

Use {{variable}} syntax to insert dynamic values anywhere in your commands.

Argument variables

Access user-provided arguments with {{args.name}}:

yaml
greet:
  args:
    - name: name
      description: Name to greet
  steps:
    - exec:
        command: echo "Hello, {{args.name}}!"
bash
x greet World
# Output: Hello, World!

Rest arguments

Use rest: true to capture all remaining arguments as a single string:

yaml
search:
  args:
    - name: query
      rest: true
  steps:
    - exec:
        command: grep -r "{{args.query}}" .
bash
x search hello world
# {{args.query}} = "hello world"

Step output variables

Previous step output

Use {{output}} to access the previous step's output:

yaml
steps:
  - exec:
      command: cat README.md
      silent: true
  - llm:
      prompt: "Summarize: {{output}}"

JSON field access

If a step outputs JSON, access individual fields with {{output.field}}:

yaml
steps:
  - llm:
      system: |
        Return JSON: {"command": "...", "summary": "..."}
      prompt: "{{args.task}}"
      silent: true
  - exec:
      command: "{{output.command}}"
      summary: "{{output.summary}}"
      confirm: true

This also works with named steps: {{steps.id.field}}

WARNING

If the output is not valid JSON, accessing a field will cause an error. Use {{output}} (without a field) for raw output.

Named step output

Give a step an id to reference its output specifically:

yaml
steps:
  - id: readme
    exec:
      command: cat README.md
      silent: true
  - id: changelog
    exec:
      command: cat CHANGELOG.md
      silent: true
  - llm:
      prompt: |
        README:
        {{steps.readme.output}}

        CHANGELOG:
        {{steps.changelog.output}}

Environment variables

VariableDescriptionExample
{{directory}}Current working directory/home/user/project
{{os}}Operating systemlinux, darwin, windows
{{arch}}CPU architectureamd64, arm64
{{shell}}User's shell/bin/bash, /bin/zsh
{{user}}Usernamejohn

Example:

yaml
info:
  steps:
    - exec:
        command: echo "OS: {{os}}, Arch: {{arch}}, Shell: {{shell}}"

Date and time variables

VariableDescriptionExample
{{date}}Current date2024-01-15
{{time}}Current time14:30:05
{{datetime}}Date and time2024-01-15 14:30:05

Example:

yaml
log:
  args:
    - name: message
      rest: true
  steps:
    - exec:
        command: echo "[{{datetime}}] {{args.message}}" >> log.txt

Using in different contexts

Variables work everywhere:

In exec commands

yaml
steps:
  - exec:
      command: echo "Running on {{os}} at {{datetime}}"

In LLM prompts

yaml
steps:
  - llm:
      system: |
        You are helping a user on {{os}}.
        Current directory: {{directory}}
      prompt: "{{args.question}}"

In OS-specific overrides

yaml
steps:
  - exec:
      command: cat {{args.file}}
      windows: type {{args.file}}

In subcommand args

yaml
steps:
  - subcommand:
      name: process
      args:
        - "{{args.file}}"
        - "{{output}}"

Variable reference

VariableSourceDescription
{{args.name}}User inputNamed argument value
{{output}}Previous stepRaw output from the previous step
{{output.field}}Previous stepJSON field from the previous step (errors if not JSON)
{{steps.id.output}}Named stepRaw output from a specific step
{{steps.id.field}}Named stepJSON field from a specific step
{{directory}}RuntimeCurrent working directory
{{os}}RuntimeOperating system (linux, darwin, windows)
{{arch}}RuntimeCPU architecture
{{shell}}RuntimeUser's default shell
{{user}}RuntimeCurrent username
{{date}}RuntimeCurrent date (YYYY-MM-DD)
{{time}}RuntimeCurrent time (HH:MM:SS)
{{datetime}}RuntimeCurrent date and time

Released under the MIT License.