Skip to content

[FEATURE]: Base path / prefix routing support #7624

Open

Description

@hsteude

Feature hasn't been suggested before.

  • I have verified this feature I'm about to request hasn't been suggested before.

Describe the enhancement you want to request

Use case

We'd like to integrate OpenCode as a feature into larger platforms, where it runs under a URL prefix (e.g., platform.com/opencode/) rather than at the root path.

Request

Add support for a configurable base path so OpenCode can be embedded into existing platforms and served alongside other applications under the same domain.

Activity

  1. added
    discussionUsed for feature requests, proposals, ideas, etc. Open discussion
    on Jan 10, 2026
  2. github-actions commented on Jan 10, 2026

    @github-actions
    Contributor

    This issue might be a duplicate of or related to existing issues. Please check:

    These issues touch on similar aspects of URL configuration and hosting OpenCode in larger platforms. Feel free to ignore if your specific use case isn't covered by these.

  3. LeonMueller-OneAndOnly commented on Feb 21, 2026

    @LeonMueller-OneAndOnly
    Contributor

    For the usage with tailscale this would also be a very nice feature, so one can expose multiple services from one machine over tailscale.

    I am referring to this feature of tailscale serve:
    --set-path= Appends the specified path to the base URL for accessing the underlying service.

    https://tailscale.com/docs/reference/tailscale-cli/serve

  4. Ark-kun commented on Mar 19, 2026

    @Ark-kun

    I was doing similar work and I might have found a simple way (just 7 lines of code) to get most of that via VITE_BASE_URL. Would you mind taking a look? #18209

    It does something a bit different - it bakes the prefix during the build. But this also makes it very easy to change at runtime or even via proxy. For example, you can set VITE_BASE_URL="XXX_OPENCODE_BASE_URL_XXX" and then even a transparent proxy can dynamically replace it on the fly as it serves compiled JS files.

  5. PhantomYdn commented on Mar 20, 2026

    @PhantomYdn

    This feature being raised in multiple issues. I have solved it there: https://github.com/SkyNetCMS/opencode

    This fork has 2 main features:

    1. Base Path Support - Run behind reverse proxy on a custom base path
    2. Embedded Assets - Self-hosted without external CDN

    This fork is needed for the SkyNetCMS: CMS where opencode is embedded into webpage. Like https://lovable.dev/ but fully opensource.

  6. solarkraft commented on Apr 23, 2026

    @solarkraft

    It would be great to have this integrated. Would make it much easier for me to host my self maintained fork.

  7. solarkraft commented on Apr 29, 2026

    @solarkraft

    Oh, it turns out that #21243 was actually merged (Github just shows it badly)! Nice one!

    Edit: I was wrong :(

  8. removed
    discussionUsed for feature requests, proposals, ideas, etc. Open discussion
    on May 3, 2026
  9. solarkraft commented on May 6, 2026

    @solarkraft

    I have tested #18209 and it works great, both in development and build. It's a tiny change and perfectly fulfills my use case - better than the dynamic version since I am hosting the front-end statically, independent of the API server.

  10. fabiovincenzi commented on May 19, 2026

    @fabiovincenzi

    I've opened #28326 which adds runtime --base-path support (CLI flag + config) without needing to rebuild the frontend. It covers server-side prefix stripping, HTML injection with CSP support, and relative asset paths via base: "./" in Vite.

  11. gitZhuo commented on Jul 17, 2026

    @gitZhuo

    We are affected by this in a real enterprise deployment.

    Our public gateway only permits applications under /web/*, so OpenCode
    must be exposed at:

    https://test.abc.com/web/oc/

    nginx strips /web/oc/ and proxies requests to:

    http://10.0.0.1:4096/

    However, opencode web generates origin-root URLs such as:

    • /assets/*
    • /event
    • /health
    • /config
    • /project
    • /global/event
    • /session/*
    • /pty/*

    These requests bypass /web/oc/ and are rejected by the gateway.
    Using nginx sub_filter is fragile because it requires rewriting minified
    JavaScript, API paths, SSE endpoints, WebSocket endpoints, dynamic imports,
    and frontend navigation routes.

    A first-class option such as the following would solve this:

    opencode web \
      --hostname 0.0.0.0 \
      --port 4096 \
      --base-path /web/oc
    
    Or configuration:
    
    {
      "server": {
        "basePath": "/web/oc"
      }
    }
    
    Expected behavior:
    
    1. Static assets use /web/oc/assets/*.
    2. HTTP APIs use /web/oc/*.
    3. SSE and WebSocket URLs include the prefix.
    4. Client-side navigation preserves the prefix.
    5. Direct navigation and refresh under /web/oc/... work.
    6. X-Forwarded-Prefix: /web/oc may optionally be honored.
    7. Root deployments remain backward compatible.
    
    A dedicated hostname or root-path deployment is not possible in our
    environment, so native base-path support is required.
  12. SmokinCaterpillar commented on Aug 23, 2026

    @SmokinCaterpillar

    I would really like to have this integrated, would make our work also easier!

  13. gitZhuo commented on Aug 23, 2026

    @gitZhuo
  14. icco commented on Sep 30, 2026

    @icco

    Would love for this to be merged.

  15. gitZhuo commented on Sep 30, 2026

    @gitZhuo
  16. opencodejr commented on Oct 29, 2026

    @opencodejr

    Thanks for the request, @hsteude!

    To restate it: you'd like a configurable base path, so the OpenCode server and web UI can be served under a URL prefix like platform.com/opencode/ behind a reverse proxy, alongside other apps on the same domain.

    As far as I can tell, OpenCode currently expects to be served from the root path, and a plugin can't change that, because the prefix would have to apply to the server's routes and to how the web app loads its assets. This would need to be added in OpenCode itself. Maintainers will consider it.

  17. gitZhuo commented on Oct 29, 2026

    @gitZhuo
  18. fabiovincenzi commented on Nov 4, 2026

    @fabiovincenzi

    I've ported #28326 to V2 in #61624. opencode serve --base-path /opencode serves the API and the web app under a path prefix, and the PR adds a docs section with an nginx example.

    It's a draft until #60559 (the client-side part) is merged.

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions