@@ -6,11 +6,12 @@ import { fileURLToPath } from "url"
66import { UI } from "@/cli/ui"
77import { errorMessage } from "@opencode-ai/tui/util/error"
88import { withTimeout } from "@/util/timeout"
9- import { withNetworkOptions , resolveNetworkOptionsNoConfig } from "@/cli/network"
9+ import { withNetworkOptions , resolveNetworkOptionsNoConfig , hasArg } from "@/cli/network"
1010import { Filesystem } from "@/util/filesystem"
1111import type { GlobalEvent } from "@opencode-ai/sdk/v2"
1212import type { EventSource } from "@opencode-ai/tui/context/sdk"
1313import { writeHeapSnapshot } from "v8"
14+ import { ServerAuth } from "@/server/auth"
1415import { validateSession } from "../tui/validate-session"
1516import { win32InstallCtrlCGuard } from "@opencode-ai/tui/terminal-win32"
1617
@@ -211,19 +212,16 @@ export const TuiThreadCommand = cmd({
211212 const config = await TuiConfig . get ( )
212213
213214 const network = resolveNetworkOptionsNoConfig ( args )
214- const external =
215- process . argv . includes ( "--port" ) ||
216- process . argv . includes ( "--hostname" ) ||
217- process . argv . includes ( "--mdns" ) ||
218- network . mdns ||
219- network . port !== 0 ||
220- network . hostname !== "127.0.0.1"
215+ const external = hasArg ( "--port" ) || hasArg ( "--hostname" ) || network . mdns === true
216+
217+ const headers = external ? ServerAuth . headers ( ) : undefined
221218
222219 const transport = external
223220 ? {
224221 url : ( await client . call ( "server" , network ) ) . url ,
225222 fetch : undefined ,
226223 events : undefined ,
224+ headers,
227225 }
228226 : {
229227 url : "http://opencode.internal" ,
@@ -237,6 +235,7 @@ export const TuiThreadCommand = cmd({
237235 sessionID : args . session ,
238236 directory : cwd ,
239237 fetch : transport . fetch ,
238+ headers,
240239 } )
241240 } catch ( error ) {
242241 UI . error ( errorMessage ( error ) )
@@ -264,6 +263,7 @@ export const TuiThreadCommand = cmd({
264263 pluginHost : createLegacyTuiPluginHost ( ) ,
265264 directory : cwd ,
266265 fetch : transport . fetch ,
266+ headers : transport . headers ,
267267 events : transport . events ,
268268 args : {
269269 continue : args . continue ,
0 commit comments