# gh cache delete: Prune Actions Caches in CI

> gh cache delete removes a GitHub Actions cache by key or ID, or all of them. Reference for --all, --succeed-on-no-caches, and the permission errors in CI.

Source: https://latchkey.dev/learn/command-reference/gh-cache-delete  
Updated: 2026-06-30

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.

## Common usage

```Terminal
gh cache delete node-modules-abc123
gh cache delete 42
gh cache delete --all
gh cache delete --all --succeed-on-no-caches
```

## Flags

| Flag | What it does |
| --- | --- |
| <cache-key | cache-id> | The cache to delete |
| -a, --all | Delete every cache in the repository |
| --succeed-on-no-caches | Exit 0 even when there are no caches to delete |
| -R, --repo <owner/repo> | Target a specific repository |

## 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.

## 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@v4
  with:
    fetch-depth: 0   # history, tags, and git describe all need this

- run: |
    git rev-parse --is-shallow-repository   # expect false
    git rev-parse --abbrev-ref HEAD          # prints HEAD when detached
```

> `git rev-parse --abbrev-ref HEAD` returns the literal string `HEAD` on a detached checkout rather than a branch name. On GitHub Actions read `github.ref_name` instead; the git command cannot know what it was checked out for.

## FAQ

### 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.

---

Latchkey runs CI/CD that repairs its own failures. Agent entry points: https://latchkey.dev/agent.txt, https://latchkey.dev/openapi.json, https://latchkey.dev/llms.txt
