Skip to content

Recent projects shows "/" when started in non-git directory #15719

Closed as not planned

Description

@imryao

Describe the bug

When opencode is started in a directory that does not contain a git repository, the recent projects list displays / as the project path instead of the actual working directory.

Steps to reproduce

  1. Start opencode in a directory without a .git folder (e.g. mkdir /tmp/test && cd /tmp/test && opencode)
  2. Open the home page / recent projects view
  3. The project path shows / instead of /tmp/test

Root cause

In packages/opencode/src/project/project.ts, Project.fromDirectory() walks up the directory tree looking for .git. When none is found, it falls back to hardcoded "/":

return {
  id: "global",
  worktree: "/",    // should be `directory`
  sandbox: "/",     // should be `directory`
  vcs: Info.shape.vcs.parse(Flag.OPENCODE_FAKE_VCS),
}

The directory argument passed into fromDirectory is available but not used in this fallback path.

Expected behavior

Recent projects should display the actual working directory (e.g. ~/projects or /tmp/test), not /.

Environment

  • opencode version: v1.2.15+
  • OS: Linux (also reproducible on macOS)
  • Affects any non-git directory

Activity

  1. added
    coreAnything pertaining to core functionality of the application (opencode server stuff)
    on Mar 2, 2026
  2. github-actions commented on Mar 2, 2026

    @github-actions
    Contributor

    This issue might be a duplicate of (or closely related to) existing issues that share the same root cause in Project.fromDirectory() returning worktree: "/" for non-git directories. Please check:

  3. disarticulate commented on Mar 21, 2026

    @disarticulate

    Further, there's zero documentation as to where it starts; trying to run this in a Docker container without root permissions basically makes it useless as the only thing that pops up is '/':

    Image
    # OpenCode Docker Image for server
    FROM node:24-slim
    
    # Set environment variables
    ENV DEBIAN_FRONTEND=noninteractive \
        OPENCODE_SERVER_PORT=42005 \
        OPENCODE_SERVER_HOSTNAME=0.0.0.0 \
        OPENCODE_CONFIG_DIR=/opt/opencode/config \
        PATH="/root/.opencode/bin:/root/.cargo/bin:/root/.local/bin:${PATH}"
    
    # Install system dependencies
    RUN apt-get update && apt-get install -y \
        curl \
        gnupg \
        ca-certificates \
        apt-transport-https \
        lsb-release \
        vim \
        wget \
        build-essential \
        libreoffice \
        libreoffice-gtk3 \
        poppler-utils \
        docker.io \
        openssh-server \
        && rm -rf /var/lib/apt/lists/*
    
    # Add Node.js repository
    RUN mkdir -p /etc/apt/keyrings && \
        curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg && \
        echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_20.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list
    
    # Install nvm (Node Version Manager) and Node.js 24 with yarn
    RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash
    
    # Source nvm and install Node.js 24 + yarn
    RUN . ~/.nvm/nvm.sh && \
        nvm install 24 && \
        nvm use 24 && \
        npm install -g yarn
    
    # Set up environment for nvm in container
    ENV PATH="/root/.nvm/versions/node/v24*/bin:${PATH}:${PATH}"
    
    # Get the GID of the host's docker group and create a matching group in container
    RUN getent group docker || groupadd -g 1001 docker
    
    # Install OpenSSH server again after docker.io (to avoid conflicts)
    RUN apt-get update && \
        apt-get install -y openssh-server && \
        rm -rf /var/lib/apt/lists/*
    
    # Create SSH directory for root user and set permissions
    RUN mkdir -p /root/.ssh && \
        chmod 700 /root/.ssh && \
        chown root:root /root/.ssh
    
    # Set default password for root user (for SSH access)
    RUN echo "root:adO1Zh7CAjUhh1" | chpasswd
    
    # Configure SSH daemon to run on port 42004
    RUN sed -i 's/#Port 22/Port 42004/' /etc/ssh/sshd_config && \
        sed -i 's/#PasswordAuthentication yes/PasswordAuthentication yes/' /etc/ssh/sshd_config && \
        sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin no/' /etc/ssh/sshd_config && \
        echo "UsePAM yes" >> /etc/ssh/sshd_config
    
    # Expose SSH port
    EXPOSE 42004
    
    # Install Rust toolchain
    RUN curl -sSf https://sh.rustup.rs --output rustup-init && \
        sh rustup-init -y && \
        rm rustup-init && \
        . /root/.cargo/env && \
        rustup component add rustfmt clippy
    
    # Install OpenCode from official source
    RUN curl -fsSL https://opencode.ai/install | bash
    
    # Create config directory for OpenCode configuration files
    RUN mkdir -p ${OPENCODE_CONFIG_DIR}
    
    # Create a working directory
    WORKDIR /workspace
    
    # Expose the OpenCode port
    EXPOSE 42005
    
    # Set up volume for config files
    VOLUME ${OPENCODE_CONFIG_DIR}
    
    # Set up volume for workspace
    VOLUME /workspace
    
    RUN apt-get update \
        && apt-get install -y \
            nano \
        && rm -rf /var/lib/apt/lists/*
    
    USER node
    
    # Default command - start the opencode server
    ENTRYPOINT ["opencode", "serve", "--hostname", "0.0.0.0", "--port", "42005"]
    

    One would think it should serve /workspace as the working directory; or at least /home/node since it was started by the user node; it doesn't appear to have permissions or anything and lives in root.

  4. gitrequests commented on Mar 22, 2026

    @gitrequests

    Related issue: #14656

  5. sergio-asenjo commented on Mar 24, 2026

    @sergio-asenjo

    I'm having a similar issue but with an extra step.

    If I start a chat in a directory without a git repo being initialized, it effectively shows all global sessions, but if after just doing opencode within that directory, no starting chats required, and I then start a git repo, it stays within that global context, there's no opt-in (or at least I couldn't find a way to do so in the docs) so this newly started git repo can have its own sessions.

  6. assigned and unassigned on Apr 26, 2026
  7. removed
    coreAnything pertaining to core functionality of the application (opencode server stuff)
    on May 3, 2026
  8. github-actions commented on Jul 3, 2026

    @github-actions
    Contributor

    To stay organized issues are automatically closed after 60 days of no activity. If the issue is still relevant please open a new one.

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