# Claude Code in GitHub Codespaces: setup and sign-in

> Claude Code runs in GitHub Codespaces through Anthropic's dev container feature, and a personal Codespaces secret keeps each new codespace signed in.

Source: https://shuriken.sh/guides/claude-code-github-codespaces

Add the feature ghcr.io/anthropics/devcontainer-features/claude-code:1.0 to .devcontainer/devcontainer.json, rebuild the codespace and run claude. Sign in through the link it gives you, or save an API key or a token from claude setup-token as a personal Codespaces secret so new codespaces start signed in.

By Shuriken Updated 27 October 2026 7 min read

**Contents**

To run Claude Code in GitHub Codespaces, add Anthropic's dev container feature to .devcontainer/devcontainer.json, rebuild the codespace and run claude in its terminal. Sign in with your Claude account through the link it gives you (if the browser then shows a code, paste it back into the terminal), or save ANTHROPIC_API_KEY or a CLAUDE_CODE_OAUTH_TOKEN as a personal Codespaces secret, so each new codespace starts signed in.

The Claude Code side below comes from Anthropic's [dev container page](https://code.claude.com/docs/en/devcontainer) and [authentication page](https://code.claude.com/docs/en/authentication); the Codespaces side from GitHub's docs on [timeouts](https://docs.github.com/en/codespaces/setting-your-user-preferences/setting-your-timeout-period-for-github-codespaces), [the codespace lifecycle](https://docs.github.com/en/codespaces/about-codespaces/understanding-the-codespace-lifecycle) and [secrets](https://docs.github.com/en/codespaces/managing-your-codespaces/managing-your-account-specific-secrets-for-github-codespaces). We read all of them on 24 October 2026.

## Install Claude Code in a codespace with the dev container feature #

In your repository, open .devcontainer/devcontainer.json (create it if the repo has none) and add the feature:

json
{
"image": "mcr.microsoft.com/devcontainers/base:ubuntu",
"features": {
"ghcr.io/anthropics/devcontainer-features/claude-code:1.0": {}
}
}

Keep your own image or Dockerfile line if you already have one; only the features entry matters.

Commit it. In a codespace that is already running, open the command palette and run Codespaces: Rebuild Container. New codespaces pick it up as they are created.

Open a terminal and run claude --version, then claude.

The feature installs Claude Code with npm install -g, and installs Node.js first when the image has none. If that step fails with Failed to install Node.js and npm, add "ghcr.io/devcontainers/features/node:1": {} above it. In Codespaces it also adds the Claude Code VS Code extension, and the extension and the terminal share one ~/.claude.

The :1.0 tag pins the feature's install script, not Claude Code. You get the newest release, which then updates itself. Pinning a version, team policy in managed-settings.json and the egress firewall work the same here as in a local container: our [dev container guide](https://shuriken.sh/guides/claude-code-devcontainer) has the files for each.

### Or use the native installer in postCreateCommand #

If you would rather not have the feature add Node.js and npm to your image, run Anthropic's native installer as a lifecycle command:

json
"postCreateCommand": "curl -fsSL https://claude.ai/install.sh | bash"

It puts the launcher at ~/.local/bin/claude. If a new terminal says claude isn't found, that folder isn't on the PATH of your image yet; add it in your shell profile. A native install updates itself in the background. A rebuild clears everything outside /workspaces, this install included, and postCreateCommand runs again in the new container and puts it back.

## Log in to Claude Code from a codespace #

Run claude, choose your Claude account (Pro, Max, Team or Enterprise) or a Claude Console account, and follow the link. If no browser opens, press c to copy the login URL and open it in your own browser.

After you approve, Claude Code expects the browser to call back to a local server inside the codespace. When that callback can't get through, the browser shows a code instead. Copy it and paste it into the terminal at Paste code here if prompted. Anthropic's authentication page names containers among the places where this is common, and its dev container page gives one cause: the editor's port forwarding doesn't route the localhost callback. The terminal then shows Login successful.

That sign-in lives in ~/.claude/.credentials.json inside this one codespace. What keeps it and what doesn't:

| What happens to the codespace | Sign-in in ~/.claude | Codespaces secret | Your repo in /workspaces |
| --- | --- | --- | --- |
| Stop and start, or idle timeout | Kept | Kept | Kept |
| Rebuild the container | Cleared, unless on a volume | Kept | Kept |
| A new codespace | Not there | Exported again | Fresh clone |

Anthropic's fix for rebuilds, a named volume at ~/.claude with CLAUDE_CONFIG_DIR pointed at it, works in Codespaces too, inside that codespace. To carry a sign-in across codespaces, Anthropic's answer is a Codespaces secret.

## Store the key or token as a Codespaces secret #

Codespaces secrets are encrypted, and GitHub exports each one as an environment variable in the terminal of every codespace whose repository has access to it. Claude Code reads two variables you can store this way:

- ANTHROPIC_API_KEY, a key from the Claude Console, billed to that Console account. In an interactive session Claude Code asks once whether to use it.
- CLAUDE_CODE_OAUTH_TOKEN, made by running claude setup-token on a computer with a browser. It's valid for a year and uses your Claude subscription (Pro, Max, Team or Enterprise). It can make model requests only, so Remote Control and claude.ai connectors still need the normal /login.

Save only one. If both are set and you approve the key, the API key wins, because it comes before the token in Claude Code's credential order.

To add it:

- On GitHub, click your profile picture, then Settings.
- In the sidebar, click Codespaces (or go straight to github.com/settings/codespaces).
- Next to Codespaces secrets, click New secret.
- Name it CLAUDE_CODE_OAUTH_TOKEN (or ANTHROPIC_API_KEY) and paste the value.
- Under Repository access, pick each repository you will open codespaces for, then click Add secret.

New codespaces get the secret when they are created. A codespace that is already running gets it only after you stop and restart it. Run /status in Claude Code to see which credential it is using.

GitHub also has repository and organisation secrets, which it describes as the place for keys a repository or organisation owner provides for a team. A subscription token doesn't belong there: Anthropic's GitHub Actions page says an OAuth token "is tied to the subscription of the person who ran claude setup-token", and for a secret shared across repositories it recommends a Console API key instead. Keep your own token in your personal secrets.

Shuriken adds a server of yours with one command, and its chats sit beside your computer's.

[Download](https://shuriken.sh/download)

## Keep secrets out of the repository #

The token or key never goes in devcontainer.json, a .env file you commit, or the Dockerfile. GitHub won't pass a Codespaces secret to a Dockerfile or a dev container feature anyway; secrets exist only once the codespace is running.

To tell people which secrets your project needs without storing a value, list the names in devcontainer.json:

json
"secrets": {
"ANTHROPIC_API_KEY": {
"description": "A Claude Console API key for Claude Code"
}
}

GitHub then offers an input for each one they haven't set yet on the New with options page when someone creates a codespace, and saves what they enter to their own Codespaces settings. Entering a value is optional.

A secret in the environment is readable by anything that runs in the codespace, Claude Code's own shell commands included. Anthropic's warning for containers applies here too: with --dangerously-skip-permissions, a malicious project can exfiltrate anything the container can reach, including the credentials in ~/.claude. Use it only on repositories you trust. Deny rules for .env files and the other ways to keep keys out of an agent's reach are in [keeping secrets from coding agents](https://shuriken.sh/guides/keep-secrets-from-coding-agents).

## What stops when the codespace idles out #

A codespace stops after 30 minutes without activity by default. You can set your default anywhere from 5 to 240 minutes (Settings › Codespaces › Default idle timeout), or per codespace with gh codespace create --idle-timeout 90m. An organisation policy with a lower maximum overrides yours.

GitHub counts typing, the mouse, and terminal input or output as activity. Closing the browser tab doesn't stop a codespace; it keeps running until the timeout. GitHub's docs don't say whether a Claude Code turn printing to the terminal on its own counts the same way, and we haven't measured it, so don't plan around it. Once a turn ends, or stops to ask you something, and nobody types, assume the idle timer is running.

Activity doesn't help past 12 hours. GitHub says a codespace "has a maximum lifetime of 12 hours, regardless of your idle timeout policy or settings", even while you are using it; it warns you, saves your data and stops.

When a codespace stops, for either reason, "any running processes are stopped", Claude Code with them. Your files in /workspaces and ~/.claude are kept, so after a restart claude --continue reopens the conversation in that folder. The turn that was running doesn't come back, and you send it again.

A stopped codespace is deleted after 30 days of inactivity by default, uncommitted changes with it, so push before you walk away.

## Where long Claude Code runs should go instead #

A codespace suits work you sit with. A task that must keep going after you leave has three other homes:

- Anthropic's [cloud sessions](https://code.claude.com/docs/en/claude-code-on-the-web) run on a VM Anthropic manages and keep going with your laptop shut. [Claude Code teleport](https://shuriken.sh/guides/claude-code-teleport-cloud-sessions) covers pulling one back into your terminal.
- For work triggered from issues and pull requests, [Claude Code GitHub Actions](https://shuriken.sh/guides/claude-code-github-actions) runs Claude on a GitHub runner, with the same key or token stored as an Actions secret.
- A machine that never sleeps, at home or rented, runs as long as you like. [Running Claude Code on an always-on machine](https://shuriken.sh/guides/claude-code-on-an-always-on-machine) walks through the install, the headless sign-in and tmux.

Shuriken fits the third. Add the machine under Settings › Devices › Add device › A server and run the one command the app gives you (it works for an hour). It installs Claude Code, Codex and the other agent CLIs for the providers you have sources for, joins your account, and runs as a service that restarts on its own. Your sources reach it end-to-end encrypted from the app, so you don't sign in to Claude on it. You start and follow its chats from your computer or any browser. [Download Shuriken](https://shuriken.sh/download) to add one.

Share

[X](https://x.com/intent/post?url=https%3A%2F%2Fshuriken.sh%2Fguides%2Fclaude-code-github-codespaces&text=Claude%20Code%20in%20GitHub%20Codespaces%3A%20setup%20and%20sign-in)[LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fshuriken.sh%2Fguides%2Fclaude-code-github-codespaces)[Hacker News](https://news.ycombinator.com/submitlink?u=https%3A%2F%2Fshuriken.sh%2Fguides%2Fclaude-code-github-codespaces&t=Claude%20Code%20in%20GitHub%20Codespaces%3A%20setup%20and%20sign-in)[Reddit](https://www.reddit.com/submit?url=https%3A%2F%2Fshuriken.sh%2Fguides%2Fclaude-code-github-codespaces&title=Claude%20Code%20in%20GitHub%20Codespaces%3A%20setup%20and%20sign-in)[E-mail](mailto:?subject=Claude%20Code%20in%20GitHub%20Codespaces%3A%20setup%20and%20sign-in&body=https%3A%2F%2Fshuriken.sh%2Fguides%2Fclaude-code-github-codespaces)

## Sources

- [Development containers (Claude Code docs)](https://code.claude.com/docs/en/devcontainer) (accessed 24 October 2026)
- [Authentication: logging in, precedence and long-lived tokens (Claude Code docs)](https://code.claude.com/docs/en/authentication) (accessed 24 October 2026)
- [Advanced setup: native installer and auto-updates (Claude Code docs)](https://code.claude.com/docs/en/setup) (accessed 24 October 2026)
- [Claude Code GitHub Actions: setting up for an organization (Claude Code docs)](https://code.claude.com/docs/en/github-actions) (accessed 24 October 2026)
- [Use Claude Code in the cloud (Claude Code docs)](https://code.claude.com/docs/en/claude-code-on-the-web) (accessed 24 October 2026)
- [Claude Code Dev Container Feature (anthropics/devcontainer-features on GitHub)](https://github.com/anthropics/devcontainer-features/tree/main/src/claude-code) (accessed 24 October 2026)
- [Setting your timeout period for GitHub Codespaces (GitHub Docs)](https://docs.github.com/en/codespaces/setting-your-user-preferences/setting-your-timeout-period-for-github-codespaces) (accessed 24 October 2026)
- [Understanding the codespace lifecycle (GitHub Docs)](https://docs.github.com/en/codespaces/about-codespaces/understanding-the-codespace-lifecycle) (accessed 24 October 2026)
- [Managing your account-specific secrets for GitHub Codespaces (GitHub Docs)](https://docs.github.com/en/codespaces/managing-your-codespaces/managing-your-account-specific-secrets-for-github-codespaces) (accessed 24 October 2026)
- [Specifying recommended secrets for a repository (GitHub Docs)](https://docs.github.com/en/codespaces/setting-up-your-project-for-codespaces/configuring-dev-containers/specifying-recommended-secrets-for-a-repository) (accessed 24 October 2026)

## Frequently asked questions

**How do I install Claude Code in GitHub Codespaces?**

Add ghcr.io/anthropics/devcontainer-features/claude-code:1.0 to the features block of .devcontainer/devcontainer.json and rebuild the container. The feature installs the CLI and, in Codespaces, the Claude Code VS Code extension. Then run claude in the terminal.

**Why does Claude Code ask me to log in again in every new codespace?**

The sign-in is saved in ~/.claude inside that one codespace. It survives a stop and start, is cleared by a rebuild, and never reaches a new codespace. A Codespaces secret holding ANTHROPIC_API_KEY or CLAUDE_CODE_OAUTH_TOKEN reaches every codespace you create for the repositories you give it.

**Can I use my Claude Pro or Max plan in a codespace instead of an API key?**

Yes. Sign in with your claude.ai account at the prompt, or run claude setup-token on a machine with a browser and save the one-year token as a personal CLAUDE_CODE_OAUTH_TOKEN secret. That token can make model requests only, so Remote Control and claude.ai connectors need the normal sign-in.

**Does Claude Code keep running after I close the codespace tab?**

For a while. Closing the tab doesn't stop a codespace, but it stops after its idle timeout (30 minutes by default) and always within 12 hours. Stopping it stops every process, Claude Code included.

**Can I use a Codespaces secret during the Docker build?**

No. GitHub's docs say Codespaces secrets can't be used at build time, in a Dockerfile or inside a dev container feature. They are exported as environment variables once the codespace is running.

Servers

Your agents on your own servers.

Add a Linux, macOS or Windows server from the app with one command. It runs as a service and updates itself.

[Download](https://shuriken.sh/download)

[Other platforms](https://shuriken.sh/download#main)

## Keep reading

- [Claude Code on a VPS: sizing, setup and staying safe: Guide 27 Oct 2026 7 min read Claude Code runs on a VPS with 4 GB of RAM, an x64 or ARM64 CPU and Ubuntu 20.04+ or Debian 10+, used from a supported country. How to size and secure it.](https://shuriken.sh/guides/claude-code-on-a-vps)
- [How to install Shuriken on Mac, Windows and Linux: Guide 27 Oct 2026 3 min read Install Shuriken from shuriken.sh on Mac, Windows or Linux. The Mac app is notarised by Apple; Windows may warn once, as its installer isn't signed yet.](https://shuriken.sh/guides/install-shuriken)
- [Run Claude Code on a remote server over SSH: Guide 27 Oct 2026 6 min read Run Claude Code over SSH the right way: sign in on a headless box, keep sessions alive with tmux, handle Git keys safely, and see what SSH alone can't do.](https://shuriken.sh/guides/claude-code-over-ssh)
- [Claude Code on a Raspberry Pi: what works: Guide 27 Oct 2026 8 min read Claude Code runs on a Raspberry Pi 4 or 5 with 4 GB of RAM or more and the 64-bit Raspberry Pi OS. Which boards qualify, the 32-bit trap, and the setup.](https://shuriken.sh/guides/claude-code-raspberry-pi)
- [Claude Code with VS Code Remote-SSH, WSL and containers: Guide 27 Oct 2026 8 min read In a VS Code Remote-SSH, WSL or dev container window, the Claude Code extension runs remotely: sign-in, ~/.claude, MCP servers and the CLI live there.](https://shuriken.sh/guides/claude-code-vscode-remote-ssh)
- [Install Claude Code on Linux: Ubuntu, Fedora, Alpine: Guide 27 Oct 2026 8 min read To install Claude Code on Linux, run curl -fsSL https://claude.ai/install.sh | bash, or add Anthropic's signed apt, dnf or apk repository.](https://shuriken.sh/guides/install-claude-code-on-linux)
- [Claude Code headless mode (-p): scripts, CI and cost caps: Guide 27 Oct 2026 5 min read Claude Code headless mode is claude -p: one prompt in, one answer out, no terminal UI. The flags that cap spend and tools, output formats, and CI.](https://shuriken.sh/guides/claude-code-headless-mode)

## Free tools

- [Claude limit reset tracker](https://shuriken.sh/tools/limit-resets/claude)
- [Codex limit reset tracker](https://shuriken.sh/tools/limit-resets/codex)
