GitHub Codespaces are automatically deleted after they have been stopped and have remained inactive for a defined number of days. The retention period for each codespace is set when the codespace is created and does not change. The default retention period is 30 days.
GitHub users can set a personal retention period of less than 30 days for codespaces they create. For more information, see "Configuring automatic deletion of your codespaces."
As an organization owner, you may want to configure constraints on the maximum retention period for codespaces created for the repositories owned by your organization. This can help you to limit the storage costs associated with codespaces that are stopped and then left unused until they are automatically deleted. For more information about storage charges, see "About billing for GitHub Codespaces." You can set a maximum retention period for all, or for specific, repositories owned by your organization.
Note: Setting a maximum retention policy for a repository prevents people from exempting a codespace from automatic deletion. The "Keep codespace" option will be unavailable for codespaces created for that repository. For more information, see "Configuring automatic deletion of your codespaces."
When you create a policy, you choose whether it applies to all repositories in your organization, or only to specified repositories. If you create an organization-wide policy with a codespace retention constraint, then the retention constraints in any policies that are targeted at specific repositories should be shorter than the restriction configured for the entire organization, or they will have no effect. The shortest retention period - in an organization-wide policy, a policy targeted at specified repositories, or the default retention period in someone's personal settings - is applied.
If you add an organization-wide policy with a retention constraint, you should set the retention period to the longest acceptable period. You can then add separate policies that set the maximum retention to a shorter period for specific repositories in your organization.
Note: Codespace policies only apply to codespaces that your organizations pays for. If someone creates a codespace for a repository in your organization at their own expense, then the codespace will not be bound by these policies. For more information, see "Choosing who owns and pays for codespaces in your organization."
In the top right corner of GitHub.com, click your profile photo, then click Your organizations.
Next to the organization, click Settings.
In the "Code, planning, and automation" section of the sidebar, select Codespaces then click Policies.
On the "Codespace policies" page, click Create Policy.
Enter a name for your new policy.
Click Add constraint and choose Retention period.
Click to edit the constraint.
Enter the maximum number of days codespaces can remain stopped before they are automatically deleted, then click Save.
- A day, in this context, is a 24-hour period, beginning at the time of day when the codespace was stopped.
- The valid range is 0-30 days.
- Setting the period to
0will result in codespaces being immediately deleted when they are stopped, or when they timeout due to inactivity.
By default the policy is set to apply to all repositories, if you want it to apply only to some of the repositories in your organization, click All repositories and then click Selected repositories in the dropdown menu.
Note: If you're adding a constraint to a policy that already contains the "Maximum codespaces per user" constraint, you won't be able to apply the policy to selected repositories. This is because the "Maximum codespaces per user" constraint always applies to all repositories in the organization.
With Selected repositories selected:
Select the repositories you want this policy to apply to.
At the bottom of the repository list, click Select repositories.
If you want to add another constraint to the policy, click Add constraint and choose another constraint. For information about other constraints, see:
After you've finished adding constraints to your policy, click Save.
The policy will be applied to all new codespaces that are billable to your organization. The retention period constraint is only applied on codespace creation.
You can edit an existing policy. For example, you may want to add or remove constraints to or from a policy.
The retention period constraint is only applied to codespaces when they are created. Editing a policy has no effect on existing codespaces.
- Display the "Codespace policies" page. For more information, see "Adding a policy to set a maximum codespace retention period."
- Click the name of the policy you want to edit.
- Beside the "Retention period" constraint, click .
- Make the required changes then click Save.
You can delete a policy at any time. Deleting a policy has no effect on existing codespaces.
Display the "Codespace policies" page. For more information, see "Adding a policy to set a maximum codespace retention period."
Click the delete button to the right of the policy you want to delete.
Click to the right of the policy you want to delete.