One mistyped selector in gh codespace delete and a batch of Codespaces is gone, unsaved work included. This guide starts with a single named Codespace and only widens to repository, age or organisation selection once the scope is clear. Allow about ten minutes for one deletion and longer for a batch, because the real work is checking the target before you confirm.
Destructive action: deletion cannot be undone with this command. Keep any needed changes in Git or another deliberate backup first.
You need GitHub CLI installed and authenticated as the account that owns the Codespace, or the organisation administrator permissions required for an organisation-billed target. This guide describes GitHub CLI 2.87.3, installed on the reference system on 23 September 2026. Check your local version and the flags your installation exposes:
$ gh version
gh version 2.87.3 (2026-02-23)
$ gh codespace delete --help
The installed manual and the current GitHub CLI manual document the same selection flags used here. The command has no dry-run flag, so treat every invocation that reaches confirmation as a real deletion request. To discover names first, use gh codespace list and copy the exact name into the next step.
The name is the narrowest target. Replace the value in angle brackets with a real Codespace name, and do not type the angle brackets.
$ gh codespace delete --codespace <codespace-name>
The short form is -c. The command may ask for confirmation when the Codespace contains unsaved changes. Read the target and prompt carefully before accepting. If the name is wrong, stop and cancel rather than trying a broader selector.
Checkpoint: the command identifies the one named Codespace you meant to remove. If it does not, answer no or interrupt it, then get the name again with gh codespace list.
A Codespace can hold edits that are not committed or pushed. Before using --force, open the Codespace or connect to it and decide what must be kept. Commit and push useful work, or copy it to a controlled backup. A typical Git check inside the Codespace is:
$ git status
$ git add --all
$ git commit -m 'Save work before deleting codespace'
$ git push
Warning: only run those Git commands if the changes are yours and the repository and remote are correct. If the working tree includes someone else's work, do not stage it.
The --force option skips confirmation for Codespaces with unsaved changes. It does not save, commit or recover them. Use it only after that decision:
$ gh codespace delete --codespace <codespace-name> --force
Recovery: there is no undo in gh codespace delete. You recreate a Codespace and check out the saved repository state, or restore files from the backup you made before deletion.
The explicit all-Codespaces form is:
$ gh codespace delete --all
Warning: this is a broad, destructive selection for the authenticated user. It is not a cleanup preview and it is not limited to stopped Codespaces. Use it only after checking that none of your Codespaces holds work you still need.
The --all flag is clearer in an audited script than relying on an accidentally broad combination of filters.
Checkpoint: if you meant one Codespace or one repository, do not use --all. Go back to the named or repository-scoped step.
To select Codespaces for one repository, give its full owner/repository name:
$ gh codespace delete --repo <owner/repository>
The long option is --repo, with -R as its short form. Check the owner as well as the repository name: a similarly named fork is a different target, and a repository filter is a batch selection rather than a single-Codespace confirmation.
You can filter by owner without naming a repository:
$ gh codespace delete --repo-owner <username-or-organisation>
Use this only when every matching Codespace is disposable. These flags give no preview mode. To review first, run gh codespace list, inspect the names and repositories, then delete named Codespaces individually.
Use --days with a non-negative number to select Codespaces older than that many days:
$ gh codespace delete --days <number-of-days>
For example, this asks to remove Codespaces older than 30 days:
$ gh codespace delete --days 30
The help output shows a default of 0 for this option. Do not treat that number as a retention policy or as evidence that a deletion is safe. When age is part of your selection, pass an explicit threshold such as 30 so the command and its audit trail state the rule clearly.
Combine an age threshold with a repository filter when the installed CLI accepts both selectors for your intended operation, for example:
$ gh codespace delete --repo <owner/repository> --days 30
Tip: read the confirmation as a final checkpoint. If the matching set is broader than expected, cancel and use named deletions instead.
Organisation administrators can target Codespaces billed to an organisation with --org:
$ gh codespace delete --org <organisation-login>
To target one user's Codespaces within that organisation, add --user:
$ gh codespace delete --org <organisation-login> --user <username>
These are administrative operations, not a reason to run the shell as root. sudo does not grant GitHub organisation permissions, so leave it off. Use the GitHub account and organisation role that actually authorise the operation. Add a repository filter or an age threshold if the intended scope is smaller, then read the confirmation before proceeding.
gh auth status. Do not fix an authorisation problem by switching to an unrelated account.--force just to make an unattended command finish.To avoid shell mistakes, quote a value if your shell treats any part of it specially:
$ gh codespace delete --codespace '<codespace-name>'
The quotes are shell syntax and are not part of the name. Keep the command in your shell history until you have verified the result, but remove or protect that history if the target names are sensitive in your environment.
--force was used only when skipping the unsaved-change confirmation was intentional.