gh-cache
Manage GitHub Actions caches
TLDR
List caches for the current repository
List caches for a specific repository
List caches with a specific cache key prefix
List caches for a specific branch
List caches sorted by least recently accessed
Delete a cache by id
Delete a cache by key
Delete all caches
SYNOPSIS
gh cache list|delete [<repository>] [flags]
PARAMETERS
--all
Delete all caches (delete only)
--created <{YYYY-MM-DD}|{YYYY-MM-DD}..{YYYY-MM-DD}>
Filter by cache creation time
--hostname <string>
Hostname (delete only)
--key <string>
Filter by cache key
--limit <int>
Maximum number of caches (default 30)
--machine-readable
Emit JSON instead of table
--ref <string>
Filter by ref/branch (delete only)
--repo [<string>]
Repository (OWNER/REPO)
--scope <string>
Filter by scope (workflow/step)
--size <{<=N}|{>=N}|{N..M}>
Filter by size in MiB
--updated <{YYYY-MM-DD}|{YYYY-MM-DD}..{YYYY-MM-DD}>
Filter by last touched time
DESCRIPTION
The gh cache command from GitHub CLI manages caches used in GitHub Actions workflows for a repository. Caches accelerate workflows by reusing dependencies, build artifacts, and other files between runs.
It offers two subcommands: list to display caches with filters like creation time, size, or key; and delete to remove caches selectively or all at once.
Caches are scoped by repository, branch, workflow, and key. Listing shows details like size, creation/update times, and actions. Deletion supports bulk operations via flags like --all or filters.
Requires GitHub CLI installed and authenticated via gh auth login. Operates on current repo by default or specified OWNER/REPO. Useful for cleaning up unused caches to save storage and costs in large projects.
Supports machine-readable JSON output for scripting.
CAVEATS
Requires GitHub CLI ≥2.4.0 and repository write access. Caches auto-expire after 7 days of inactivity. Use cautiously with --all to avoid data loss.
EXAMPLES
gh cache list --limit 10
gh cache delete --key '::ff::' --repo owner/repo
gh cache list --size '>=100' --machine-readable
AUTHENTICATION
Run gh auth login first. Token needs repo or actions:write scopes.
HISTORY
Added in GitHub CLI 2.4.0 (Oct 2022) to address Actions cache management needs. Enhanced in later versions with more filters and JSON support.


