Uh oh!
There was an error while loading. Please reload this page.
feat: base path support - #7625
Conversation
Hey! Your PR title Please update it to start with one of:
Where See CONTRIBUTING.md for details. |
The following comment was made by an LLM, it may be inaccurate: No duplicate PRs found |
Thanks for your contribution! This PR doesn't have a linked issue. All PRs must reference an existing issue. Please:
See CONTRIBUTING.md for details. |
PhantomYdn
commented
Jan 11, 2026
Really looking for this PR to be merged! Thank you, @hsteude. Dear maintainers - please check/merge. |
PhantomYdn
commented
Jan 14, 2026
@hsteude I was playing around with your PR. Seems that additional fix is needed. When I run from a custom base path I see the following error: |
docs: improve comment explaining double mounting for reverse proxy support
77978fe to
e393b1fComparehsteude
commented
Jan 14, 2026
@PhantomYdn : Thanks for taking a look into this, good catch! I didn't realize because we tested with our own internal build where the basePath fix is baked in at build time. Added a commit that fixes the regex pattern. Also rebased on dev. Would you mind checking again if it works for you now? |
PhantomYdn
commented
Jan 15, 2026
@hsteude It partially helped, but not yet fully solve the issue. The fonts (may be other resources as well) are loaded through JavaScript and still assume hardcoded paths like |
- Install Bun for building OpenCode from source - Clone OpenCode from prokube/opencode fork with base-path PR (#7625) - Build OpenCode with 'bun install' and 'bun run build' - Add --base-path /sn_admin/oc flag to opencode web command - Update health check URL to use base path - Remove nginx rewrite since OpenCode handles base path internally This fixes OpenCode assets (JS/CSS) returning 404 when running behind nginx reverse proxy at /sn_admin/oc/ PR: anomalyco/opencode#7625 TODO: Switch back to npm install when PR is merged to mainline
Add support for running OpenCode behind a reverse proxy with a configurable base path prefix (e.g., /myapp/). - Adds --base-path CLI option, OPENCODE_BASE_PATH env var, and server.basePath config - Rewrites HTML/JS/CSS responses at runtime to include the base path - Wraps history.pushState/replaceState to prepend base path to URLs
PhantomYdn
commented
Jan 18, 2026
@hsteude I have solved this problem here: https://github.com/SkyNetCMS/opencode. There are few complexities, like availablility of frontend beyond reverse proxy with fixated opencode version (apparantly "opencode web" proxy all requests to app.opencode.ai and it's posslb to have case when opencode is older and not compatible with frontend) |
f802701 to
f1ae801CompareDaehoYang
commented
Feb 3, 2026
Is this going to be merged? |
nick-the-nuke
commented
Feb 5, 2026
This is a high need. Making the app more compatible with reverse-proxies can help make it more secure. |
nick-the-nuke
commented
Feb 5, 2026
nick-the-nuke
commented
Feb 5, 2026
AI slopping together a fix right now that takes some of the changes from the SkyNetCMS repo and applies it on top of this branch |
nick-the-nuke
commented
Feb 5, 2026
@PhantomYdn thank you for your fork. AI-sloppify added your changes in prokube#3 on @hsteude's branch. |
hsteude
commented
Feb 26, 2026
@nick-the-nuke, @DaehoYang, @PhantomYdn: Since I consider this PR a) somewhat hacky myself and b) don't expect it to be merged anytime soon (and I'd rather avoid rebase hell), I've spent some time, love, and a whole lot of tokens spinning up this project: https://github.com/prokube/pk-opencode-webui Feedback welcome! |
h0jeZvgoxFepBQ2C
commented
Mar 6, 2026
hm can this be merged? this is really blocking us from rolling out on our clusters |
PhantomYdn
commented
Mar 10, 2026
Just to be on the same page. I'm maintaining the following 2 features at https://github.com/SkyNetCMS/opencode:
Code being true-up to current active version of opencode roughly once per week. These fixes are needed for "aka lovable.dev" open source CMS: https://github.com/SkyNetCMS/SkyNetCMS |
@hsteude@PhantomYdn I was doing similar work and I might have found a much simpler way (just 7 lines of code) 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 |
multikoop
commented
Mar 20, 2026
This is a needed feature for broader adoption of opencode inside nowadays beeing created agentic plattforms. Would be appreciated to see this beeing merged. |
geosmart
commented
Mar 23, 2026
This is a needed feature for deploy on k8s |
without basic path , I use sub_filter to handle this apiVersion: "networking.k8s.io/v1"kind: "Ingress"metadata:
name: "opencode"annotations:
nginx.ingress.kubernetes.io/ssl-redirect: "false"nginx.ingress.kubernetes.io/configuration-snippet: | rewrite ^/opencode(/|$)(.*)$ /$2 break; proxy_set_header Accept-Encoding ""; sub_filter_once off; sub_filter_types text/html application/javascript text/javascript text/css; sub_filter ' href="/' ' href="/opencode/'; sub_filter ' src="/' ' src="/opencode/'; sub_filter ' content="/' ' content="/opencode/'; sub_filter ' srcset="/' ' srcset="/opencode/'; sub_filter ' manifest="/' ' manifest="/opencode/'; sub_filter 'url(/' 'url(/opencode/'; sub_filter 'url("/' 'url("/opencode/'; sub_filter 'url:"/' 'url:"/opencode/'; sub_filter '="/assets/' '="/opencode/assets/'; sub_filter '"assets/' '"/opencode/assets/'; sub_filter '/assets/' '/opencode/assets/';labels:
app.kubernetes.io/part-of: "agent"app.kubernetes.io/component: "skill"app.kubernetes.io/instance: "opencode"spec:
ingressClassName: "nginx"rules:
- http:
paths:
- backend:
service:
name: "opencode"port:
number: 5000path: "/opencode(/|$)(.*)"pathType: "ImplementationSpecific" |
hulto
commented
Mar 31, 2026
Thank you! Need this feature to deploy in coder w/o subdomains. |
Ark-kun
commented
Mar 31, 2026
carsongee
commented
Jun 30, 2026
Hi! I was really hoping we could get this in. Any updates here? I'm happy to contribute! |
PhantomYdn
commented
Jun 30, 2026
I have this built in in the following branch of opencode: https://github.com/SkyNetCMS/opencode |

Add support for running OpenCode behind a reverse proxy with a configurable base path prefix (e.g.,
/myapp/)Fixesthis issue.
Why
When deploying OpenCode with path-based routing, the application needs to serve assets and handle routing under a URL prefix. Without this, OpenCode can only run at the root path.
What it does
--base-pathCLI option,OPENCODE_BASE_PATHenv var, andserver.basePathconfighistory.pushState/replaceStateto prepend base path to URLsDesign decisions
Runtime rewriting: We rewrite content at runtime because the frontend is proxied from
app.opencode.aiand we don't control the build.Regex-based Vite patching: Vite bakes the base path into a function at build time (
function(t){return"/"+t}). Since we don't know the base path until runtime, we patch this via regex. It's not great, but the only alternative would require rebuilding the frontend for each deployment.Double mounting: The app is mounted at both
basePathAND/because some reverse proxies strip the path before forwarding. Without this, requests would 404.No CSP with basePath: We inject inline scripts for the history wrapper, which is incompatible with strict CSP.
Feedback and Ideas are welcome :)