jpskill.com
📦 その他 コミュニティ

port-allocator

複数のClaude Codeインスタンスが開発サーバーのポートを共有する際に、ポートの競合を自動で回避し、割り当てと管理を効率的に行うことで、スムーズな開発作業を支援するSkill。

📜 元の英語説明(参考)

Automatically allocate and manage development server ports, avoiding port conflicts between multiple Claude Code instances

🇯🇵 日本人クリエイター向け解説

一言でいうと

複数のClaude Codeインスタンスが開発サーバーのポートを共有する際に、ポートの競合を自動で回避し、割り当てと管理を効率的に行うことで、スムーズな開発作業を支援するSkill。

※ jpskill.com 編集部が日本のビジネス現場向けに補足した解説です。Skill本体の挙動とは独立した参考情報です。

⚡ おすすめ: コマンド1行でインストール(60秒)

下記のコマンドをコピーしてターミナル(Mac/Linux)または PowerShell(Windows)に貼り付けてください。 ダウンロード → 解凍 → 配置まで全自動。

🍎 Mac / 🐧 Linux
mkdir -p ~/.claude/skills && cd ~/.claude/skills && curl -L -o port-allocator.zip https://jpskill.com/download/19191.zip && unzip -o port-allocator.zip && rm port-allocator.zip
🪟 Windows (PowerShell)
$d = "$env:USERPROFILE\.claude\skills"; ni -Force -ItemType Directory $d | Out-Null; iwr https://jpskill.com/download/19191.zip -OutFile "$d\port-allocator.zip"; Expand-Archive "$d\port-allocator.zip" -DestinationPath $d -Force; ri "$d\port-allocator.zip"

完了後、Claude Code を再起動 → 普通に「動画プロンプト作って」のように話しかけるだけで自動発動します。

💾 手動でダウンロードしたい(コマンドが難しい人向け)
  1. 1. 下の青いボタンを押して port-allocator.zip をダウンロード
  2. 2. ZIPファイルをダブルクリックで解凍 → port-allocator フォルダができる
  3. 3. そのフォルダを C:\Users\あなたの名前\.claude\skills\(Win)または ~/.claude/skills/(Mac)へ移動
  4. 4. Claude Code を再起動

⚠️ ダウンロード・利用は自己責任でお願いします。当サイトは内容・動作・安全性について責任を負いません。

🎯 このSkillでできること

下記の説明文を読むと、このSkillがあなたに何をしてくれるかが分かります。Claudeにこの分野の依頼をすると、自動で発動します。

📦 インストール方法 (3ステップ)

  1. 1. 上の「ダウンロード」ボタンを押して .skill ファイルを取得
  2. 2. ファイル名の拡張子を .skill から .zip に変えて展開(macは自動展開可)
  3. 3. 展開してできたフォルダを、ホームフォルダの .claude/skills/ に置く
    • · macOS / Linux: ~/.claude/skills/
    • · Windows: %USERPROFILE%\.claude\skills\

Claude Code を再起動すれば完了。「このSkillを使って…」と話しかけなくても、関連する依頼で自動的に呼び出されます。

詳しい使い方ガイドを見る →
最終更新
2026-05-18
取得日時
2026-05-18
同梱ファイル
1

📖 Skill本文(日本語訳)

※ 原文(英語/中国語)を Gemini で日本語化したものです。Claude 自身は原文を読みます。誤訳がある場合は原文をご確認ください。

[Skill 名] port-allocator

ポートアロケーター

package.json を含む実際のプロジェクトにのみポートを割り当てるスマートなポートアロケーターです。

使用方法

コマンド 説明
/port-allocator 現在のプロジェクトのポートを割り当て/照会します
/port-allocator list 割り当てられているすべてのポートを一覧表示します
/port-allocator scan コードディレクトリをスキャンし、新しいプロジェクトを検出してポートを割り当てます
/port-allocator config <path> メインのコードディレクトリパスを設定します
/port-allocator add <dir-path> プロジェクトのポート割り当てを手動で追加します
/port-allocator allow このスキルが使用するコマンドの Claude Code 権限を設定します

重要なルール

1. サービス再起動時は現在のプロジェクトのポートのみを操作する

開発サーバーを再起動する際は、現在のプロジェクトのポート範囲内のプロセスのみを終了し、他のポートには決して影響を与えないでください。

