port-manager
Skill1 starsChanged 7 months agoMITView on GitHub
Manage cross-project localhost port allocation. Prevents port conflicts when multiple Claude Code instances work on different projects simultaneously. The PreToolUse hook (check-port.sh) uses two layers of detection: Regex patterns matched against Bash command strings: When npm run dev, pnpm dev, bun run dev, etc. are detected: The hook resolves the current project name by walking up from $PWD to find the nearest .git directory or CLAUDE.md file. This correctly handles monorepo subdirectories (e.g., my-app/packages/client/ resolves to my-app). Installed to ~/.claude/skills/port-manager/scripts/port-helpers.sh,…
- Reads credentials
In this repository14 other files it gives its agents.
- brew-maintainSkill
- cc-updatesSkill
- commit-helperSkill
- dev-consoleSkill
- explain-codeSkill
- init-modularSkill
- learnSkill
- plan-debateSkill
- product-contextSkill
- projectSkill
- refactorSkill
- techdebtSkill
- ui-specSkill
- web-researcherSkill
The file
We split this skill into the rules it gives an agent
1 rule. About 0 are common, 0 are distinctive, and 1 is very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈0
Distinctive · estimate
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 65
When npm run dev, pnpm dev, bun run dev, etc.
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
port-manager
Manage cross-project localhost port allocation. Prevents port conflicts when multiple Claude Code instances work on different projects simultaneously.
Architecture
~/.claude/
├── port-registry.json # Central registry (source of truth)
├── hooks/
│ └── check-port.sh # PreToolUse hook (auto-installed)
└── skills/
└── port-manager/
├── SKILL.md # This file
├── port-manager.md # Command definition
├── scripts/
│ ├── setup.sh # One-click installer
│ ├── check-port.sh # Hook script source
│ └── port-helpers.sh # Shell helper functions
└── examples/
└── port-registry.example.json # Registry templatePort Registry Format
{
"version": "1.0.0",
"updated_at": "2026-02-08",
"port_ranges": {
"reserved": { "min": 1024, "max": 8999, "description": "Project ports" },
"available": { "min": 9000, "max": 9999, "description": "Allocation pool" },
"system": { "min": 1, "max": 1023, "description": "System reserved" }
},
"ports": {
"3000": {
"project": "my-app",
"service": "Backend API (Koa)",
"added": "2026-02-08"
}
}
}Detection Mechanism
The PreToolUse hook (check-port.sh) uses two layers of detection:
Layer 1: Explicit Port Detection
Regex patterns matched against Bash command strings:
| Pattern | Example |
PORT=XXXX | PORT=3000 node server.js |
--port XXXX / --port=XXXX | vite --port 5173 |
-p XXXX / -p=XXXX | docker run -p 8080:80 |
localhost:XXXX | curl localhost:3000 |
127.0.0.1:XXXX | curl 127.0.0.1:8080 |
0.0.0.0:XXXX | nc -l 0.0.0.0:9000 |
.listen(XXXX | app.listen(3000) |
Layer 2: Indirect Startup Detection
When npm run dev, pnpm dev, bun run dev, etc. are detected:
- package.json scripts — extract
--portfrom script commands - vite.config.{ts,js,mts,mjs} — extract
port:value - next.config.{js,mjs,ts} — extract
port:value - .env / .env.local / .env.development — extract
PORT=,VITE_PORT=,DEV_PORT= - Registry fallback — if no port found in config files, look up all ports registered to the current project and check if they're occupied
Project Resolution
The hook resolves the current project name by walking up from $PWD to find the nearest .git directory or CLAUDE.md file. This correctly handles monorepo subdirectories (e.g., my-app/packages/client/ resolves to my-app).
Conflict Actions
| Scenario | Action |
| Port belongs to other project | Block (exit 2) with conflict message |
| Port belongs to current project, occupied | Allow with warning |
| Port belongs to current project, free | Allow silently |
| Port not registered, occupied | Allow with warning to register |
| Port not registered, free | Allow silently |
Shell Helper Functions
Installed to ~/.claude/skills/port-manager/scripts/port-helpers.sh, sourced via ~/.zshrc:
| Function | Usage | Description |
port-check <port> | port-check 3000 | Check registry + lsof status |
port-find [count] | port-find 5 | Find available ports in 9000-9999 |
port-reserve <port> <project> [service] | port-reserve 9001 my-app "API" | Register a port |
port-release <port> | port-release 9001 | Unregister a port |
port-status | port-status | Full status report |
Setup Components
The /port-manager setup command installs:
- Port registry —
~/.claude/port-registry.json(from template) - Hook script —
~/.claude/hooks/check-port.sh - PreToolUse hook config — added to
~/.claude/settings.json - SessionStart integration — port summary in
~/.claude/hooks/session-start.sh - Shell functions — source reference in
~/.zshrc - CLAUDE.md section — port management rules appended
Uninstall
# Remove registry
rm ~/.claude/port-registry.json
# Remove hook
rm ~/.claude/hooks/check-port.sh
# Manual cleanup needed:
# - ~/.claude/settings.json: remove PreToolUse hook entry for check-port
# - ~/.claude/hooks/session-start.sh: remove port summary section
# - ~/.zshrc: remove port-helpers.sh source line
# - ~/.claude/CLAUDE.md: remove port management sectionKnown Limitations
| Limitation | Workaround |
| Docker Compose port mappings | Register ports manually via /port-manager reserve |
| Direct terminal usage (outside Claude Code) | Use port-status shell function |
Ports in deep config files (e.g., src/config.ts) | Register in port-registry.json |
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

