In GitHub Codespaces, an organization pays for 120 engineers' codespaces: how would you cap the spend with ownership and policies, and where do policies stop?
answer
- who owns is who pays
- six constraints, one policy page
- the shortest value wins
- each constraint bites at a different moment
basics
~20 sMake codespaces organization-owned for enabled members, set a budget, then add policies limiting machine types, idle timeout, retention, codespaces per user, base images and port visibility. Policies bind only organization-billed codespaces, and some apply only at creation.
solid answer
~40 sStart with **ownership**: on GitHub Team or Enterprise Cloud, choose organization ownership and enable Codespaces only for the members who need it, so their codespaces are organization-billed, and set a **budget** as the hard ceiling. Then add **Codespaces policies**: allowed **machine types** and a **maximum idle timeout** bound compute; a **retention period** and **maximum codespaces per user** bound storage; **base images** and **port visibility** cover risk. Organization-wide policies set the outer limit and repository policies only tighten it; for timeouts and retention the shortest applicable value wins. The limits: policies bind only codespaces the organization pays for, retention and base-image changes do not reach existing codespaces, and prebuild costs sit outside these constraints. The judgement is the trade: every limit that saves hours also costs engineers waiting time or lost work.
go deeper
Know that an organization can pay for its members' codespaces and limit them with policies such as allowed machine types and idle timeout.
Explain organization against user ownership and list what each policy constraint bounds, including the shortest-value rule for timeout and retention.
Know when each constraint takes effect, why user-owned codespaces escape policy, and how machine-type limits can block a repository with a minimum machine requirement.
Own the trade-off: set limits that save hours without costing more in engineer waiting time and lost work, and measure usage before and after tightening.
## Ownership decides everything else A codespace is paid for by the account that **owns** it, and only an organization that owns a codespace can govern it: apply policies, read audit logs, stop or delete it through the REST API. The setting is **Codespace ownership**: - **Organization ownership**: the organization pays for a codespace when the organization has no Codespaces budget or a non-zero one, the codespace comes from one of its repositories (or an organization-owned fork), and the creator is a member or collaborator for whom Codespaces is enabled. - **User ownership**: the creator always pays, and the organization has no control over the codespace. Organizations on GitHub Free cannot pay for codespaces at all. On paid plans the owner chooses whether Codespaces is enabled for all members and collaborators or for a selected list in private repositories. For a fleet of 120, enabling a named group keeps the population that can spend money explicit. A **budget** is the ceiling under everything else. When it is exhausted, nobody can create or resume organization-billed codespaces, though work can still be exported to a branch. ## The six constraints Policies live on the organization's *Codespaces > Policies* page. Each policy holds one or more constraints and targets all repositories or selected ones. | Constraint | Bounds | When it applies | |---|---|---| | **Machine types** | Compute rate (cost scales with cores) | New codespaces; existing ones when restarted or reconnected | | **Maximum idle timeout** | Compute wasted while idle | New codespaces; existing ones at their next start | | **Retention period** (0 to 30 days) | Storage of stopped codespaces | **At creation only**; editing or deleting the policy changes no existing codespace | | **Maximum codespaces per user** | How many organization-billed codespaces each person holds | When a codespace is created; always covers **all** repositories | | **Base images** | Which dev container images are allowed | At creation and on a full rebuild; not existing codespaces | | **Port visibility** | Whether Org or Public sharing is offered | New codespaces; existing ones at their next start | ## How policies combine 1. An **organization-wide** policy should be set to the most generous value acceptable anywhere; **repository** policies then tighten it. A repository policy cannot loosen the organization-wide one. 2. For the idle timeout and retention period, the **shortest** value among the organization-wide policy, any repository policy and the user's personal setting is applied. 3. A policy carrying **Maximum codespaces per user** applies to every repository, so other constraints added to that policy cannot be limited to selected repositories. 4. A retention policy also removes the **Keep codespace** escape hatch for the repositories it covers. ## Where the policies stop - **Only organization-billed codespaces are bound.** A codespace someone creates at their own expense, for example on a public repository where they are not enabled, ignores every policy. - **Retention and base-image changes are not retroactive.** Tightening retention from 30 days to 7 leaves every existing codespace on its old period. - **Machine-type limits can collide with a repository's own minimum.** If the dev container configuration demands a machine type the policy removed, nobody can create a codespace for that repository until the policy is adjusted for it. - **Prebuilds** consume GitHub Actions minutes and Codespaces storage; their configuration, regions and triggers are governed with the dev container setup, not by these constraints. ## The judgement There is no single right set of numbers. The trade-offs to argue: - **Machine size versus engineer time.** Restricting everyone to 2 cores is cheap on paper and expensive if builds and tests crawl; a repository-specific policy can allow larger machines only where they pay for themselves. - **Idle timeout versus interruption.** Short timeouts stop forgotten codespaces quickly, but stopping and restarting costs time each time someone steps away. - **Retention versus lost work.** Short retention cuts storage, and deletion ignores unpushed changes, so it only works alongside a habit of pushing. - **Per-user caps versus parallel work.** A cap of two codespaces stops sprawl but blocks someone reviewing one branch while building another. Measure before tightening: usage reports, the organization's codespace list and the audit log show where the hours and gigabytes go, and organization owners can delete stale codespaces from the CLI with `gh codespace delete --org`.
- Finance asks to shorten retention from 30 to 7 days to cut storage this month. What do you tell them?The retention constraint applies only when a codespace is created, so existing codespaces keep their 30 days and storage falls only as new ones replace them. Storage already counted this month does not come back either. For an immediate effect, list stale organization-owned codespaces and delete them, after warning their owners about unpushed work.
- After a machine-type policy removes 8-core machines, nobody can create codespaces for one repository. Why, and what are the options?Its dev container configuration sets a minimum machine specification that no remaining machine type satisfies. Either add a repository-specific exception allowing a type that meets the minimum, or change the configuration's requirement. People with codespaces they can no longer open can export their changes to a branch.
- Codespaces policies govern every codespace created from the organization's repositories.
- Shortening the retention policy also shortens it for existing codespaces.
- A repository-specific policy can grant larger machines than the organization-wide policy allows.
- Organization plans include a free monthly Codespaces quota like personal accounts.
- Restricting everyone to the smallest machine is always the cheapest choice overall.