Manage your stacks and services with the CLI
Install and use the Stackhero CLI to manage your stacks and services from the command line, scripts, CI, and AI agents
Introduction
The Stackhero CLI is a lightweight, standalone command-line tool that enables you to manage your stacks and services directly from your terminal. You can use it to create and delete services, access credentials, update configurations, and perform many other routine tasks.
The CLI is compatible with Linux (glibc and musl), macOS, and Windows. It is distributed as a single binary of less than 3 MB, with no additional dependencies, making installation and updates straightforward.
Whether you are working interactively or automating workflows with scripts, CI pipelines, or AI agents, the Stackhero CLI is designed for both human users and automation. Every command supports the --format=json flag for machine-readable output, as well as --format=script if you want to capture raw values in shell variables.
Installation
You can install the latest version by running:
curl -fsSL https://www.stackhero.io/install.sh | sh
This command downloads the appropriate binary for your platform and installs it as stackhero. The CLI also keeps itself up to date automatically.
Interactive mode
Run stackhero with no arguments in a terminal, and the CLI opens a full-screen interface navigable with the keyboard. It is organised like your dashboard, so you can find your way immediately:
- Home: your organisations with their stacks, services, and available updates, as well as your account and the store.
- Updates: all services with a pending update, in a single list. Select one and press
Enterto install it. - Organisation and stack: their stacks and services, with the relevant actions, such as creating a stack or adding a service.
- Service: its status, CPU, RAM, and disk usage, and its logs, refreshed live, alongside the actions you can perform on it.
Every change requires confirmation first. At the bottom of the screen, the CLI always displays the equivalent command line: run an action once in interactive mode, then copy the command into your scripts.
Interactive mode starts only when there is a terminal and no argument. With an argument, in a pipe, in a CI job, or with an AI agent, the CLI behaves as a standard command-line tool. To see the list of commands, run stackhero --help.
Authentication
You have two main options for authentication:
Interactive browser-based login
stackhero login
When you run this command, the CLI provides you with a URL and also opens it automatically in your browser. From there, you can approve access directly from your Stackhero dashboard, where you are already signed in.
Two-factor authentication is fully supported, and you do not need to enter your password in the CLI.
Non-interactive authentication for scripts, CI, and automation
For automated workflows, you can create an access token in your dashboard under Account > Access tokens and provide it to the CLI via the STACKHERO_TOKEN environment variable.
export STACKHERO_TOKEN="usr-xxxxxx:your-token"
stackhero organizations-list
When STACKHERO_TOKEN is set, it takes precedence over interactive sessions, so a browser is optional. This method is ideal for non-interactive use cases. You can review and revoke your tokens from your dashboard at any time.
Output formats
Every CLI command accepts a global --format option:
human(default): Displays readable tables and text for interactive use.json: Returns machine-readable JSON, useful for scripts and AI agents.script: Returns only the raw value(s), making it easy to assign output to shell variables.
For example:
stackhero organizations-list --format=json
stackId=$(stackhero --format=script stack-create --name="My stack")
Commands overview
To see the full list of available commands, run stackhero --help. For details on a specific command, try stackhero COMMAND --help.
Some commonly used commands include:
- Organisations:
organizations-list - Stacks:
stacks-list(add--organizationto show the stacks of a specific organisation),stack-create,stack-rename,stack-delete - Services:
services-list(add--stackto show the services of a specific stack),service-get,service-add,service-wait-for,service-logs,service-metrics,service-rename,service-restart,service-delete - Configuration:
service-configuration-get,service-configuration-set,service-configuration-example - Firewall:
service-firewall-get,service-firewall-set - Version updates:
service-updates-list,service-update - Backups:
service-backups-list,service-backup-rollback - Store:
services-store-list,instances-store-list,regions-list - Upgrades:
service-upgrade-instances-store-list,service-upgrade-instance - Account:
login,logout,whoami - Maintenance:
self-update
Commands that restart, update, restore, or delete something require confirmation. In scripts, add --confirm to skip the prompt.
Example: Create a service end to end
Here is a sample script that demonstrates how to create a stack, add a service, wait for it to be ready, and retrieve its credentials. This example is fully non-interactive and uses the STACKHERO_TOKEN environment variable.
#!/bin/bash
set -e
export STACKHERO_TOKEN="usr-xxxxxx:your-token"
serviceStore="directus" # A service store name. See: `stackhero services-store-list`
instance="20" # An instance (size) name. See: `stackhero instances-store-list --service-store=directus`
region="europe" # A region name. See: `stackhero regions-list`
# Create a stack (uses your only organisation, add `--organization` if you have several)
stackId=$(stackhero --format=script stack-create \
--name="My stack")
echo "Stack: ${stackId}"
# Add a service (names are resolved automatically, and the stack ID above also works)
serviceId=$(stackhero --format=script service-add \
--stack="My stack" \
--service-store="${serviceStore}" \
--instance="${instance}" \
--region="${region}")
echo "Service: ${serviceId}"
# Wait for the service to be running
stackhero service-wait-for --service="${serviceId}"
# Retrieve credentials and configuration
stackhero service-configuration-get --service="${serviceId}" --format=json
Each service documentation page includes a ready-to-use Automate with the CLI guide tailored to that service, so you have everything you need to get started.
Start services for your CI tests
Your tests can run against a real Stackhero service instead of a mock: your GitHub Actions or GitLab CI pipeline adds the service, runs the tests, and deletes it when the run ends. It only takes a few lines:
- Create an access token and store it as the
STACKHERO_TOKENsecret in your CI. - Create a stack for your CI, once:
stackhero stack-create --name="CI". Each run adds its own service to it, so runs can safely overlap. - In the job, run
service-add, thentimeout 15m stackhero service-wait-for, thenservice-configuration-getto read the credentials. - In a step that always runs (
if: always()on GitHub Actions,after_scripton GitLab CI), runservice-delete --confirm. You are never billed for a service your tests no longer use.
Each database, cache, message broker, and search engine has a complete guide with ready-to-copy YAML for both platforms and a real smoke test. For example: PostgreSQL, MySQL, Redis, RabbitMQ, and Elasticsearch.
Example: Update a service to its latest version
service-updates-list shows your service version, available updates, and the severity of each one (normal, critical, or critical, internet blocked). Add --changelog to read what each version brings.
Some versions cannot be skipped, so updates are grouped into steps: each service-update installs the next step. This script applies each step, one after the other:
#!/bin/bash
set -e
service="My service" # A service name or ID. See: `stackhero services-list`
stackhero service-updates-list --service="${service}" --changelog
while [ "$(stackhero service-updates-list --service="${service}" --format=json | jq .steps)" != "0" ]; do
stackhero service-update --service="${service}" --confirm
stackhero service-wait-for --service="${service}"
done
Before an update, a backup of your service is taken automatically. If you need to roll back, stackhero service-backups-list --service="${service}" lists the backups, and stackhero service-backup-rollback --service="${service}" --backup=BACKUP_ID restores one.
Updating and uninstalling
The CLI keeps itself up to date automatically. If you ever want to force a manual update, you can run:
stackhero self-update
To uninstall the CLI, simply delete the stackhero binary from your system.