portman

Port management for local development with git worktrees. Use when setting up local development environments, booking ports for services to avoid collisions between parallel worktrees, or configuring docker-compose with dynamic ports.

9 stars

Best use case

portman is best used when you need a repeatable AI agent workflow instead of a one-off prompt.

Port management for local development with git worktrees. Use when setting up local development environments, booking ports for services to avoid collisions between parallel worktrees, or configuring docker-compose with dynamic ports.

Teams using portman should expect a more consistent output, faster repeated execution, less prompt rewriting.

When to use this skill

  • You want a reusable workflow that can be run more than once with consistent structure.

When not to use this skill

  • You only need a quick one-off answer and do not need a reusable workflow.
  • You cannot install or maintain the underlying files, dependencies, or repository context.

Installation

Claude Code / Cursor / Codex

$curl -o ~/.claude/skills/portman/SKILL.md --create-dirs "https://raw.githubusercontent.com/jpoutrin/product-forge/main/plugins/devops-data/skills/portman/SKILL.md"

Manual Installation

  1. Download SKILL.md from GitHub
  2. Place it in .claude/skills/portman/SKILL.md inside your project
  3. Restart your AI agent — it will auto-discover the skill

How portman Compares

Feature / AgentportmanStandard Approach
Platform SupportNot specifiedLimited / Varies
Context Awareness High Baseline
Installation ComplexityUnknownN/A

Frequently Asked Questions

What does this skill do?

Port management for local development with git worktrees. Use when setting up local development environments, booking ports for services to avoid collisions between parallel worktrees, or configuring docker-compose with dynamic ports.

Where can I find the source code?

You can find the source code on GitHub using the link provided at the top of the page.

SKILL.md Source

# Portman Skill

This skill provides patterns for managing port allocations in local development environments using portman. It enables running multiple worktrees of the same project in parallel without port conflicts.

## Why Portman?

When working with git worktrees or multiple project instances:
- Each worktree needs unique ports for services (postgres, redis, web server, etc.)
- Manual port management is error-prone and tedious
- Docker-compose files hardcode ports causing conflicts

Portman automatically assigns unique ports per worktree context.

## Core Workflow

### 1. Initial Setup (Once per machine)

```bash
# Initialize portman and show shell integration
portman init

# For direnv users (recommended)
portman init --direnv
```

### 2. Setting Up a New Worktree

When cloning or creating a new worktree, book ports for all services:

```bash
# Auto-discover services from docker-compose.yml
portman book --auto

# Or book specific services
portman book postgres
portman book redis
portman book frontend --port 3000
```

### 3. Using Ports in Your Environment

```bash
# Export as environment variables (add to .envrc for direnv)
eval "$(portman export --auto)"

# Get a specific port
PGPORT=$(portman get postgres -q)
```

## Command Reference

| Command | Description | Example |
|---------|-------------|---------|
| `portman book` | Reserve ports for services | `portman book --auto` |
| `portman get` | Get port for a service | `portman get postgres -q` |
| `portman export` | Export as env vars | `eval "$(portman export)"` |
| `portman status` | Show current allocations | `portman status --all` |
| `portman release` | Free port allocations | `portman release --all` |
| `portman context` | Show current context | `portman context` |
| `portman discover` | Preview auto-discovery | `portman discover` |
| `portman prune` | Clean orphaned allocations | `portman prune --dry-run` |

## Integration with Docker Compose

### Dynamic Port Configuration

Use environment variables in `docker-compose.yml`:

```yaml
services:
  postgres:
    image: postgres:16
    ports:
      - "${POSTGRES_PORT:-5432}:5432"
    environment:
      POSTGRES_PASSWORD: dev

  redis:
    image: redis:7
    ports:
      - "${REDIS_PORT:-6379}:6379"

  web:
    build: .
    ports:
      - "${WEB_PORT:-8000}:8000"
    environment:
      DATABASE_URL: postgres://localhost:${POSTGRES_PORT:-5432}/app
```

### Direnv Integration (.envrc)

```bash
# .envrc - Automatically set ports when entering directory
eval "$(portman export --auto)"

# Or with fallbacks
export POSTGRES_PORT=$(portman get postgres -q 2>/dev/null || echo 5432)
export REDIS_PORT=$(portman get redis -q 2>/dev/null || echo 6379)
export WEB_PORT=$(portman get web -q 2>/dev/null || echo 8000)
```