# 正しい例: 現在のプロジェクトのポートのみを終了します (例: 3000-3009)
lsof -ti:3000 | xargs kill -9 2>/dev/null
lsof -ti:3001 | xargs kill -9 2>/dev/null

# 間違った例: すべての node プロセスまたは他のポートを終了します
pkill -f node  # 他のプロジェクトに影響を与えます!
lsof -ti:3010 | xargs kill  # これは別のプロジェクトのポートです!

2. CLAUDE.md を更新する際は上書きではなく追記する

~/.claude/CLAUDE.md を更新する際は、ユーザーの既存のコンテンツを保持する必要があります。

# 正しい例: 特定のセクションを確認して追記または更新します
# 間違った例: ファイル全体を直接上書きします

実行手順

コマンド: /port-allocator allow

このスキルが使用するコマンドを Claude Code が許可するように設定し、毎回手動で確認する手間を省きます。

  1. ~/.claude/settings.json を読み込みます (存在する場合)
  2. 以下のコマンドを permissions.allow 配列にマージします (既存の設定は保持します)。
{
  "permissions": {
    "allow": [
      "Bash(ls -d *)",
      "Bash(find * -maxdepth * -name package.json *)",
      "Bash(cat ~/.claude/*)",
      "Bash(dirname *)",
      "Bash(lsof -i:3*)",
      "Bash(lsof -ti:3*)"
    ]
  }
}
  1. 更新された settings.json を書き込みます
  2. 追加された権限のリストを出力します

出力形式:

Claude Code の権限を設定しました

