LinuxCommandLibrary

gh-cs

Access GitHub Codespaces

TLDR

View documentation for the original command

$ tldr gh codespace
copy

SYNOPSIS

gh cs <command> [<args>...] [flags]

PARAMETERS

code
    Open codespace in VS Code

connect-gh
    Connect a codespace to GitHub

create
    Create a new codespace from repo/branch

delete
    Delete one or more codespaces

edit
    Edit codespace machine configuration

export
    Export codespace to backup image

list
    List codespaces for authenticated user
(flags: --limit, --repo, --json)

logs
    Download codespace logs

ports
    Forward ports from a codespace

preflight
    Run preflight checks for repo

rebuild
    Rebuild codespace container

rename
    Rename a codespace

ssh
    SSH into a codespace

start
    Start a stopped codespace

stop
    Stop a running codespace

upgrade
    Upgrade codespace machine type

web
    Open codespace in browser

--help
    Show help for command

--repo
    Select repo in <OWNER>/<REPO> format

--codespace
    Select codespace by name

DESCRIPTION

gh cs (alias for gh codespace) is a subcommand of the GitHub CLI (gh) that allows users to manage GitHub Codespaces from the terminal.

GitHub Codespaces provide instant dev environments in the cloud, configured via devcontainer.json in repositories. With gh cs, you can list, create, start, stop, connect to, and delete codespaces without a GUI.

Essential workflows include creating a codespace from a repo/branch/ref, connecting via SSH, VS Code, or browser, port forwarding for web previews, and monitoring logs. It supports filtering by repo, state (queued, available, etc.), and machine size upgrades.

Requires GitHub CLI installed (brew install gh on macOS) and authentication via gh auth login. Ideal for CI/CD, quick prototyping, or headless development.

Enhances productivity by integrating Codespaces into shell scripts and Git workflows.

CAVEATS

Requires gh CLI ≥ v2.0, GitHub account with Codespaces access (not free for all plans).
Rate-limited by GitHub API; no offline mode.

AUTHENTICATION

Run gh auth login first; supports GitHub.com, Enterprise.

EXAMPLES

gh cs create --repo OWNER/REPO --branch main
gh cs list --json name,state
gh cs ssh MY-CODESPACE

HISTORY

Added in GitHub CLI v0.7.0 (Oct 2020) alongside Codespaces public beta; expanded with v2.x for new features like port forwarding and upgrades.

SEE ALSO

gh(1), git(1), ssh(1)

Copied to clipboard