By default, codespaces time out after 30 minutes of inactivity. When a codespace times out it is stopped and will no longer incur charges for compute usage.
The personal settings of a GitHub user allow them to define their own timeout period for codespaces they create. This may be longer than the default 30-minute period. For more information, see "
Setting your timeout period for GitHub Codespaces
."
As an organization owner, you may want to configure constraints on the maximum idle timeout period for codespaces created for repositories owned by your organization. This can help you to limit costs associated with codespaces that are left to timeout after long periods of inactivity. You can set a maximum timeout for the codespaces for all repositories owned by your organization, or for the codespaces of specific repositories.
Note
: Maximum idle timeout constraints only apply to codespaces that are owned by your organization.
For more information about pricing for GitHub Codespaces compute usage, see "
About billing for GitHub Codespaces
."
In the context of the Codespaces idle timeout, inactivity is defined as the absence of activity indicative of a user's presence. Personal interaction with a codespace, such as typing or using the mouse, resets the idle timeout period. Terminal activity, either input or output, also resets the idle timeout period. For example, if you publish a web app on a port from a codespace and page requests generate output in a terminal on the codespace, then each time terminal output occurs the timeout will be reset. However, if you share a port, and then don't interact with the codespace, and no terminal output is generated, the codespace will time out after the configured period.
If someone sets the default idle timeout to 90 minutes in their personal settings and they then start a codespace for a repository that has a maximum idle timeout constraint of 60 minutes, the codespace will time out after 60 minutes of inactivity. When codespace creation completes, a message explaining this will be displayed:
Idle timeout for this codespace is set to 60 minutes in compliance with your organization’s policy.
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 timeout constraint, then the timeout constraints in any policies that are targeted at specific repositories must fall within the restriction configured for the entire organization. The shortest timeout period - in an organization-wide policy, a policy targeted at specified repositories, or in someone's personal settings - is applied.
If you add an organization-wide policy with a timeout constraint, you should set the timeout to the longest acceptable period. You can then add separate policies that set the maximum timeout to a shorter period for specific repositories in your organization.
Note
: Codespaces 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 upper-right corner of GitHub, select 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 "Codespaces policies" page, click
Create Policy
.
-
Enter a name for your new policy.
-
Click
Add constraint
and choose
Maximum idle timeout
.
-
Click
to edit the constraint.
-
Enter the maximum number of minutes codespaces can remain inactive before they time out, then click
Save
.
-
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 an existing 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:
-
Click
.
-
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 timeout constraint is also applied to existing codespaces the next time they are started.
You can edit an existing policy. For example, you may want to add or remove constraints to or from a policy.
- Display the "Codespaces policies" page. For more information, see "
Adding a policy to set a maximum idle timeout period
."
- Click the name of the policy you want to edit.
- Beside the "Maximum idle timeout" constraint, click
.
- Make the required changes then click
Save
.
-
Display the "Codespaces policies" page. For more information, see "
Adding a policy to set a maximum idle timeout period
."
-
Click
to the right of the policy you want to delete.