追加された許可コマンドパターン:
  - Bash(ls -d *)
  - Bash(find * -maxdepth * -name package.json *)
  - Bash(cat ~/.claude/*)
  - Bash(lsof -i:3*)
  - Bash(lsof -ti:3*)

設定ファイル: ~/.claude/settings.json

コマンド: /port-allocator config <path>

ユーザーのメインのコードディレクトリを設定します。

  1. パスが存在することを確認します (必須です!見つからない場合はエラーを出力して終了します)
  2. ~/.claude/port-registry.jsoncode_root フィールドを更新します
  3. 確認メッセージを出力します

初回実行: 自動検出

初回実行時 (~/.claude/port-registry.json が存在しないか、code_root がない場合) は、コードディレクトリを自動的に検出します。

# 一般的なコードディレクトリを確認します
for dir in ~/Codes ~/Code ~/Projects ~/Dev ~/Development ~/repos; do
  if [ -d "$dir" ]; then
    CODE_ROOT="$dir"
    break
  fi
done

# 存在しない場合は、~/Codes をデフォルトとします
CODE_ROOT="${CODE_ROOT:-~/Codes}"

自動検出の出力:

初回実行です。コードディレクトリを検出しています...

コードディレクトリが検出されました: ~/Codes

ポートレジストリが初期化されました: ~/.claude/port-registry.json

変更するには、以下を使用してください:
   /port-allocator config ~/your/code/path

ディレクトリが見つからなかった場合:

コードディレクトリを自動検出できませんでした。

手動で設定してください:
   /port-allocator config ~/your/code/path

一般的な場所:
   ~/Codes, ~/Code, ~/Projects, ~/Dev

コマンド: /port-allocator scan

コードディレクトリをスキャンし、プロジェクトを自動的に検出して登録します。

  1. ~/.claude/port-registry.json を読み込み、code_root を取得します
    • 設定が存在しない場合は、まず自動検出を実行します
    • code_root ディレクトリが存在しない場合は、ユーザーに設定を促します
  2. package.json を含むすべてのディレクトリを検索します (package.json の正確な場所まで)。
# すべての package.json を検索し、ビルド成果物ディレクトリを除外します
find <code_root> -maxdepth 3 -name "package.json" -type f \
  -not -path "*/.next/*" \
  -not -path "*/node_modules/*" \
  -not -path "*/dist/*" \
  -not -path "*/build/*" | while read pkg; do
  dirname "$pkg"
done
  1. 重要: パスは package.json を含むディレクトリに正確である必要があります

    • 正しい例: ~/Codes/chekusu/landing
    • 間違った例: ~/Codes/chekusu (package.json がサブディレクトリにある場合)
  2. 検出された各プロジェクトディレクトリについて:

    • レジストリにすでに存在するかどうかを確認します
    • 存在しない場合は、次に利用可能なポート範囲を割り当てます
  3. 設定ファイルを更新します (追記モードで、ユーザーのコンテンツを上書きしないでください)

  4. スキャン結果の概要を出力します

コマンド: /port-allocator (デフォルト)

現在のプロジェクトのポートを割り当て/照会します。

  1. 現在の作業ディレクトリを取得します
  2. 設定を読み込み、code_root と割り当てられたポートを取得します
  3. 現在のディレクトリを対応するプロジェクトに一致させます
  4. package.json がない場合は、ポートを必要としないプロジェクトであることを示します
  5. 存在する場合は、ポートがすでに割り当てられているかを確認し、割り当てられていない場合は自動的に割り当てます
  6. ポート情報を出力します

コマンド: /port-allocator list

割り当てられているすべてのポートを一覧表示します (読み取り専用操作)。

出力形式

ポート情報

プロジェクトディレクトリ: ~/Codes/chekusu/landing
package.json: 検出済み
ポート範囲: 3000-3009
   - メインアプリ: 3000
   - API: 3001
   - その他のサービス: 3002-3009

警告: サービスを再起動する際は、ポート 3000-3009 のみで操作してください!

スキャン結果

スキャン完了: ~/Codes

登録済みプロジェクト (N):
   - chekusu/landing: 3000-3009
   - saifuri: 3010-3019

新規検出プロジェクト (M):
   - new-project: 3090-3099 (新規割り当て)

スキップ済み (K):
   - .next, node_modules (ビルド成果物)
   - research-folder (package.json がありません)

ポート割り当てルール

  • 各プロジェクトには連続する10個のポートが割り当てられます
  • 開始ポート: 3000
  • 間隔: 10
  • x0: メインアプリケーション (例: 3000, 3010, 3020)
  • x1: APIサービス (例: 3001, 3011, 3021)
  • x2-x9: その他のサービス (データベース、キャッシュなど)

設定ファイル

  • ポートレジストリ: ~/.claude/port-registry.json
  • グローバル指示: ~/.claude/CLAUDE.md (追記モードで更新)
  • Claude Code 設定: ~/.claude/settings.json (allowedCommands を保存)
  • **スキップ

(原文がここで切り詰められています)

📜 原文 SKILL.md(Claudeが読む英語/中国語)を展開

Port Allocator

Smart port allocator that only assigns ports to real projects containing package.json.

Usage

Command Description
/port-allocator Allocate/query port for current project
/port-allocator list List all allocated ports
/port-allocator scan Scan code directory, discover and allocate ports for new projects
/port-allocator config <path> Set the main code directory path
/port-allocator add <dir-path> Manually add port allocation for a project
/port-allocator allow Configure Claude Code permissions for this skill's commands

Important Rules

1. Only Operate on Current Project's Ports When Restarting Services

When restarting the development server, only kill processes within the current project's port range, never affect other ports:

# Correct: Only kill current project ports (e.g., 3000-3009)
lsof -ti:3000 | xargs kill -9 2>/dev/null
lsof -ti:3001 | xargs kill -9 2>/dev/null

# Wrong: Kill all node processes or other ports
pkill -f node  # Will affect other projects!
lsof -ti:3010 | xargs kill  # This is another project's port!

2. Append Rather Than Overwrite When Updating CLAUDE.md

When updating ~/.claude/CLAUDE.md, must preserve the user's existing content:

# Correct: Check and append or update specific sections
# Wrong: Directly overwrite the entire file

Execution Steps

Command: /port-allocator allow

Configure Claude Code to allow commands used by this skill, avoiding manual confirmation each time:

  1. Read ~/.claude/settings.json (if exists)
  2. Merge the following commands into permissions.allow array (preserve existing config):
{
  "permissions": {
    "allow": [
      "Bash(ls -d *)",
      "Bash(find * -maxdepth * -name package.json *)",
      "Bash(cat ~/.claude/*)",
      "Bash(dirname *)",
      "Bash(lsof -i:3*)",
      "Bash(lsof -ti:3*)"
    ]
  }
}
  1. Write updated settings.json
  2. Output the list of added permissions

Output Format:

Configured Claude Code permissions

Added allowed command patterns:
  - Bash(ls -d *)
  - Bash(find * -maxdepth * -name package.json *)
  - Bash(cat ~/.claude/*)
  - Bash(lsof -i:3*)
  - Bash(lsof -ti:3*)

Config file: ~/.claude/settings.json

Command: /port-allocator config <path>

Set the user's main code directory:

  1. Verify path exists (required! Error and exit if not found)
  2. Update code_root field in ~/.claude/port-registry.json
  3. Output confirmation

First Run: Auto-Detection

On first run (when ~/.claude/port-registry.json doesn't exist or has no code_root), automatically detect the code directory:

# Check common code directories
for dir in ~/Codes ~/Code ~/Projects ~/Dev ~/Development ~/repos; do
  if [ -d "$dir" ]; then
    CODE_ROOT="$dir"
    break
  fi
done

# If none exist, default to ~/Codes
CODE_ROOT="${CODE_ROOT:-~/Codes}"

Auto-detection output:

First run, detecting code directory...

Code directory detected: ~/Codes

Port registry initialized: ~/.claude/port-registry.json

To change, use:
   /port-allocator config ~/your/code/path

If no directory found:

Could not auto-detect code directory.

Please configure manually:
   /port-allocator config ~/your/code/path

Common locations:
   ~/Codes, ~/Code, ~/Projects, ~/Dev

Command: /port-allocator scan

Scan code directory, automatically discover and register projects:

  1. Read ~/.claude/port-registry.json to get code_root
    • If config doesn't exist, run auto-detection first
    • If code_root directory doesn't exist, prompt user to configure
  2. Find all directories containing package.json (exact to package.json location):
# Find all package.json, exclude build artifact directories
find <code_root> -maxdepth 3 -name "package.json" -type f \
  -not -path "*/.next/*" \
  -not -path "*/node_modules/*" \
  -not -path "*/dist/*" \
  -not -path "*/build/*" | while read pkg; do
  dirname "$pkg"
done
  1. Important: Path must be exact to the directory containing package.json

    • Correct: ~/Codes/chekusu/landing
    • Wrong: ~/Codes/chekusu (if package.json is in subdirectory)
  2. For each discovered project directory:

    • Check if already in registry
    • If not, allocate next available port range
  3. Update config file (append mode, don't overwrite user content)

  4. Output scan result summary

Command: /port-allocator (default)

Allocate/query port for current project:

  1. Get current working directory
  2. Read config to get code_root and allocated ports
  3. Match current directory to corresponding project
  4. If no package.json, indicate this is not a project needing ports
  5. If exists, check if port already allocated, auto-allocate if not
  6. Output port info

Command: /port-allocator list

List all allocated ports (read-only operation).

Output Format

Port Information

Project directory: ~/Codes/chekusu/landing
package.json: Detected
Port range: 3000-3009
   - Main app: 3000
   - API: 3001
   - Other services: 3002-3009

Warning: Only operate on ports 3000-3009 when restarting services!

Scan Results

Scan complete: ~/Codes

Registered projects (N):
   - chekusu/landing: 3000-3009
   - saifuri: 3010-3019

Newly discovered projects (M):
   - new-project: 3090-3099 (newly allocated)

Skipped (K):
   - .next, node_modules (build artifacts)
   - research-folder (no package.json)

Port Allocation Rules

  • Each project is allocated 10 consecutive ports
  • Starting port: 3000
  • Interval: 10
  • x0: Main application (e.g., 3000, 3010, 3020)
  • x1: API service (e.g., 3001, 3011, 3021)
  • x2-x9: Other services (database, cache, etc.)

Configuration Files

  • Port registry: ~/.claude/port-registry.json
  • Global instructions: ~/.claude/CLAUDE.md (append mode updates)
  • Claude Code settings: ~/.claude/settings.json (stores allowedCommands)
  • Skip patterns: .next, node_modules, dist, build

Notes

  1. Only operate on project ports - Never affect other projects when restarting services
  2. Append not overwrite - Preserve user's existing content when updating config files
  3. Precise paths - Point to actual directory containing package.json
  4. Skip build artifacts - .next, node_modules, etc. don't get port allocation
  5. First use - Recommend running /port-allocator allow to configure permissions first