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本体の挙動とは独立した参考情報です。
下記のコマンドをコピーしてターミナル(Mac/Linux)または PowerShell(Windows)に貼り付けてください。 ダウンロード → 解凍 → 配置まで全自動。
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
$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. 下の青いボタンを押して
port-allocator.zipをダウンロード - 2. ZIPファイルをダブルクリックで解凍 →
port-allocatorフォルダができる - 3. そのフォルダを
C:\Users\あなたの名前\.claude\skills\(Win)または~/.claude/skills/(Mac)へ移動 - 4. Claude Code を再起動
⚠️ ダウンロード・利用は自己責任でお願いします。当サイトは内容・動作・安全性について責任を負いません。
🎯 このSkillでできること
下記の説明文を読むと、このSkillがあなたに何をしてくれるかが分かります。Claudeにこの分野の依頼をすると、自動で発動します。
📦 インストール方法 (3ステップ)
- 1. 上の「ダウンロード」ボタンを押して .skill ファイルを取得
- 2. ファイル名の拡張子を .skill から .zip に変えて展開(macは自動展開可)
- 3. 展開してできたフォルダを、ホームフォルダの
.claude/skills/に置く- · macOS / Linux:
~/.claude/skills/ - · Windows:
%USERPROFILE%\.claude\skills\
- · macOS / Linux:
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 が許可するように設定し、毎回手動で確認する手間を省きます。
~/.claude/settings.jsonを読み込みます (存在する場合)- 以下のコマンドを
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*)"
]
}
}
- 更新された settings.json を書き込みます
- 追加された権限のリストを出力します
出力形式:
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>
ユーザーのメインのコードディレクトリを設定します。
- パスが存在することを確認します (必須です!見つからない場合はエラーを出力して終了します)
~/.claude/port-registry.jsonのcode_rootフィールドを更新します- 確認メッセージを出力します
初回実行: 自動検出
初回実行時 (~/.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
コードディレクトリをスキャンし、プロジェクトを自動的に検出して登録します。
~/.claude/port-registry.jsonを読み込み、code_rootを取得します- 設定が存在しない場合は、まず自動検出を実行します
code_rootディレクトリが存在しない場合は、ユーザーに設定を促します
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
-
重要: パスは
package.jsonを含むディレクトリに正確である必要があります- 正しい例:
~/Codes/chekusu/landing - 間違った例:
~/Codes/chekusu(package.json がサブディレクトリにある場合)
- 正しい例:
-
検出された各プロジェクトディレクトリについて:
- レジストリにすでに存在するかどうかを確認します
- 存在しない場合は、次に利用可能なポート範囲を割り当てます
-
設定ファイルを更新します (追記モードで、ユーザーのコンテンツを上書きしないでください)
-
スキャン結果の概要を出力します
コマンド: /port-allocator (デフォルト)
現在のプロジェクトのポートを割り当て/照会します。
- 現在の作業ディレクトリを取得します
- 設定を読み込み、
code_rootと割り当てられたポートを取得します - 現在のディレクトリを対応するプロジェクトに一致させます
package.jsonがない場合は、ポートを必要としないプロジェクトであることを示します- 存在する場合は、ポートがすでに割り当てられているかを確認し、割り当てられていない場合は自動的に割り当てます
- ポート情報を出力します
コマンド: /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:
- Read
~/.claude/settings.json(if exists) - Merge the following commands into
permissions.allowarray (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*)"
]
}
}
- Write updated settings.json
- 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:
- Verify path exists (required! Error and exit if not found)
- Update
code_rootfield in~/.claude/port-registry.json - 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:
- Read
~/.claude/port-registry.jsonto getcode_root- If config doesn't exist, run auto-detection first
- If
code_rootdirectory doesn't exist, prompt user to configure
- 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
-
Important: Path must be exact to the directory containing
package.json- Correct:
~/Codes/chekusu/landing - Wrong:
~/Codes/chekusu(if package.json is in subdirectory)
- Correct:
-
For each discovered project directory:
- Check if already in registry
- If not, allocate next available port range
-
Update config file (append mode, don't overwrite user content)
-
Output scan result summary
Command: /port-allocator (default)
Allocate/query port for current project:
- Get current working directory
- Read config to get
code_rootand allocated ports - Match current directory to corresponding project
- If no
package.json, indicate this is not a project needing ports - If exists, check if port already allocated, auto-allocate if not
- 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
- Only operate on project ports - Never affect other projects when restarting services
- Append not overwrite - Preserve user's existing content when updating config files
- Precise paths - Point to actual directory containing package.json
- Skip build artifacts - .next, node_modules, etc. don't get port allocation
- First use - Recommend running
/port-allocator allowto configure permissions first