Skip to main content

Restricting the retention period for codespaces

You can set a maximum retention period for any codespaces owned by your organization.

Who can use this feature

To manage retention constraints for an organization's codespaces, you must be an owner of the organization.

GitHub Codespaces は、GitHub Team または GitHub Enterprise Cloud を使用する Organization で利用できます。 GitHub Free および GitHub Pro プランの個人ユーザーも、GitHub Codespaces を制限付きのベータ リリースとして利用できます。 詳細については、「GitHub's products」を参照してください。


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.

Everyone who has access to GitHub Codespaces can configure a retention period for the codespaces they create. The initial setting for this default retention period is 30 days. Individual users can set this period within the range 0-30 days. 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.

Setting organization-wide and repository-specific policies

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.

: Codespaces に対して定義した Organization ポリシーは、Organization に課金される codespace にのみ適用されます。 個々のユーザーが Organization 内のリポジトリ用の codespace を作成し、その Organization に課金されない場合、codespace はそれらのポリシーに制約されません。 Organization に課金される codespace を作成できるユーザーを選ぶ方法については、「Organization に対してGitHub Codespaces を有効にする」を参照してください。

Adding a policy to set a maximum codespace retention period

  1. の右上隅にあるプロファイル写真をクリックし、 [自分の Organization] をクリックします。 プロファイル メニューの組織

  2. 組織の隣の [設定] をクリックします。 [設定] ボタン

  3. サイドバーの [コード、計画、自動化] セクションで、 [ Codespaces] を選択してから、 [ポリシー] をクリックします。

  4. [codespace ポリシー] ページで、 [ポリシーの作成] をクリックします。

  5. 新しいポリシーの名前を入力します。

  6. Click Add constraint and choose Retention period.

    Add a constraint for retention periods

  7. Click to edit the constraint.

    Edit the timeout constraint

  8. Enter the maximum number of days codespaces can remain stopped before they are automatically deleted, then click Save.

    Set the retention period in days


    • 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 0 will result in codespaces being immediately deleted when they are stopped, or when they timeout due to inactivity.
  9. In the "Change policy target" area, click the dropdown button.

  10. Choose either All repositories or Selected repositories to determine which repositories this policy will apply to.

  11. If you chose Selected repositories:

    1. Click .

      Edit the settings for the policy

    2. Select the repositories you want this policy to apply to.

    3. At the bottom of the repository list, click Select repositories.

      Select repositories for this policy

  12. If you want to add another constraint to the policy, click Add constraint and choose another constraint. For information about other constraints, see "Restricting access to machine types," "Restricting the visibility of forwarded ports," and "Restricting the idle timeout period."

  13. After you've finished adding constraints to your policy, click Save.

The policy will be applied to all new codespaces that are created.

Editing a policy

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.

  1. Display the "Codespace policies" page. For more information, see "Adding a policy to set a maximum codespace retention period."
  2. Click the name of the policy you want to edit.
  3. Make the required changes then click Save.

Deleting a policy

You can delete a policy at any time. Deleting a policy has no effect on existing codespaces.

  1. Display the "Codespace policies" page. For more information, see "Adding a policy to set a maximum codespace retention period."

  2. Click the delete button to the right of the policy you want to delete.

    The delete button for a policy