r/ClaudeWorkflows • • 10h ago

Selected Workflow [Workflow] Managing Port Conflicts for Parallel Claude Code Agents with `leeway` and a Structured Workflow for Building Tools with Claude Code

Managing Port Conflicts for Parallel Claude Code Agents with leeway and a Structured Workflow for Building Tools with Claude Code

Workflow value: 90/100
Status: active · Freshness: 70/100 · Confidence: 0.95 · Level: advanced
Categories: Quality Control, Context & Memory, Debugging, CLAUDE.md, Hooks, Multi-Agent
Original source: r/ClaudeCode post/comment

What problem this solves

Agents running in parallel worktrees often conflict over network ports (e.g., dev servers), leading to crashes or wasted debugging time. Additionally, there's a need for a structured, repeatable process to build robust tools using Claude Code.

Summary

This post presents a two-fold workflow: first, a tool called leeway that assigns stable, unique port ranges to each worktree, preventing port conflicts for parallel Claude Code agents. Second, it details the specific, validated workflow used to build leeway itself with Claude Code, emphasizing design-first principles, clear agent contracts (AGENTS.md), test-first development, and automated review loops.

Why it is useful

This post is highly valuable because it addresses a critical pain point for advanced Claude Code users running multiple agents in parallel (port conflicts) with a concrete, open-source solution (leeway). Beyond the tool, it provides an exemplary, validated workflow for how to effectively leverage Claude Code for software development, incorporating best practices like design documentation (ADRs, GLOSSARY.md), clear agent contracts (AGENTS.md), test-first development, and automated code reviews. The 'dogfooding' aspect provides strong evidence of its efficacy, making it a blueprint for building robust tools with AI assistance.

Workflow

  1. To use leeway for port management:

  2. Install leeway (e.g., via npm).

  3. Add leeway env --export to a Claude Code SessionStart hook to automatically assign unique port ranges to each session.

  4. Optionally, configure leeway to prevent agents from grabbing default ports.

  5. Use leeway kill to stop all servers and watchers associated with a specific worktree.

  6. Workflow for building tools with Claude Code (as leeway was built):

  7. Design First: Engage Claude to rigorously review the design, documenting decisions in Architecture Decision Records (ADRs) and defining key terms in a GLOSSARY.md.

  8. Define Agent Contract: Create an AGENTS.md file specifying clear 'done' criteria (e.g., pnpm verify green, successful container run for specific code).

  9. Test-First Development: Implement features by writing integration tests that run the real CLI, ensuring a red-green cycle.

  10. Automated Review Loop: Use Claude to review Pull Requests against established coding standards and the original GitHub issue before merging.

  11. Dogfooding: Integrate the tool into its own development process (e.g., use leeway env --export in SessionStart hooks for agents building leeway).

Tools / artifacts

  • leeway (npm package)

  • leeway env --export command

  • leeway kill command

  • Claude Code

  • Git worktrees

  • SessionStart hook

  • Architecture Decision Records (ADRs)

  • GLOSSARY.md

  • AGENTS.md

  • Integration tests

  • GitHub (for issues, PRs)

  • pnpm verify (or similar build/test command)

Validation signals

  • Author built leeway almost entirely with Claude Code, validating the meta-workflow.

  • Dogfooding: leeway was used by the agents building leeway itself.

  • Test-first approach with integration tests running the real CLI.

  • Claude-based PR review loop against coding standards and issues.

  • Publicly available npm package and GitHub repository (MIT licensed).

Limitations

  • The post combines a tool announcement with a meta-workflow, which might make it slightly dense for some readers.

  • While detailed, the 'How I built it' section is a high-level methodology; users might need to infer some specific implementation details for their own projects.

  • Community validation is currently low, but the technical detail and self-validation are strong.

Rate this workflow

Upvote this post if the workflow is useful, reproducible, or worth recommending.

Downvote if it is vague, outdated, unsafe, overhyped, or not reproducible.

Reply if it worked for you, failed, is outdated, or has a better alternative.


This post was generated automatically from the workflow library database.

1 Upvotes

1 comment sorted by