agentleFS
almax000almax000/claude-skills/port-manager/SKILL.md

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

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
  1. Very specific:

    When npm run dev, pnpm dev, bun run dev, etc.

    line 65

≈ “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.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

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 template

Port 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:

PatternExample
PORT=XXXXPORT=3000 node server.js
--port XXXX / --port=XXXXvite --port 5173
-p XXXX / -p=XXXXdocker run -p 8080:80
localhost:XXXXcurl localhost:3000
127.0.0.1:XXXXcurl 127.0.0.1:8080
0.0.0.0:XXXXnc -l 0.0.0.0:9000
.listen(XXXXapp.listen(3000)

Layer 2: Indirect Startup Detection

When npm run dev, pnpm dev, bun run dev, etc. are detected:

  1. package.json scripts — extract --port from script commands
  2. vite.config.{ts,js,mts,mjs} — extract port: value
  3. next.config.{js,mjs,ts} — extract port: value
  4. .env / .env.local / .env.development — extract PORT=, VITE_PORT=, DEV_PORT=
  5. 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

ScenarioAction
Port belongs to other projectBlock (exit 2) with conflict message
Port belongs to current project, occupiedAllow with warning
Port belongs to current project, freeAllow silently
Port not registered, occupiedAllow with warning to register
Port not registered, freeAllow silently

Shell Helper Functions

Installed to ~/.claude/skills/port-manager/scripts/port-helpers.sh, sourced via ~/.zshrc:

FunctionUsageDescription
port-check <port>port-check 3000Check registry + lsof status
port-find [count]port-find 5Find available ports in 9000-9999
port-reserve <port> <project> [service]port-reserve 9001 my-app "API"Register a port
port-release <port>port-release 9001Unregister a port
port-statusport-statusFull status report

Setup Components

The /port-manager setup command installs:

  1. Port registry — ~/.claude/port-registry.json (from template)
  2. Hook script — ~/.claude/hooks/check-port.sh
  3. PreToolUse hook config — added to ~/.claude/settings.json
  4. SessionStart integration — port summary in ~/.claude/hooks/session-start.sh
  5. Shell functions — source reference in ~/.zshrc
  6. 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 section

Known Limitations

LimitationWorkaround
Docker Compose port mappingsRegister 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

Download now (ZIP)

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
What did you use it for? e.g. Reviewing pull requests in a Rails app

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.