0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

【Claude Code】コンテナ(devcontainer)でもclaude code usage monitorを使う方法!🐳

0
Last updated at Posted at 2025-07-27

はじめに

Claude Code をYOLOモード(--dangerously-skip-permissions)でコンテナ内で暴れてもらいつつ、Claude Code Usage Monitorも使いたい……!

この記事では、VS Code の devcontainer 上で claude-monitor を自動導入する方法をご紹介します!

この記事でできること

  • devcontainer.json で再現可能な Claude Code 開発環境の構築
  • claude-monitor のインストール自動化

方法

↓1.~3.各ファイルを置いたリポジトリはこちら

1.devcontainer.json を準備する

まずは .devcontainer/devcontainer.json を以下のように編集します↓

折り畳みました
{
  "name": "Claude Code Sandbox",
  "build": {
    "dockerfile": "Dockerfile",
    "args": {
      "TZ": "${localEnv:TZ:Asia/Tokyo}"
    }
  },
  "runArgs": ["--cap-add=NET_ADMIN", "--cap-add=NET_RAW"],
  "customizations": {
    "vscode": {
      "extensions": [
        "dbaeumer.vscode-eslint",
        "esbenp.prettier-vscode",
        "eamodio.gitlens"
      ],
      "settings": {
        "editor.formatOnSave": true,
        "editor.defaultFormatter": "esbenp.prettier-vscode",
        "editor.codeActionsOnSave": {
          "source.fixAll.eslint": "explicit"
        },
        "terminal.integrated.defaultProfile.linux": "zsh",
        "terminal.integrated.profiles.linux": {
          "bash": {
            "path": "bash",
            "icon": "terminal-bash"
          },
          "zsh": {
            "path": "zsh"
          }
        }
      }
    }
  },
  "remoteUser": "node",
  "mounts": [
    "source=claude-code-bashhistory-${devcontainerId},target=/commandhistory,type=volume",
    "source=claude-code-config-${devcontainerId},target=/home/node/.claude,type=volume"
  ],
  "remoteEnv": {
    "NODE_OPTIONS": "--max-old-space-size=4096",
    "CLAUDE_CONFIG_DIR": "/home/node/.claude",
    "PATH": "${containerEnv:PATH}:/home/node/.local/bin"
  },
  "postCreateCommand": "bash -li /workspace/.devcontainer/install-usage-monitor.sh",
  "workspaceMount": "source=${localWorkspaceFolder},target=/workspace,type=bind,consistency=delegated",
  "workspaceFolder": "/workspace"
  // "postCreateCommand": "sudo /usr/local/bin/init-firewall.sh"
}

ベースは、claude codeの公式リポジトリのファイルを使っています!

2.install-usage-monitor.sh を用意

続いて .devcontainer/install-usage-monitor.sh を作成

#!/usr/bin/env bash
set -e
curl -LsSf https://astral.sh/uv/install.sh | sh
echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.zshrc
uv tool update-shell || true
uv tool install claude-monitor

devcontainer.jsonのpostCreateCommand によって、devcontainer 起動時にスクリプトが自動で実行されます!)

3.Dockerfileを用意

以下のClaude Code公式のをそのまま使いましょう〜

🚀 使ってみる!

コンテナを Rebuild Container(再構築) し、
claude-monitorコマンドを実行すると…

claude-monitor --plan pro --timezone Asia/Tokyo

image.png

このように、すでに claude-monitor が使えるようになっています!

🙌 まとめ

コンテナ内で自由にYOLOで暴れてもらいつつ、トークン使用量も把握しましょう〜!

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?