Skip to content

Conversation

@berilevi
Copy link

@berilevi berilevi commented Nov 27, 2025

Adds a --host (alias -h) option to the start subcommand so users can bind the Copilot API server to a specific interface/IP (e.g. 127.0.0.1 or ::1) instead of all interfaces.

Changes

  • Extend RunServerOptions with host?: string.
  • Generate usage viewer URL using the provided host.
  • Pass hostname to serve(...); fallback (omitting --host) preserves previous behavior.
  • Add CLI argument definition (--host, -h).
  • Update README: option table plus usage examples for IPv4/IPv6 localhost.

Rationale

Binding to all interfaces (0.0.0.0 / ::) can unintentionally expose the API on shared or cloud hosts. Allowing explicit loopback binding improves security.

Backward Compatibility

No change for existing users who don’t supply --host. All interfaces remain default.

Testing

  • bun run build
  • bun run dist/main.js start --host 127.0.0.1 → confirmed 127.0.0.1:4141
  • bun run dist/main.js start --host ::1 → confirmed IPv6 loopback
  • Omitted --host → confirmed :::4141
  • Usage viewer link reflects chosen host.

Summary by CodeRabbit

New Features

  • Added --host (alias -h) option to the start command, enabling users to specify which host or interface the server listens on. Supports IPv4 localhost (127.0.0.1), IPv6 localhost (::1), and all interfaces. Updated documentation with configuration examples.

Documentation

  • Added usage examples demonstrating the new --host option with common configurations.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link

coderabbitai bot commented Nov 27, 2025

Walkthrough

This change introduces a new --host CLI option to the start command, enabling users to specify which network interface the server binds to (IPv4, IPv6, or default). The option is documented in README with usage examples and implemented in src/start.ts by threading the parameter through RunServerOptions to the underlying serve configuration.

Changes

Cohort / File(s) Summary
Documentation
README.md
Added --host option documentation with alias and description; included usage examples for IPv4 (127.0.0.1), IPv6 (::1), and default behavior (listen on all interfaces)
Start Command Implementation
src/start.ts
Extended RunServerOptions with optional host?: string property; updated start command definition to include host option (alias h); threaded host parameter from CLI args through runServer to serve configuration; introduced hostForUrl variable (currently unused)

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

  • Verify that hostForUrl variable is intentional or should be removed
  • Confirm the fallback behavior (hostname defaults to undefined) aligns with intended system behavior
  • Ensure README examples are accurate and cover documented use cases

Poem

🐰 A host of new options, binding tight,
IPv4, IPv6—listen where you like!
From CLI to serve, the parameter hops,
Flexibility flows where the rabbit stops! 🌐

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: adding a --host option to restrict the listening interface, which aligns directly with the changeset's primary objective.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Tip

📝 Customizable high-level summaries are now available in beta!

You can now customize how CodeRabbit generates the high-level summary in your pull requests — including its content, structure, tone, and formatting.

  • Provide your own instructions using the high_level_summary_instructions setting.
  • Format the summary however you like (bullet lists, tables, multi-section layouts, contributor stats, etc.).
  • Use high_level_summary_in_walkthrough to move the summary from the description to the walkthrough section.

Example instruction:

"Divide the high-level summary into five sections:

  1. 📝 Description — Summarize the main change in 50–60 words, explaining what was done.
  2. 📓 References — List relevant issues, discussions, documentation, or related PRs.
  3. 📦 Dependencies & Requirements — Mention any new/updated dependencies, environment variable changes, or configuration updates.
  4. 📊 Contributor Summary — Include a Markdown table showing contributions:
    | Contributor | Lines Added | Lines Removed | Files Changed |
  5. ✔️ Additional Notes — Add any extra reviewer context.
    Keep each section concise (under 200 words) and use bullet or numbered lists for clarity."

Note: This feature is currently in beta for Pro-tier users, and pricing will be announced later.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (3)
README.md (2)

154-167: Clarify default host wording in options table

The new --host row looks good and matches the implementation/CLI. Consider rewording the default from all (::) to something like all interfaces (system default) so users don’t confuse it with a literal :: hostname value.


168-185: --host examples are clear and helpful

The IPv4/IPv6 localhost examples and default behavior are well illustrated and align with the new CLI option. You might optionally add a short example using the -h alias for completeness, but the section is already solid as-is.

