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.
YAML file format
Section titled “YAML file format”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.
Schema structure
Section titled “Schema structure”The schema has two parts:
- Config - The top-level object containing global settings and commands
- Command - Individual command definitions within the
commandsmap
Top-level fields
Section titled “Top-level fields”# Required: API version declarationahoyapi: v2
# Optional: Global environment file (v2.3.0+)env: .env
# Optional: Custom command interpreterentrypoint: - bash - "-c" - "{{cmd}}" - "{{name}}"
# Optional: Usage description for help textusage: "My project CLI commands"
# Required: Command definitionscommands: command-name: usage: Description cmd: command to runField specifications
Section titled “Field specifications”ahoyapi
Section titled “ahoyapi”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: v2Validation 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"env v2.3.0+
Section titled “env ”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: .envenv: .env.localenv: ../shared/config.envMultiple environment files v2.5.0+:
env: - .env.base - .env.local - .env.overrideOptional 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 absentTechnical 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-leveloptionalflag, which only covers imports - Maintains full backwards compatibility with single file syntax
entrypoint
Section titled “entrypoint”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’scmdvalue{{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
commands
Section titled “commands”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.
Command definition fields
Section titled “Command definition fields”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 doesdescription
Section titled “description”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 prodRequired: 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
aliases v2.2.0+
Section titled “aliases ”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 -dimports
Section titled “imports”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.ymlValidation 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
optionalis 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
env v2.3.0+
Section titled “env ”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.shMultiple environment files v2.5.0+:
commands: deploy: usage: Deploy application env: - .env.deploy - .env.staging - .env.secrets cmd: ./deploy.shOptional 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.shTechnical 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-leveloptionalflag, 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.shoptional v2.2.0+
Section titled “optional ”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.ymlComplete schema example
Section titled “Complete schema example”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!"Environment file format
Section titled “Environment file format”See the Environment variables reference.
Command execution context
Section titled “Command execution context”Commands have access to:
Positional arguments
Section titled “Positional arguments”$1,$2, etc.: Individual arguments$@: All arguments as array$#: Number of arguments$0: Command name
Environment variables
Section titled “Environment variables”- 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) v3AHOY_CMD- path to the ahoy binary (injected by Ahoy) v3
Special considerations
Section titled “Special considerations”File paths
Section titled “File paths”- All paths are relative to the YAML file location
- Environment file paths are also relative
- Import paths should use
./for current directory
Command override rules
Section titled “Command override rules”- Later commands override earlier ones
- Imported commands can be overridden
- Last definition wins
Environment variable precedence
Section titled “Environment variable precedence”Highest priority first:
- Command-specific env files
- Global env files
- Shell environment variables
Best practices
Section titled “Best practices”YAML file organisation
Section titled “YAML file organisation”# Start with versionahoyapi: v2
# Global configurationenv: .enventrypoint: [...]
# Group related commandscommands: # Development commands dev-start: usage: ... dev-stop: usage: ...
# Database commands db-backup: usage: ... db-restore: usage: ...Command naming
Section titled “Command naming”commands: # ✅ Good: Clear and descriptive db-migrate: usage: Run database migrations
# ❌ Bad: Unclear abbreviation dbm: usage: Run database migrationsUsage text
Section titled “Usage text”Keep usage to one short line and put anything longer in description. See description for an example.