Skip to content

YAML Schema

Every field Ahoy supports in its YAML config files, with types, defaults and validation rules. The Implementation lines name the Go function that handles each field, for anyone reading the source.

Ahoy reads commands and settings from a YAML file. By default it looks for .ahoy.yml in the current directory, then in each parent directory. Use -f to point at a different file.

The schema has two parts:

  1. Config - The top-level object containing global settings and commands
  2. Command - Individual command definitions within the commands map
# Required: API version declaration
ahoyapi: v2
# Optional: Global environment file (v2.3.0+)
env: .env
# Optional: Custom command interpreter
entrypoint:
- bash
- "-c"
- "{{cmd}}"
- "{{name}}"
# Optional: Usage description for help text
usage: "My project CLI commands"
# Required: Command definitions
commands:
command-name:
usage: Description
cmd: command to run

Required: Yes
Type: String
Allowed values: v2
Default: None
Implementation: Validated in getConfig() function
Description: Specifies the Ahoy API version to use. Currently only version v2 is supported. This field is required in all Ahoy files including imported ones to ensure forward compatibility.

ahoyapi: v2

Validation rule: If this field is not set to v2, Ahoy will exit with an error.

Required: No
Type: String
Default: "Creates a configurable cli app for running commands."
Implementation: Set in setupApp() function
Description: A description of the whole command set, shown in Ahoy’s help text.

usage: "Collection of commands for the project"

Required: No
Type: String, Array of Strings, or Array of Strings and Mappings
Default: None
Implementation: Processed in getCommands() function
Description: Path(s) to global environment file(s), relative to the YAML file location. Variables defined here are available to every command in this file. Takes a single path or a list.

Single environment file (backwards compatible):

env: .env
env: .env.local
env: ../shared/config.env

Multiple environment files v2.5.0+:

env:
- .env.base
- .env.local
- .env.override

Optional environment files v3.0.1+:

An entry written as a mapping takes a path and an optional flag. Entries are required by default: a missing required file is reported on stderr, and a missing optional one is skipped quietly. You can mix both forms in one list.

env:
- .env.base # Required: warns when absent
- path: .env.local
optional: true # Silent when absent

Technical details:

  • Environment variables are loaded at runtime and passed to command processes
  • When using multiple files, they are loaded in order with later files overriding earlier ones
  • Blank lines and lines starting with ‘#’ are ignored
  • Variables from global files can be overridden by command-specific environment files
  • A non-existent file is skipped and the command still runs; from v3.0.1 it is reported on stderr unless that entry is marked optional: true. This is set per env entry, and is separate from the command-level optional flag, which only covers imports
  • Maintains full backwards compatibility with single file syntax

Required: No
Type: Array of Strings
Default: ["bash", "-c", "{{cmd}}", "{{name}}"]
Implementation: Default set in getConfig(), replacement in command action
Description: The interpreter and arguments used to run each command. The default is bash.

entrypoint:
- bash
- "-c"
- "{{cmd}}"
- "{{name}}"

Template variables:

  • {{cmd}}: Replaced with the command’s cmd value
  • {{name}}: Replaced with the command name

Implementation details:

  • Template variables are replaced at runtime before execution
  • The final command is executed with the working directory set to the directory containing the YAML file

Required: Yes
Type: Map of command definitions
Default: None
Implementation: Processed in getCommands() function
Description: Holds all command definitions. Each key is a command name, and its value is that command’s settings.

Validation rule: This field must be present and contain at least one command.

Each command under commands can have these fields:

Required: No
Type: String
Default: Empty
Implementation: Set in CLI command setup in getCommands()
Description: A one-line summary, shown in the command list and in ahoy help command-name.

commands:
example:
usage: Brief description of what this command does

Required: No
Type: String
Default: Empty
Implementation: Set in CLI command setup in getCommands()
Description: Longer help shown by ahoy help command-name, below the usage text. It can span several lines.

commands:
example:
usage: Deploy the application
description: |
Deploy the application to the specified environment.
This command will:
- Build the application
- Run tests
- Deploy to the target environment
- Send notifications
Arguments:
$1: Environment (dev|staging|prod)
$2: Version tag (optional)
Examples:
ahoy deploy dev v1.0.0
ahoy deploy prod

Required: Yes (unless using imports)
Type: String
Default: None
Implementation: Executed through the entrypoint in command action
Description: The command to run, on one line or several.

commands:
single-line:
cmd: echo "Hello"
multi-line:
cmd: |
echo "Starting..."
npm install
echo "Done!"

Technical details:

  • Executed through the configured entrypoint (default is bash)
  • Has access to environment variables from both global and command-specific env files
  • Working directory is set to the directory containing the YAML file

Required: No
Type: Array of Strings
Default: Empty
Implementation: Set in CLI command setup in getCommands()
Description: Other names that run the same command.

