Documentation menu
Getting started
Dashboard & analytics
Managed runners
Team & notifications
Billing & plans
Workflow files
Latchkey CLI commands
Every Latchkey CLI command in one reference: what it does, its usage, its main flags, what it prints, how it exits, the API key scope it needs and the first release that has it.
In short
- One section per command: its usage line, the flags you will use, what it prints, its exit codes, the API key scope it needs and the first CLI release that has it.
latchkey help <command>prints the same usage from the CLI you have installed, andlatchkey versionprints which release that is.- Remote commands take
--token,--api-urland--output json.latchkey cache,latchkey artifactandlatchkey oidcrun inside a job and talk to its runner instead. - A key holds only the scopes picked when it was created: reads need
jobs:read, starting and cancelling jobsjobs:run, and secrets, migrations and workflow runs each have a scope of their own.
This page is the reference for each command of the Latchkey CLI (@latchkeydev/cli). Run one-off jobs from the CLI is the guide: installing, logging in, running a job and what ships with it. What each release added, changed and fixed is in the Latchkey CLI changelog, and a section here names the first CLI release a command or flag needs when that release came after 0.3.0. latchkey help <command> and latchkey <command> --help print a command's usage from the CLI you have installed, and latchkey version prints its version.
What every command shares#
| Option | What it does |
|---|---|
--token <key> | The API key, which overrides LATCHKEY_TOKEN and the saved login |
--api-url <url> | The API base URL (default https://api.latchkey.dev) |
--output <mode> | json or text (default text) |
-h, --help | Print the command's usage and exit 0 |
Authentication resolves --token, then the LATCHKEY_TOKEN environment variable, then the config file latchkey login wrote. With --output json, a one-shot command prints one JSON object and a streaming command prints NDJSON, one event object per line, and a refused command also prints one object with its code on stdout. Every command exits 2 on a usage error (an unknown command or flag, or an invalid value) and 1 on an operational error (authentication, the network, or the API refusing or failing); the sections below give the other codes a command exits with. latchkey cache, latchkey artifact and latchkey oidc work only inside a job: they talk to the job's runner, not to the Latchkey API, so they take no --token, --api-url or --output.
| Scope | What it lets a key do |
|---|---|
jobs:read | Read jobs, their logs, batches and runs: status, logs, list, wait, batch show, budget show, environments list, schedule ls, validate and workflows list |
jobs:run | Start and cancel jobs and set batch budgets: run, cancel, budget set and preflight. A key created with it also holds jobs:read |
secrets:write | Set workspace and repository secrets: secrets set |
migration:apply | Open a migration pull request: migrate apply |
workflows:run | Start a workflow file on demand: workflows run |
runs:control | Re-run and cancel Latchkey CI runs: workflows rerun and workflows cancel |
workflows:propose | Propose a workflow change: workflows propose |
Every key also carries mcp:read, the only scope latchkey watch, latchkey steps, latchkey migrate plan and latchkey migrate status need. An owner or admin picks a key's scopes when creating it in Settings, API keys and agents: the CLI runner access gives jobs:run and jobs:read, and an existing key never gains a scope later. latchkey login saves a key without jobs:read only with --force; or pass such a key as LATCHKEY_TOKEN.
latchkey login#
Validates an API key against the API, without starting anything billable, and saves it for this machine in ~/ (mode 0600). With no --token, it prompts for the key on a terminal with hidden input, and without a terminal it exits 2. On success it prints Logged in. Key <key> saved to <file>., the key shown only as its first eight and last four characters. --force saves a key the API refused for a reason other than authentication, such as a key without the jobs:read scope. --api-url saves the URL with the key. Run one-off jobs from the CLI walks through creating the key.
latchkey run#
Packs a directory into a context archive, starts a job on a fresh runner, streams its logs, and exits with the job's exit code. Flags come before the command: everything from the first word that is not a flag, or after --, is the command line the runner runs. Its flags, what ships with the job and how to split a suite across runners are on Run one-off jobs from the CLI. It needs the jobs:run scope. --budget (exit 3), a skipped job's exit 1 and the 193 refusal at a batch's budget need CLI 0.4.0, and the 130 for a job whose run was rejected for its environment needs 0.5.0. Its exit code, and that of latchkey logs --follow, is the job's outcome:
| Outcome | Exit code |
|---|---|
| Succeeded | The job's exit code, normally 0 |
| Failed | The job's exit code, or 1 when that is 0 or unknown |
| Failed, because an owner or admin rejected its run for its environment | 130 |
Stopped at its --budget | 3 |
| Cancelled | 130 |
| Expired before it started | 124 |
| Skipped, so no command ran | 1 |
| Refused at its batch's budget, so no job was created | 193 |
latchkey status and latchkey logs#
latchkey status shows one job: its state, runner size, timeout, whether a cancel was requested, its exit code and failure reason, and when it was created, submitted, started and completed. When the server sends them, it adds rows for the workspace's running and queued jobs against its limit, the jobs ahead of a queued job and why it waits, what holds the concurrency group a held job waits on, the size's rate a minute, a running job's cost so far or a finished job's cost at list rate, its batch, key and budget, when it last wrote output, and a Self-heal row for each self-heal attempt that fixed a failure or could not. It exits 0, and 1 when the workspace has no such job.
latchkey logs without --follow prints the log available now, from chunk --cursor (default 0), and exits 0. With --follow it tails the job to completion and exits with the job's outcome, as latchkey run does. A tail that keeps hitting transient errors gives up on the log, not the job: it reads the job once more and reports its outcome if it has finished, and a job still running then exits 1. Logs stay readable for 30 days from when the job started; past that the command says they are no longer kept and exits 1.
Both need the jobs:read scope. The Cost row for a finished job needs CLI 0.6.0, the Self-heal rows 0.10.0, and the Held by, Holder started and Holder ends rows 0.20.0.
latchkey list#
Lists the workspace's jobs, newest first, including the ones still running, which show no duration and no exit code yet. It is how a job id that scrolled out of a terminal is found again. It reads Latchkey's durable records rather than live job state, so it outlives the roughly 24 hours in which latchkey cancel answers for a job, and for the same reason shows less than latchkey status: no timeout and no pending cancel. It needs the jobs:read scope.
| Flag | What it does |
|---|---|
--batch <name> | Only the jobs created in this batch. It never reads LATCHKEY_BATCH |
--before <value> | Only the jobs queued before this: a job id, a time, or the next_before of an earlier page |
--limit <n> | Jobs to return, 1 to 100 (default 20) |
--state <state> | active lists only the jobs queued, provisioning or running, up to 100, and takes neither --before nor --limit; all, the default, lists every job |
Text output is a table with the columns JOB, STATUS, SIZE, BATCH, KEY, DURATION, COST, COMMAND and QUEUED, then a line under it for each job that ended for a reason Latchkey can explain. COST is a finished job's cost, or a running job's cost so far, at list rate before free minutes. With no jobs it prints No jobs. on stderr. With --output json it prints one object with a jobs array and next_before: run the same command with --before <next_before> for the next older page, until it is null. With --state active the object holds jobs and truncated instead, true when more than 100 jobs were on their way, and in text a line on stderr says so. --batch, --before and the COST column need CLI 0.6.0, and --state needs 0.13.0.
latchkey cancel#
Requests a job's cancellation. A job not yet submitted, or still held in the queue, is cancelled at once, and the command prints Job <id> cancelled. Any other job still in progress has its cancel flag set, and the runner honors it within about 10 seconds; the command says so, with the job's current state. A job already in a terminal state cannot be cancelled: the command prints the server's message and nothing to cancel., and exits 1. Cancel answers for a job for about 24 hours after it finishes. It needs the jobs:run scope. To cancel every job of a Latchkey CI run at once, use latchkey workflows cancel.
latchkey wait#
Waits for jobs, a batch or Latchkey CI runs to end, then summarizes each outcome. It reads the jobs you name, or with --batch the jobs the batch holds when the wait starts, on one shared interval, and prints each job's outcome line as it ends. When the last one ends, it prints a table of each job's state, exit code, run time, cost and batch (JOB, STATE, EXIT, RUN TIME, COST, BATCH), and exits 0 when every job's exit code is 0, and 1 when any has another or when it stopped waiting early. --batch never reads LATCHKEY_BATCH. Ctrl-C stops the wait, never a job or a run.
--commit and --pr wait on Latchkey CI runs instead, in the repository --repository names: the runs at a commit, named by its full id, or a pull request's runs at its newest commit. When they end, it prints a table of them and exits 0 when each one succeeded or was skipped, and 1 otherwise. --through <workflow> with --pr follows the pull request past its merge: its runs, then the commit it landed as, then that commit's runs of the workflow file named, such as deploy.yml. A wait on runs can also exit with these codes:
| Exit code | When |
|---|---|
| 194 | The repository is not connected to Latchkey CI, or every run it follows ended with no job because no workflow file matched (RUN_NOT_EXPECTED) |
| 196 | Every run passed, and one still owes its full suite: a job of it was skipped because no change reached it, so its check asks for a full run of the commit before merge (full_run_owed) |
| 197 | Its last look before it gave up met Latchkey's limit on the waits it holds for a workspace at once (RUN_WAIT_LIMIT_REACHED) |
| 198 | With --through, the pull request was last closed without being merged, merged with no record of the commit it landed as, or had no merge recorded by an hour after its runs ended or the wait began, whichever was later (PULL_REQUEST_NOT_LANDED) |
| 1 | A run did not pass, no run it follows was recorded in ten minutes, the commit holds more than 50 runs besides scheduled runs that began after the wait began, or, with --through, a run at the landing commit or at the commit of the push that carried it had not planned by ten minutes after it last changed or the wait began, whichever was later (WAIT_TRUNCATED) |
It needs the jobs:read scope, and a wait on runs is not counted against the API key's read limit. With --output json it prints one ended event per job as it ends, then a summary event; a wait on runs prints one run_ended event per run in place of ended. latchkey wait needs CLI 0.6.0, --commit and --pr need 0.15.0, and --through needs 0.19.0. Exit 196 needs CLI 0.22.0; an older CLI exits 1 there.
latchkey cache#
Restores or saves one cache entry from inside a job, so a dependency directory survives to the next job. It talks to the cache proxy on the job's runner, not to the Latchkey API, so it needs no API key, and it works only inside a Latchkey CI job or a latchkey run job, where the runner exports LATCHKEY_CACHE_URL. Anywhere else, a GitHub Actions job on a Latchkey managed runner included, it prints that the cache is unavailable and exits 0. The CLI is not on the runner image, so the job installs it first (npm install -g @latchkeydev/cli). It needs CLI 0.4.0.
| Flag | What it does |
|---|---|
--key <key> | The entry name (required), used as written: no derivation and no fallback keys |
--version <version> | The entry version (required); a different version is a different entry |
--into <dir> | restore only: the directory to extract into, created if needed (default: the working directory) |
--from <dir> | save only: the directory the saved paths are relative to (default: the working directory) |
restore prints cache restored: <key> (<n> bytes), or on a miss cache miss: <key> (version <version>). save prints cache saved: <key> (<n> bytes), and on a key that already holds an entry, which it never overwrites, cache entry already exists: <key> was not overwritten. A saved tree may not hold a symlink that points outside the directory being saved, which makes a stock virtualenv uncacheable.
No cache condition fails the job: a miss, a cache error, a read-only cache and a runner with no proxy all exit 0. It exits 2 on a usage error, such as a missing --key or --version, a save with no paths or a path outside the directory being saved, and 1 on an unexpected local error, such as a scratch directory it cannot create.
latchkey secrets#
Sets a secret that a step of a workflow file reads as ${{ secrets.<name> }}, for the whole workspace or, with --repository, for one of its repositories. set is its only subcommand. The value comes from standard input when it is piped, with one trailing line ending removed, or from a hidden prompt on a terminal. It is never taken from the command line, never printed, and sent once: a failed set is not retried. A value can be up to 48 KiB, and setting a name again replaces its value with a new version.
It prints Set <name> for the workspace (version <n>)., or with --repository the repository in place of the workspace, and exits 0. It needs the secrets:write scope (Allow setting workspace secrets), which no other scope implies. A key that can only set secrets cannot read jobs, so latchkey login saves it only with --force; or pass it as LATCHKEY_TOKEN. It needs CLI 0.4.0. A job started with latchkey run holds no stored secrets: pass it values with --env.
latchkey budget#
set sets the budget of a batch of jobs in US dollars, with at most two decimal places. Once the batch's jobs have cost that much at list rates, Latchkey refuses to create another job in it and holds its queued jobs; jobs already running finish. An API key can set a batch's first budget, up to the workspace's spend limit, or lower it, and never raise it: a raise is refused (exit 1), and a workspace owner or admin raises a budget on the Billing page. --max-concurrent <n> also limits how many of the batch's jobs run at once, a whole number from 1 to 1000, and the rest wait in the queue; a key can set the first limit or lower it, never raise it. set needs the jobs:run scope.
show prints the batch's budget and what its jobs have cost at list rates, and changes nothing; it needs the jobs:read scope. A batch name is 1 to 64 characters with no / or %, and not . or .. alone. A latchkey run refused at its batch's budget exits 193 and creates no job. latchkey budget set needs CLI 0.4.0, budget show needs 0.6.0, and --max-concurrent needs 0.10.0.
latchkey batch#
Shows one batch of the workspace's jobs: its budget and what its jobs have cost at list rates, how many are in each state, why its queued jobs wait, and its jobs, newest first, as latchkey list prints them, paged with --before and --limit as list pages. It changes nothing. A name with no jobs and no budget exits 1. It needs the jobs:read scope and CLI 0.6.0.
latchkey steps and latchkey validate#
latchkey steps lists the Latchkey steps a workflow file can name with uses: latchkey/<name>@<version>, each at its newest version: the uses: value to write, what the step does, and each input marked required, optional or with its default, then its rule. --output json gives every published version with its digest and outputs, the same answer as the MCP tool list_latchkey_steps. Any API key can run it. It needs CLI 0.5.0.
latchkey validate checks a workflow file as Latchkey compiles it for a run, without starting anything. A refused file prints its first refusal on stderr as <file>:<line>: <sentence> (<code>), the sentence a push would get, and exits 1. A file that compiles prints one line per job, one per matrix leg, with its key, where it runs, its timeout, the jobs it needs, its environment and its name, then the most one run of them can cost at list rates: each job's timeout plus a minute, once. That is a ceiling, not a forecast. It checks the file alone, so a secret, an environment's branches and the key a map of branches chooses are checked when a run starts. A file over 128 KiB is refused before anything is sent.
latchkey validate exits 0 when the file compiles. It needs the jobs:read scope and CLI 0.9.0, and --output json gives the same answer as the MCP tool validate_workflow.
latchkey preflight#
Runs the jobs of one workflow file, as Latchkey compiles it, on your working tree as it is now, before you commit or push it. The repository is packed whole from its top level by the rules of latchkey run, and the change is measured against the merge base of HEAD and the default branch origin/HEAD names, as this clone last fetched it. A preflight paints no check, opens no pull request, starts no self-heal, saves no cache entry, and is handed no secret, identity token or clone credential, so a job that needs one is not run, with its reason. --only-failed-from <run> runs only what did not succeed in an earlier run of the file. It needs the jobs:run scope, a repository connected to Latchkey CI, and CLI 0.16.0, or 0.19.0 for --only-failed-from.
| Exit code | When |
|---|---|
| 0 | No job failed, none was left not run, and a job ran |
| 195 | It left a job not run, or ran no job, and every job it ran passed or was skipped by its own condition or for a job it needs |
| 193 | The batch had already spent its budget, so nothing was started |
| 197 | Latchkey already held the most waits it holds for the workspace at once, so the CLI stopped following; the preflight goes on running |
| 1 | A job failed, was cancelled or timed out, Latchkey ended a job or the run for a reason that is not the change's (it concluded neutral), Latchkey's answer listed only some of its jobs or did not say how it concluded, or the preflight did not get going |
latchkey artifact#
Passes files between the jobs of one Latchkey CI run: upload packs the paths into one artifact under the name, and download fetches and extracts an artifact that a job this job needs uploaded. Like latchkey cache, it talks to the job's runner rather than the Latchkey API, so it needs no API key and the job installs the CLI first, and it works only inside a job of a Latchkey CI run. In a workflow file, the latchkey/artifact-upload and latchkey/ steps do the same without installing the CLI. It needs CLI 0.5.0.
| Flag | What it does |
|---|---|
--name <name> | The artifact name (required): letters, digits, ., _ and - |
--from <dir> | upload only: the directory the uploaded paths are relative to (default: the working directory) |
--include-hidden-files | upload only: also upload files and directories whose names start with a dot, such as .git and .env, which an upload leaves out by default |
--into <dir> | download only: the directory to extract into (default: the working directory) |
It prints artifact uploaded: <name> (<n> bytes) or artifact downloaded: <name> (<n> bytes) and exits 0. Unlike latchkey cache, a failed upload or download prints its reason and exits 1, so the step fails. It exits 199 when the store refuses it because the job is a job of a preflight, which cannot upload or download artifacts, and 2 on a usage error. Exit 199 needs CLI 0.18.0; an older CLI exits 1 there.
latchkey oidc#
Gets a short-lived identity token for one audience from inside a job of a Latchkey CI run, so the job can sign in to your cloud with no stored key. The audience is the name your cloud expects in the token's aud claim, such as sts.amazonaws.com: 1 to 255 visible ASCII characters with no space, passed as written. It prints the token alone on stdout, or with --out <file> writes it to a file only its owner can read (mode 0600), and never through a link. The token never goes to stderr, and the runner hides it in the job's log.
Like latchkey cache, it talks to the job's runner, needs no API key, and the job installs the CLI first. Only a job of a Latchkey CI run that runs your repository's own commit gets a token; a job of a pull request from a fork has no way to ask. It exits 0 when the token was printed or written, 1 when there is no token or it could not be written, with the reason printed, and 2 on a usage error. It needs CLI 0.9.0. On AWS, the latchkey/aws-login step signs in without installing the CLI.
latchkey environments#
Lists the branches each environment of one repository accepts, and whether its jobs wait for an approval in runs on them, as a table with the columns Environment, Branches, Approval and Set at; Approval reads Required or Not required. An owner or admin sets both in the dashboard, under Settings, Environments; no API key can. An environment it does not list accepts every branch, and its jobs always wait for an approval. list is its only subcommand. It needs the jobs:read scope and CLI 0.6.0, and the Approval column needs 0.9.0.
latchkey schedule#
Lists what holds the workspace's jobs now and what its schedules start next, the answer the get_schedule MCP tool gives. First the held jobs, the longest wait first, in a table with the columns JOB, REASON, HOLDER, ENDS OR RESETS and REPOSITORY: the code of the reason each waits, the job or run holding a job's concurrency group (not read when the answer had already read as many holders as one answer reads, not known when Latchkey has no reading of the group's holder), and about when that holder ends or when the spend limit or included minutes holding the job reset, or none. latchkey status <job-id> gives a held job's reason in words. A job waiting for an approval (JOB_AWAITING_APPROVAL), one approved and waiting until Latchkey can read the branches its environment accepts (JOB_AWAITING_BRANCH_CHECK), and one waiting for the jobs it needs are not listed: only the jobs still in line and the jobs parked in a concurrency group are. Then each cron of each repository's default branch with a fire inside the horizon, in a table with the columns REPOSITORY, FILE, CRON, NEXT FIRES (UTC) and MORE: at most 12 fires a cron, and how many more. --horizon <hours> sets the horizon, a whole number of hours from 1 to 168 (default 24). Every fire is approximate: it can start up to 30 minutes late or be skipped.
A Gate line says once whether the workspace's schedules start runs: allowed, refused or decided at fire time. An Undecided line names a repository whose default branch holds no schedule while another branch does, which lists no fire, and a line says when more than 100 jobs are queued, when the job store could not be read and when the read reached its bound. With --output json it prints the server's object as it came. It changes nothing, and needs the jobs:read scope and CLI 0.21.0. It exits 0 when it printed the answer, 1 when Latchkey refused the request or could not be reached, and 2 on a usage error.
latchkey migrate#
Plans a repository's move from GitHub Actions to Latchkey CI and opens the pull request for it; the repository must be connected to Latchkey CI in this workspace. plan reads the GitHub Actions workflow files at the head of the default branch and prints the migration plan: for each pipeline, whether it moves, and each step, job or change that needs a person's answer. --answers <file> passes a JSON file of answers and moves, in the shape the plan names them. The plan is saved on this machine with the answers and moves it was made with, so apply needs only its id, and --output json prints the plan exactly as Latchkey serves it.
apply opens the one pull request that adds the plan's Latchkey CI workflow files, once every item that needs a person has an answer, and closes the open pull request of any earlier apply of the repository; a person merges it. It is sent once: if its answer is lost, run status before applying again. status shows the repository's newest migration pull request and where it stands: open, merged, closed, or superseded by a newer apply.
plan and status take any API key. apply needs the migration:apply scope (Allow opening migration pull requests), which works only while the person who created the key is an owner or admin. It exits 0 when the plan was printed and saved, or the pull request or the status was printed; 1 when Latchkey refused the request or could not be reached, an apply's answer was lost, or the saved plan could not be read or written; and 2 on a usage error or a plan id this machine has no saved plan for. It needs CLI 0.5.0.
latchkey workflows#
run starts a run of one Latchkey CI workflow file that declares on: workflow_dispatch, on a branch or tag of a repository connected to Latchkey CI; <workflow> is the file's name, such as deploy.yml, or its whole path. --ref picks the branch or tag (default: the repository's default branch), and each --input <name=value> reaches every job as LATCHKEY_INPUT_ and its name in capitals, with - written as _. An input is recorded on the run and shown on its page, so never put a token or password in one. It does not wait: exit 0 says the run started, and running the command again starts a second run, billed as its own. It needs the workflows:run scope.
list prints the Latchkey CI runs of a commit, named by its full id, or of a pull request over the last 90 days, newest first; with more than 50 runs it exits 1 unless --allow-truncated takes the newest 50. It needs the jobs:read scope. rerun runs the jobs of a finished run that did not pass again, with every job that needs one of them, as a new attempt of the same run, and cancel cancels every job of the run's current attempt that has not finished. Both take the run id and its repository, and need the runs:control scope.
propose sends the text of one local workflow file to Latchkey as a change to the repository's file at --path (by default the file's own path under .latchkey/workflows/, else its name there). Latchkey checks that it compiles, compares its plan with the default branch's, and prints the sensitive changes and the change in cost per run; it opens nothing unless --open-pr is given, and then opens a pull request from a branch of its own, or prints the pull request it already has open for the same path, the same text and the same default-branch commit, for a person to merge. --try first runs latchkey preflight with that file on your working tree, on runners billed like any job's, and proposes only when it passes, so the key must also hold jobs:run. It needs the workflows:propose scope.
The workflows:run and runs:control scopes work only while the person who created the key is in the workspace, and workflows:propose only while that person is an owner or admin. Each subcommand exits 0 when it did what it says, 1 when Latchkey refused the request or could not be reached, or when the preflight propose --try ran did not pass, and 2 on a usage error. run needs CLI 0.10.0, list needs 0.15.0, rerun and cancel need 0.17.0, and propose needs 0.22.0.
latchkey watch#
Polls Latchkey for CI failures self-healing recorded but did not fix, and hands the first new one of each job (of each run on Latchkey on GH) to your coding agent: claude by default, or the command --agent names. The first poll records what is already failing without handing anything off. --once polls once, prints what is failing and exits 0, never starting an agent; --no-spawn prints new failures without running one; --interval sets the seconds between polls, 5 to 86400 (default 15); and --repository <owner/name> watches one repository. Any API key can run it. Run one-off jobs from the CLI shows it running.