Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ The following command line options are available for the `start` command:
| Option | Description | Default | Alias |
| -------------- | ----------------------------------------------------------------------------- | ---------- | ----- |
| --port | Port to listen on | 4141 | -p |
| --host | Host/interface to listen on (e.g., 127.0.0.1 for IPv4, ::1 for IPv6) | all (::) | -h |
| --verbose | Enable verbose logging | false | -v |
| --account-type | Account type to use (individual, business, enterprise) | individual | -a |
| --manual | Enable manual request approval | false | none |
Expand All @@ -164,6 +165,24 @@ The following command line options are available for the `start` command:
| --show-token | Show GitHub and Copilot tokens on fetch and refresh | false | none |
| --proxy-env | Initialize proxy from environment variables | false | none |


#### Usage examples with --host

Listen on IPv4 localhost only:
```sh
npx copilot-api@latest start --account-type business --host 127.0.0.1
```

Listen on IPv6 localhost only:
```sh
npx copilot-api@latest start --account-type business --host ::1
```

Default (listen on all interfaces):
```sh
npx copilot-api@latest start --account-type business
```

### Auth Command Options

| Option | Description | Default | Alias |
Expand Down
10 changes: 10 additions & 0 deletions src/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { server } from "./server"

interface RunServerOptions {
port: number
host?: string
verbose: boolean
accountType: string
manual: boolean
Expand Down Expand Up @@ -65,6 +66,7 @@ export async function runServer(options: RunServerOptions): Promise<void> {
)

const serverUrl = `http://localhost:${options.port}`
const hostForUrl = options.host || 'localhost';

Comment on lines 68 to 70
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.

if (options.claudeCode) {
invariant(state.models, "Models should be loaded by now")
Expand Down Expand Up @@ -117,6 +119,7 @@ export async function runServer(options: RunServerOptions): Promise<void> {
serve({
fetch: server.fetch as ServerHandler,
port: options.port,
hostname: options.host || undefined, // undefined falls back to system default (all interfaces)
})
}

Expand All @@ -138,6 +141,12 @@ export const start = defineCommand({
default: false,
description: "Enable verbose logging",
},
host: {
alias: "h",
type: "string",
description:
"Host/interface to listen on (e.g., 127.0.0.1 for IPv4 localhost, ::1 for IPv6 localhost)",
},
"account-type": {
alias: "a",
type: "string",
Expand Down Expand Up @@ -193,6 +202,7 @@ export const start = defineCommand({

return runServer({
port: Number.parseInt(args.port, 10),
host: args.host,
verbose: args.verbose,
accountType: args["account-type"],
manual: args.manual,
Expand Down