Skip to content

fix(app): auto-register server working directory as a project - #41138

Open
cshintov wants to merge 1 commit into
anomalyco:devfrom
cshintov:server-cwd-project
Open

cshintov wants to merge 1 commit into
anomalyco:devfrom
cshintov:server-cwd-project

Conversation

@cshintov

@cshintov cshintov commented Aug 7, 2026

Copy link
Copy Markdown

Issue for this PR

Closes #39655

Type of change

  • Bug fix

What does this PR do?

A fresh opencode web/serve started in a folder showed an empty UI — no
projects in the sidebar, "Nothing here yet" — even though the backend returns
projects and sessions. The web sidebar and session list are driven by the
app's local open-projects store (keyed on worktree), not the server /project
table, so until the user manually typed the folder path into the (empty)
picker, nothing appeared.

This registers the server's working directory as an open project on connect
(once sync.data.path.directory is known), skipping the user's home dir and
the filesystem root, which the file finder cannot index. The project then
appears in the sidebar with its sessions, without a manual "Add project" step.

How did you verify your code works?

  • Ran the app and backend dev servers locally (bun), started the server in a
    clean scratch folder, and loaded the UI in a fresh browser context (no
    persisted state): the launch folder appeared as a project with a new session.
  • bun typecheck in packages/app passes.

Screenshots / recordings

Before: empty sidebar, "Nothing here yet"; after: the server's working
directory (ocdemo) shown as a project with a session. (I can attach the PNG
to the issue if needed.)

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

On connecting to a server, open its working directory as a project so
that a fresh `opencode web`/`serve` started in a folder surfaces that
folder and its sessions in the UI, instead of an empty "Add project"
screen.

The web nav and session list are driven by the app's local open-projects
store (keyed on worktree), not the server `/project` table. Previously
nothing appeared until the user manually typed the folder path into the
picker — a common first-run confusion that recurs across anomalyco#39655, anomalyco#39040,
anomalyco#27837 and others.

Skip the user's home directory and the filesystem root, which the file
finder cannot index and would otherwise render as empty projects.

Fixes anomalyco#39655
@github-actions github-actions Bot added the needs:compliance This means the issue will auto-close after 2 hours. label Aug 7, 2026
@github-actions

github-actions Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

Potential Duplicate Found

PR #38992: fix(app): adopt the server directory when no project is open
#38992

Why it's related: This PR addresses the same problem — handling the server's working directory when no project is currently open. Both PRs appear to be tackling the empty sidebar issue in fresh opencode web sessions and the need to automatically register the server's working directory as a project. You should check if #38992 is already merged or if this PR supersedes it with a different implementation approach.

@github-actions github-actions Bot removed the needs:compliance This means the issue will auto-close after 2 hours. label Aug 7, 2026
@github-actions

github-actions Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

@ZipiDan

ZipiDan commented Sep 1, 2026

Copy link
Copy Markdown

Thanks for this fix — it solves the empty web UI and is needed, but it only fixes the frontend.

Please also consider reopening the two closed PRs that fix the deeper server issue:

  • fix(opencode): add --dir option to web/serve; use directory as worktree #35976 fix: add --dir option to web/serve; use directory as worktree (closed by automated-pr-cleanup 9 Aug) — makes web/serve respect the directory where you ran the command, just like TUI already does with opencode [project] / CWD. Without it the server starts with worktree:/ instead of the actual project (e.g. /workspace with podman run --workdir /workspace -v $PROJECT:/workspace:Z), so GET /project returns only global, skills in .opencode/skills/ are not found, and new sessions get cwd=/.
  • fix(app): adopt the server directory when no project is open #38992 fix: adopt the server directory when no project is open (closed 26 Aug, predecessor of this PR) — same localStorage seeding as this PR.

The text interface already follows this policy — opencode (TUI) correctly uses the current directory/project — and it would be consistent for the web interface to follow the same policy.

Container repro:

  • podman --workdir /workspace + opencode web --hostname 0.0.0.0 --port 4070 -> TUI starts in /workspace (correct), web shows empty ("No projects") and picker at / -> must manually add /workspace. http://localhost:4070 vs http://127.0.0.1:4070 are different browser storages, so it repeats. Log shows creating instance directory=/workspace but GET /project=[{"id":"global","worktree":"/"}].

This PR #41138 makes the browser show the server's folder without manual steps (great), but the server is still on / without #35976. For a full fix we need both: server (#35976) + app (#41138). Could you reopen #35976 and #38992? Happy to test together. Thanks!

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] OpenCode Web shows "No folders found" although projects are returned by the backend API

2 participants