port-allocator
БесплатноБез исполняемых скриптовНе проверенAutomatically allocate and manage development server ports, avoiding port conflicts between multiple Claude Code instances
Об этом скилле
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/c
Установить port-allocator в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
FAQ
Что делает скилл port-allocator?
Automatically allocate and manage development server ports, avoiding port conflicts between multiple Claude Code instances
Как установить скилл port-allocator?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл port-allocator запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
mcp-builder
Guide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when…
от Anthropicclaude-api
Reference for the Claude API / Anthropic SDK — model ids, pricing, params, streaming, tool use, MCP, agents, caching, token counting, model migration. TRIGGER…
от Anthropicalgorithmic-art
Creating algorithmic art using p5.js with seeded randomness and interactive parameter exploration. Use this when users request creating art using code…
от Anthropicmcp-integration
This skill should be used when the user asks to "add MCP server", "integrate MCP", "configure MCP in plugin", "use .mcp.json", "set up Model Context…
от Anthropic