Claude Code in DevContainers
Overview
Section titled “Overview”Claude Code is Anthropic’s AI coding assistant CLI. It can read and edit files, run terminal commands, search your codebase, create commits, and help with complex multi-step software engineering tasks — all from within your DevContainer.
Installation
Section titled “Installation”Add the Claude Code feature to your devcontainer.json:
{ "features": { "ghcr.io/infrashift/trusted-devcontainer-features/bun:latest": {}, "ghcr.io/infrashift/trusted-devcontainer-features/claude-code:latest": { "target_version": "latest" } }}The Bun feature is required as a dependency — Claude Code is installed as a global npm package via Bun.
API Key Configuration
Section titled “API Key Configuration”Claude Code requires an Anthropic API key. Pass it from your host environment:
{ "containerEnv": { "ANTHROPIC_API_KEY": "${localEnv:ANTHROPIC_API_KEY}" }}Alternatively, set the key in a .env file or configure it after container startup with claude config.
VS Code Extension
Section titled “VS Code Extension”The feature automatically recommends the anthropics.claude-code VS Code extension, which provides:
- Inline chat with Claude in the editor
- Code suggestions and completions
- Terminal integration for Claude Code CLI
CLI Usage
Section titled “CLI Usage”Once inside your DevContainer, use Claude Code from the terminal:
# Start an interactive sessionclaude
# Ask a questionclaude "explain the authentication flow in this codebase"
# Run in non-interactive modeclaude -p "add error handling to the API endpoint in server.ts"Example Workflows
Section titled “Example Workflows”Code Review
Section titled “Code Review”claude "review the changes in my current git diff and suggest improvements"Test Writing
Section titled “Test Writing”claude "write unit tests for the UserService class"Debugging
Section titled “Debugging”claude "the /api/users endpoint returns 500 — investigate and fix"Security Considerations
Section titled “Security Considerations”- API keys: Never commit API keys to version control. Use
containerEnvwithlocalEnvreferences or secrets management. - Egress filtering: Pair with the Egress Filter feature to restrict network access to only
api.anthropic.comand other required domains. - Container isolation: Claude Code runs within the DevContainer boundary and cannot access your host filesystem beyond the mounted workspace.