Devcontainer claude setup

From findscripter/everything-skills · View interactive version

Devcontainer claude setup is an AI agent skill from the GitHub repository findscripter/everything-skills. 当需要为项目新增 Devcontainer 支持、搭建隔离/沙箱化的 Claude Code 开发环境时使用;做语言探测并在 .devcontainer/ 生成 Dockerfile、devcontainer.json、post_install.py、.zshrc、install.sh 等配置产物;不适用于已有 devcontainer 仅做微调、通用 Docker 问题或生产容器部署。触发词:devcontainer、隔离开发环境、沙箱 Claude Code

How to use this skill

Skill file

何时使用

适用:

不该用(负边界):

步骤

整体流程:项目侦察 → 语言探测 → 生成配置 → 写入 .devcontainer/ → 提示用户启动。

1. 项目侦察

推断项目名(按序取首个命中):

  1. package.json → name
  2. pyproject.toml → project.name
  3. Cargo.toml → package.name
  4. go.mod → 模块路径最后一段(/ 之后)
  5. 兜底用目录名

转为 slug:全小写,空格/下划线替换为连字符。得到两个占位值:{{PROJECT_NAME}}(人类可读名)、{{PROJECT_SLUG}}(卷命名用)。

2. 语言探测

| 语言 | 探测文件 |

|------|----------|

| Python | pyproject.toml、*.py |

| Node/TS | package.json、tsconfig.json |

| Rust | Cargo.toml |

| Go | go.mod、go.sum |

多语言项目按优先级全部配置:Python(用 Dockerfile 装 uv + Python)> Node/TS(devcontainer feature)> Rust(feature)> Go(feature)。各语言的扩展与 settings 合并写入;postCreateCommand 用 && 串联,如:

uv run /opt/post_install.py && uv sync && npm ci

3. 生成配置

从 resources/ 基础模板起步,替换 {{PROJECT_NAME}} / {{PROJECT_SLUG}},再叠加语言专属修改。

基础模板已含:Claude Code(marketplace 插件 anthropics/skills、trailofbits/skills、trailofbits/skills-curated)、uv 装 Python 3.13、fnm 装 Node 22、ast-grep、网络隔离工具(iptables/ipset,需 NET_ADMIN 能力)、现代 CLI(ripgrep、fd、fzf、tmux、git-delta)。

4. 写入这些文件到 `.devcontainer/`

  1. Dockerfile — 镜像构建指令
  2. devcontainer.json — VS Code/devcontainer 配置
  3. post_install.py — 创建后初始化脚本
  4. .zshrc — Shell 配置
  5. install.sh — 管理 devcontainer 的 CLI(提供 devc 命令)

5. 校验清单(呈给用户前逐项核对)

  1. 所有 {{PROJECT_NAME}} 已替换为人类可读名。
  2. 所有 {{PROJECT_SLUG}} 已替换为 slug。
  3. devcontainer.json JSON 合法(无尾随逗号、嵌套正确)。
  4. 已为所有探测到的语言加上对应扩展。
  5. postCreateCommand 含全部所需命令(&& 串联)。

指令

各语言专属修改(按探测结果叠加):

Python(含自定义版本时改 Dockerfile):

RUN uv python install <version> --default

扩展:ms-python.python、ms-python.vscode-pylance、charliermarsh.ruff;settings 设 python.defaultInterpreterPath 为 .venv/bin/python,[python] 用 ruff 格式化并 source.organizeImports: explicit。

postCreate(有 pyproject.toml):rm -rf .venv && uv sync && uv run /opt/post_install.py

Node/TS(基础模板已含 Node 22,无需改 Dockerfile):

扩展 dbaeumer.vscode-eslint、esbenp.prettier-vscode;settings 用 prettier 格式化 + source.fixAll.eslint: explicit。按 lockfile 选包管理器:

Rust:feature "ghcr.io/devcontainers/features/rust:1": {};扩展 rust-lang.rust-analyzer、tamasfe.even-better-toml。postCreate:有 Cargo.lock 用 ... && cargo build --locked,否则 ... && cargo build。

Go:feature "ghcr.io/devcontainers/features/go:1": {"version": "latest"};扩展 golang.go,settings 开 go.useLanguageServer。postCreate:uv run /opt/post_install.py && go mod download。

持久化卷(devcontainer.json 的 mounts):

"mounts": [
  "source={{PROJECT_SLUG}}-<purpose>-${devcontainerId},target=<container-path>,type=volume"
]

常见追加:Rust target=/home/vscode/.cargo、Go target=/home/vscode/go。

示例

为一个 Python + Node 双语言项目生成配置:

  1. 侦察:pyproject.toml 中 name = "my-project" → PROJECT_NAME=「My Project」,PROJECT_SLUG=「my-project」。
  2. 探测:命中 Python + Node/TS。
  3. 合并扩展(python/pylance/ruff + eslint/prettier),合并 settings。
  4. postCreateCommand(lockfile 为 package-lock.json):
rm -rf .venv && uv sync && uv run /opt/post_install.py && npm ci
  1. 写入 .devcontainer/ 下 5 个文件,校验 JSON 合法后呈给用户。

注意事项

互见


采编自 sickn33/antigravity-awesome-skills(MIT)。原 skill 标注上游来源为 vibeship-spawner-skills(Apache 2.0)。

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.