AgentSkillsCN

devcontainer-init

通过 Claude Code 认证,为无头代理初始化 devcontainer 环境

SKILL.md
--- frontmatter
name: devcontainer-init
description: Initialize devcontainer with Claude Code authentication for headless agents
argument-hint: [--name <container-name>]
allowed-tools: Bash(git *), Bash(mkdir *), Bash(bash *), Bash(chmod *), Read, Write, Edit

/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)

bash
git rev-parse --git-dir

If not a git repo, initialize it:

bash
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
bash <script-path>/detect-auth.sh --env-file .devcontainer/.env

The script checks (in priority order):

  1. CLAUDE_CODE_OAUTH_TOKEN - env var, then platform storage:
    • macOS: Keychain "Claude Code-credentials"
    • Linux: ~/.claude/.credentials.json
  2. ANTHROPIC_AUTH_TOKEN - env var only (enterprise)
  3. ANTHROPIC_API_KEY - env var only (API key)

If no auth detected, warn user they'll need to configure manually.

4. Create .devcontainer directory

bash
mkdir -p .devcontainer

5. Copy template files

Read and write the templates:

If --name was provided, update the "name" field in devcontainer.json.

6. Update .gitignore

Add these entries if not already present:

code
.devcontainer/.env

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