fix(cli): allow site admins to use `coder create --org` for any organization by ethanndickson · Pull Request #21528 · coder/coder

@ethanndickson ethanndickson changed the title fix(cli): allow site admins to use --org for any organization fix(cli): allow site admins to use coder create --org for any organization

Jan 15, 2026

@ethanndickson

Site-wide admins (e.g., Owners) can now use the --org flag to select
organizations they are not members of. Previously, OrganizationContext.Selected()
only checked the user's membership list, causing 'organization not found' errors
even when the user had RBAC permission to access the org.

The fix adds a fallback that fetches the org directly via the API when not found
in the membership list. This works because the API endpoint applies RBAC filtering,
allowing Owners to read any org.

This fixes all 29+ CLI commands that use OrganizationContext.Selected(), including:
- coder create --org <any-org>
- coder templates push --org <any-org>
- coder organizations members add --org <any-org>

geokat