src/start.ts (1)

144-149: Check for potential -h (help) vs -h (host) alias conflict

Defining host with alias -h is intuitive, but many CLIs reserve -h for help. citty’s docs don’t clearly specify whether -h is used/reserved by your current entrypoint, so there’s some risk of confusing or overriding help behavior.

Please run your top‑level CLI with -h and --help (e.g., copilot-api -h, copilot-api --help, and copilot-api start -h) to confirm:

  • Help output is still accessible in the expected way.
  • -h correctly maps to --host where intended.

If there is a collision, consider switching the short flag to something like -H or dropping the short alias for host.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0ea08fe and 534f7df.

📒 Files selected for processing (2)
  • README.md (2 hunks)
  • src/start.ts (5 hunks)
🧰 Additional context used
🪛 ESLint
src/start.ts

[error] 69-69: 'hostForUrl' is assigned a value but never used. Allowed unused vars must match /^_/u.

(@typescript-eslint/no-unused-vars)


[error] 69-69: Replace 'localhost'; with "localhost"

(prettier/prettier)

🔇 Additional comments (3)
src/start.ts (3)

17-29: RunServerOptions.host field wiring is appropriate

Adding an optional host?: string here is a clean way to thread the CLI --host flag through to the server; the type and optionality both look correct.


115-123: Hostname forwarding into serve() matches srvx semantics

Passing hostname: options.host || undefined correctly lets srvx bind to the specified interface, and falls back to “all interfaces” when --host is omitted, which aligns with the srvx docs for the hostname option (undefined => all network interfaces). (srvx.h3.dev)

If you upgrade srvx later, please double‑check that this behavior remains the same in that version’s documentation.


203-215: Threading args.host into runServer is correct

Wiring host: args.host into runServer cleanly connects the new CLI option to the server binding logic, and the optional nature of the flag is preserved end to end.

Comment on lines 68 to 70
const serverUrl = `http://localhost:${options.port}`
const hostForUrl = options.host || 'localhost';

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Fix unused hostForUrl and align serverUrl with the selected host (including IPv6)

hostForUrl is currently unused, causing the ESLint error, and the usage URL still hardcodes localhost, ignoring options.host. You can both fix lint and make the Usage Viewer / Claude Code URLs reflect the actual bind host (with basic IPv6 handling) by updating this block:

-  const serverUrl = `http://localhost:${options.port}`
-  const hostForUrl = options.host || 'localhost';
+  const hostForUrl =
+    options.host &&
+    options.host.includes(":") &&
+    !options.host.startsWith("[")
+      ? `[${options.host}]`
+      : options.host || "localhost";
+  const serverUrl = `http://${hostForUrl}:${options.port}`;

This:

  • Removes the unused-variable error and fixes the Prettier single‑quote warning.
  • Makes the printed Usage Viewer URL and Claude Code env script consistent with a user‑supplied host.
  • Produces valid URLs for IPv6 literals (e.g., ::1http://[::1]:4141).
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const serverUrl = `http://localhost:${options.port}`
const hostForUrl = options.host || 'localhost';
const hostForUrl =
options.host &&
options.host.includes(":") &&
!options.host.startsWith("[")
? `[${options.host}]`
: options.host || "localhost";
const serverUrl = `http://${hostForUrl}:${options.port}`;
🧰 Tools
🪛 ESLint

[error] 69-69: 'hostForUrl' is assigned a value but never used. Allowed unused vars must match /^_/u.

(@typescript-eslint/no-unused-vars)


[error] 69-69: Replace 'localhost'; with "localhost"

(prettier/prettier)

🤖 Prompt for AI Agents
In src/start.ts around lines 68 to 70, replace the hardcoded `localhost` with
the `hostForUrl` value and eliminate the unused variable by building `serverUrl`
from `hostForUrl`; specifically, set hostForUrl = options.host || "localhost"
and then construct serverUrl = `http://<hostForUrl>:${options.port}` but ensure
IPv6 literals are wrapped in brackets when they contain a colon (e.g., if
hostForUrl.includes(':') and not already bracketed, use `[${hostForUrl}]`), and
use double quotes for string literals to satisfy Prettier.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant