Skip to content

Conversation

@jhsu
Copy link

@jhsu jhsu commented Dec 24, 2025

Fixes #5844

When running opencode web --hostname 0.0.0.0 and accessing via a network IP,
the terminal WebSocket fails because the SDK URL defaults to http://localhost:4096.

Changed the fallback in packages/app/src/app.tsx from hardcoded localhost:4096
to window.location.origin, which correctly uses the hostname and port the user
accessed the page with.

This only affects the web production fallback case - desktop (Tauri), opencode.ai
console, and dev mode all hit earlier conditions and are unaffected.

Testing

run the app with:
cd packages/opencode && bun dev web --hostname 0.0.0.0 --port 4096

run opencode with:
VITE_OPENCODE_SERVER_HOST=0.0.0.0 VITE_OPENCODE_SERVER_PORT=4096 bun dev

then access the app from another network device at <hostname/ip>:3000 and it should work

alternatively

build first with
cd packages/app && bunx vite build

run opencode
cd packages/opencode && bun dev web --hostname 0.0.0.0 --port 4096 --app-dir ../app/dist

and access with <hostname/ip>:4096, works from accessing from another device.

Related issues

@jhsu jhsu marked this pull request as draft December 24, 2025 16:43
Simplify SDK URL resolution to use window.location.origin as fallback,
enabling opencode web to work with custom --hostname and --port options.

Env vars (VITE_OPENCODE_SERVER_HOST/PORT) are only used when explicitly
set, for dev mode where frontend and API run on different ports.
@jhsu jhsu force-pushed the fix-custom-hostname branch from 8c04d17 to dcd5bf5 Compare December 24, 2025 16:49
@jhsu jhsu marked this pull request as ready for review December 24, 2025 16:51
@jhsu jhsu marked this pull request as draft December 24, 2025 16:53
jhsu added 2 commits December 24, 2025 16:49
Allows testing local app builds with opencode web instead of proxying
from app.opencode.ai. Useful for development and testing changes to
the web app before deployment.
@jhsu jhsu marked this pull request as ready for review December 25, 2025 02:39
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.

Bug: Web terminal fails when accessing via network IP instead of localhost

1 participant