Skip to content

Support --ref parameter in gh cache delete #11425

Closed

Description

@luxass

Describe the feature or problem you'd like to solve

The gh cache delete command currently lacks support for the --ref parameter to narrow the caches to delete down.

GitHub's REST API has support for the --ref query parameter: https://docs.github.com/en/rest/actions/cache?apiVersion=2022-11-28#delete-github-actions-caches-for-a-repository-using-a-cache-key

Proposed solution

Add a --ref flag to the gh cache delete command that accepts Git references in the same format as gh cache list --ref:

  • gh cache delete <key> --ref refs/heads/main
  • gh cache delete <key> --ref refs/pull/123/merge

Benefits:

  • Safer automated cleanup: CI workflows can clean up PR-specific caches without affecting other branches
  • Better cache management: Users can target specific branches for cache deletion
  • Consistency: Aligns the delete command with the list command's filtering capabilities

Additional context

I will gladly open a PR for this, if this is a welcoming change :)

Activity

  1. added
    enhancement
    on Jul 31, 2025
  2. github-actions commented on Jul 31, 2025

    @github-actions
    Contributor

    Thank you for your issue! We have categorized it as a feature request, and it has been added to our backlog. In doing so, we are not committing to implementing this feature at this time, but, we will consider it for future releases based on community feedback and our own product roadmap.

    Unless you see the help wanted Contributions welcome label, we are not currently looking for external contributions for this feature.

    If you come across this issue and would like to see it implemented, please add a thumbs up! This will help us prioritize the feature. Please only comment if you have additional information or viewpoints to contribute.

  3. added
    needs-triage
    on Jul 31, 2025
  4. changed the title [-]Support --ref parameter in gh cache delete[/-] [+]Support `--ref` parameter in `gh cache delete`[/+] on Aug 1, 2025
  5. self-assigned this
    on Aug 4, 2025
  6. added
    needs-investigation
    gh-cache
    on Aug 4, 2025
  7. babakks commented on Aug 4, 2025

    @babakks
    Member

    Hi @luxass, and thanks for the nice suggestion! 🙏

    I can see the value to this addition as it'll allow users to purge a specific piece of a cache entry.

    Please be aware that as with any enhancement a request to improve CLI issues, we need to discuss this internally and finalise an A/C for it. So, I'm going to lay out the context needed for discussion.

    Investigations

    It's a pretty straightforward change:

    • The ref query parameter is also supported on GHES v3.14 (if not earlier), so there's no feature detection required for this change.
    • The ref field is already present in the cache list --json output, so no need to touch that command.
  8. removed
    needs-investigation
    on Aug 4, 2025
  9. added
    help wanted candidate
    and removed
    needs-triage
    on Aug 11, 2025
  10. Cpoing commented on Aug 14, 2025

    @Cpoing

    Hi! I’d like to work on this as a first-time contributor if that’s okay.

  11. babakks commented on Aug 14, 2025

    @babakks
    Member

    Thanks for your interest in helping us, @Cpoing! 🙏

    However, the issue is not marked as help wanted Contributions welcome , which means the team has yet to decide if this should be picked up by our community. Please follow this issue for future updates.

  12. added
    help wanted
    and removed
    help wanted candidate
    on Aug 18, 2025
  13. added
    help wanted candidate
    and removed
    help wanted
    on Aug 18, 2025
  14. babakks commented on Aug 26, 2025

    @babakks
    Member

    @luxass @Cpoing I'm going to put down the A/C for this change and mark it as help wanted Contributions welcome . Since both of you folks have kindly expressed interest in submitting a PR for this, to avoid working in parallel, please comment here if any of you are going to work on this. 🙏

    Regardless of who is going to make the PR, I want to appreciate your help and your will to make gh better. ❤️

  15. babakks commented on Aug 26, 2025

    @babakks
    Member

    Acceptance Criteria

    1. Existing behaviour

    When I run gh cache delete <key> with a valid/existing <key>
    Then the cached data associated with the given <key> is deleted

    2. Delete with --ref

    When I run gh cache delete <key> --ref <ref> with a valid/existing <key> and <ref> values
    Then the cached data associated with the given <ref> and <key> is deleted

    3. Invalid --ref value

    When I run gh cache delete <key> --ref <ref> with an invalid <ref> value
    Then I get the error returned by the API call

    Note

    This is probably going to be done already. I'm just repeating to hint at that we don't need to perform client-side validation (as we don't in cache list). This is to make the experience consistent with the cache list command, and also keep gh forward-compatible if the API changes in favour of accepting non-full refs (e.g. a branch name or PR number). FWIW I've seen API endpoints that behave like this.

    4. Invalid option usages

    4.1. Use with no arg (i.e. cache key/ID)

    When I run gh cache delete --ref <ref>
    Then I get an error saying --ref cannot be used without cache key/ID

    4.2. Use with --all

    When I run gh cache delete --all --ref <ref>
    Then I get an error saying --ref cannot be used with --all

    5. Docs

    When I run gh cache delete --help
    Then I see the docs include the --ref option with examples:

    FLAGS
      -r, --ref string        Narrow down deletion to a specific ref, formatted as refs/heads/<branch name> or refs/pull/<number>/merge
    
    EXAMPLES
      # Delete a cache by key and branch ref
      $ gh cache delete cache-key --ref refs/heads/feature-branch
    
      # Delete a cache by key and PR ref
      $ gh cache delete cache-key --ref refs/pull/<PR-number>/merge
    

    Note

    The examples should be put where it makes sense (i.e. not just at the end).

  16. removed their assignment
    on Aug 26, 2025
  17. added
    help wanted
    and removed
    help wanted candidate
    on Aug 26, 2025
  18. luxass commented on Aug 26, 2025

    @luxass
    ContributorAuthor

    @babakks I'd like to take this on - I've already started working on some of the implementation locally. I should be able to get a PR up within the next few hours.

  19. babakks commented on Aug 26, 2025

    @babakks
    Member

    Thanks, @luxass! It's great! I'm looking forward to it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancementgh-cachehelp wanted

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions