| name | devcontainer-init |
| description | Initialize devcontainer with Claude Code authentication for headless agents Use when this capability is needed. |
| metadata | {"author":"gnnng"} |
/devcontainer-init
Initialize a devcontainer configuration with automatic Claude Code authentication detection.
Handle: $ARGUMENTS
Parse optional arguments:
--name <name>: Custom container name (default: "claude-devcontainer")
Steps
1. Check if this is a git repository (on host)
git rev-parse --git-dir
If not a git repo, initialize it:
git init
Note: Git init runs on HOST because typically the docker host is local and the directory
is mounted into the devcontainer.
2. Check if .devcontainer already exists
If .devcontainer/ exists, ask user if they want to:
- Overwrite existing configuration
- Skip and keep existing
- Merge (keep existing, add missing files)
3. Detect Claude authentication
Run the auth detection script from ../../scripts/detect-auth.sh:
bash <script-path>/detect-auth.sh
The script checks (in priority order):
CLAUDE_CODE_OAUTH_TOKEN - env var, then platform storage:
- macOS: Keychain "Claude Code-credentials"
- Linux:
~/.claude/.credentials.json
ANTHROPIC_AUTH_TOKEN - env var only (enterprise)
ANTHROPIC_API_KEY - env var only (API key)
If no auth detected, warn user they'll need to configure manually.
4. Create .devcontainer directory
mkdir -p .devcontainer
5. Copy template files
Read and write the template:
If --name was provided, update the "name" field in devcontainer.json.
6. Inject authentication into devcontainer.json
Based on the auth method detected in step 3, add a remoteEnv block to the generated devcontainer.json:
- OAuth:
"remoteEnv": { "CLAUDE_CODE_OAUTH_TOKEN": "${localEnv:CLAUDE_CODE_OAUTH_TOKEN}" }
- Enterprise:
"remoteEnv": { "ANTHROPIC_AUTH_TOKEN": "${localEnv:ANTHROPIC_AUTH_TOKEN}" }
- API key:
"remoteEnv": { "ANTHROPIC_API_KEY": "${localEnv:ANTHROPIC_API_KEY}" }
If no auth detected, skip this step.
7. Report success
Show:
- Auth method detected (or "none - manual setup required")
- Files created
- Next steps:
devcontainer up --workspace-folder . to start
- Use Claude Code inside the container
Template Files
Converted and distributed by TomeVault — claim your Tome and manage your conversions.