gh cache delete removes one Actions cache by key or ID, or every cache with --all.
Cleanup jobs delete stale caches to reclaim the per-repo storage limit and force a fresh restore on the next run.
What it does
gh cache delete removes a cache identified by its key or numeric ID. --all deletes every cache in the repository. It pairs naturally with gh cache list to find which keys to prune.
Set GH_TOKEN and permissions: { actions: write }. Without --succeed-on-no-caches, gh cache delete --all returns a non-zero exit when no caches exist, which can fail a cleanup job; add the flag for idempotent runs.
Common errors in CI
"Resource not accessible by integration" or "HTTP 403" means the token lacks actions: write. "no caches to delete" with --all exits non-zero unless you add --succeed-on-no-caches. A wrong key reports the cache was not found.
Using this in CI
CI checkouts are shallow and detached by default, which changes the answer this command gives you. Commands that read history, branch names, or tags need the checkout configured for it.
.github/workflows/ci.yml
- uses:actions/checkout@v4with:fetch-depth:0 # history, tags, and git describe all need this- run:|git rev-parse --is-shallow-repository # expect falsegit rev-parse --abbrev-ref HEAD # prints HEAD when detached
Frequently asked questions
gh cache delete: Prune Actions Caches in CI?
Cleanup jobs delete stale caches to reclaim the per-repo storage limit and force a fresh restore on the next run.
What it does?
gh cache delete removes a cache identified by its key or numeric ID. --all deletes every cache in the repository. It pairs naturally with gh cache list to find which keys to prune.
In CI?
Set GH_TOKEN and permissions: { actions: write }. Without --succeed-on-no-caches, gh cache delete --all returns a non-zero exit when no caches exist, which can fail a cleanup job; add the flag for idempotent runs.
Common errors in CI?
"Resource not accessible by integration" or "HTTP 403" means the token lacks actions: write. "no caches to delete" with --all exits non-zero unless you add --succeed-on-no-caches. A wrong key reports the cache was not found.