commands:
start-dev:
usage: Start development environment
aliases: ["up", "start"]
cmd: docker-compose up -d

Required: No (but required if cmd is not specified)
Type: Array of Strings
Default: None
Implementation: Processed in getSubCommands() function
Description: List of YAML files to import as subcommands. Paths are relative to the directory containing the current YAML file.

commands:
dev:
usage: Development commands
imports:
- ./commands/dev.ahoy.yml
- ./commands/docker.ahoy.yml

Validation rules:

  • Cannot be used together with cmd (must specify one or the other)
  • Must contain at least one item if specified
  • If the imports don’t resolve to valid files and optional is false, Ahoy will exit with an error

Implementation details:

  • Relative paths are resolved based on the parent YAML file location
  • Commands from the imported files become subcommands under this command
  • Imported files must also use ahoyapi: v2

Required: No
Type: String, Array of Strings, or Array of Strings and Mappings
Default: None
Implementation: Processed in command action
Description: Path(s) to command-specific environment file(s), relative to the YAML file location. Variables defined here override any with the same name from the global env files. Takes a single path or a list.

Single environment file (backwards compatible):

commands:
deploy:
usage: Deploy application
env: .env.deploy
cmd: ./deploy.sh

Multiple environment files v2.5.0+:

commands:
deploy:
usage: Deploy application
env:
- .env.deploy
- .env.staging
- .env.secrets
cmd: ./deploy.sh

Optional environment files v3.0.1+:

commands:
deploy:
usage: Deploy application
env:
- .env.deploy # Required: warns when absent
- path: .env.secrets
optional: true # Silent when absent
cmd: ./deploy.sh

Technical details:

  • When using multiple files, they are loaded in order with later files overriding earlier ones
  • Command-specific environment files always override global environment files
  • A non-existent file is skipped and the command still runs; from v3.0.1 it is reported on stderr unless that entry is marked optional: true. This is set per env entry, and is separate from the command-level optional flag, which only covers imports
  • Maintains full backwards compatibility with single file syntax

Required: No
Type: Boolean
Default: false
Implementation: Set in CLI command setup in getCommands()
Description: When true, the command is left out of the help output but can still be run.

commands:
internal-command:
usage: Internal command not shown in help
hide: true
cmd: ./internal-script.sh

Required: No
Type: Boolean
Default: false
Implementation: Checked in getCommands() function
Description: When true, a command whose imported files can’t be found is skipped instead of causing an error. It applies to imports and nothing else.

commands:
optional-group:
usage: Commands that may or may not be available
optional: true
imports:
- ./commands/optional.ahoy.yml
ahoyapi: v2
env: .env
entrypoint:
- bash
- "-c"
- "{{cmd}}"
- "{{name}}"
commands:
# Basic command
hello:
usage: Say hello to someone
description: |
A simple greeting command that demonstrates basic argument usage.
Arguments:
$1: Name to greet
cmd: echo "Hello, $1!"
aliases: ["hi", "greet"]
# Command with custom environment
db:
usage: Database operations
description: Connect to the database using credentials from environment file
env: .env.db
cmd: mysql -u$DB_USER -p$DB_PASS $DB_NAME
# Command with imports
dev:
usage: Development commands
description: Collection of development-related commands imported from external files
imports:
- ./dev.ahoy.yml
# Multi-line command
setup:
usage: Set up project
description: |
Complete project setup including dependency installation.
This command will:
- Install Node.js dependencies
- Install PHP dependencies via Composer
- Display completion message
cmd: |
echo "Installing dependencies..."
npm install
composer install
echo "Done!"

See the Environment variables reference.

Commands have access to:

  • $1, $2, etc.: Individual arguments
  • $@: All arguments as array
  • $#: Number of arguments
  • $0: Command name
  • Variables from the shell environment
  • Variables from global env files
  • Variables from command-specific env files
  • AHOY_COMMAND_NAME - the name of the command being run (injected by Ahoy) v3
  • AHOY_CMD - path to the ahoy binary (injected by Ahoy) v3
  • All paths are relative to the YAML file location
  • Environment file paths are also relative
  • Import paths should use ./ for current directory
  • Later commands override earlier ones
  • Imported commands can be overridden
  • Last definition wins

Highest priority first:

  1. Command-specific env files
  2. Global env files
  3. Shell environment variables
# Start with version
ahoyapi: v2
# Global configuration
env: .env
entrypoint: [...]
# Group related commands
commands:
# Development commands
dev-start:
usage: ...
dev-stop:
usage: ...
# Database commands
db-backup:
usage: ...
db-restore:
usage: ...
commands:
# ✅ Good: Clear and descriptive
db-migrate:
usage: Run database migrations
# ❌ Bad: Unclear abbreviation
dbm:
usage: Run database migrations

Keep usage to one short line and put anything longer in description. See description for an example.