## Context-Aware Port Allocation

Portman uses the current directory and git remote to create a unique context:

```bash
# View your current context
portman context

# Output:
# Context: abc123
# Path: /home/user/projects/myapp-feature-x
# Git Remote: github.com/org/myapp
# Git Branch: feature-x
```

Each worktree gets its own context, ensuring port isolation.

## Port Ranges Configuration

Configure port ranges per service:

```bash
# Set custom range for postgres
portman config --set-range postgres:5500-5599

# View current configuration
portman config --show
```

## Maintenance Commands

### View All Allocations

```bash
# Show current context only
portman status

# Show all contexts
portman status --all

# Check if ports are actually listening
portman status --all --live
```

### Cleanup Orphaned Allocations

```bash
# Preview what would be removed
portman prune --dry-run

# Remove allocations for deleted worktrees
portman prune

# Also remove stale allocations (not accessed in 30 days)
portman prune --stale 30
```

## Common Patterns

### Setup Script for New Developers

```bash
#!/bin/bash
# scripts/dev-setup.sh

# Book ports for all services
portman book --auto

# Show allocated ports
portman status

# Export for current shell
eval "$(portman export --auto)"

echo "Development environment ready!"
echo "PostgreSQL: localhost:$POSTGRES_PORT"
echo "Redis: localhost:$REDIS_PORT"
```

### Makefile Integration

```makefile
.PHONY: setup ports

setup:
	portman book --auto
	@echo "Ports allocated. Run 'make ports' to see them."

ports:
	@portman status

start:
	eval "$$(portman export --auto)" && docker-compose up
```

### CI/CD Considerations

In CI environments, portman context is unique per workspace, allowing parallel CI jobs:

```yaml
# GitHub Actions
jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Setup ports
        run: |
          portman book --auto
          eval "$(portman export --auto)"
      - name: Run tests
        run: docker-compose up -d && pytest
```

## Troubleshooting

### Port Already in Use

```bash
# Check what's using a port
portman status --all --live

# Release and rebook
portman release postgres
portman book postgres
```

### Reset All Allocations

```bash
# Release all for current context
portman release --all

# Rebook
portman book --auto
```

Related Skills

zod

9
from jpoutrin/product-forge

Zod schema validation patterns and type inference. Auto-loads when validating schemas, parsing data, validating forms, checking types at runtime, or using z.object/z.string/z.infer in TypeScript.

typescript-import-style

9
from jpoutrin/product-forge

Merge-friendly import formatting (one-per-line, alphabetical). Auto-loads when writing TypeScript/JavaScript imports to minimize merge conflicts in parallel development. Enforces consistent grouping and sorting.

setup-mcp-auth

9
from jpoutrin/product-forge

Configure authentication for an existing FastMCP server

fastmcp

9
from jpoutrin/product-forge

FastMCP TypeScript framework patterns for MCP servers. Auto-loads when building MCP servers, creating tools/resources/prompts, implementing authentication, configuring transports, or working with FastMCP in TypeScript.

add-mcp-tool

9
from jpoutrin/product-forge

Add a new tool to an existing FastMCP server with guided configuration

add-mcp-resource

9
from jpoutrin/product-forge

Add a new resource or resource template to an existing FastMCP server

plan-with-team

9
from jpoutrin/product-forge

Validate plan file ownership

privacy-compliance

9
from jpoutrin/product-forge

GDPR, CCPA, and privacy compliance guidance for data protection. Use when handling personal data, implementing consent management, or ensuring regulatory compliance across jurisdictions.

oauth

9
from jpoutrin/product-forge

OAuth 2.0 and OpenID Connect implementation patterns. Use when implementing authentication, authorization flows, or integrating with OAuth providers like Google, GitHub, or custom identity providers.

mcp-security

9
from jpoutrin/product-forge

Use when securing MCP servers, preventing prompt injection, implementing authorization, validating user input, or building secure multi-agent pipelines. Provides 5-layer defense architecture patterns.

rag-cag-security

9
from jpoutrin/product-forge

Security patterns for RAG and CAG systems with multi-tenant isolation. Use when building retrieval-augmented or cache-augmented generation systems that require tenant isolation, access control, and secure data handling.

chunking-strategies

9
from jpoutrin/product-forge

Document chunking strategies for RAG systems. Use when implementing document processing pipelines to determine optimal chunking approaches based on document type and retrieval requirements.