opcode icon indicating copy to clipboard operation
opcode copied to clipboard

Bug: Project path incorrectly reconstructed when username contains underscores — causes "Failed to send prompt"

Open mikesmichal opened this issue 6 months ago • 3 comments

Bug Description

When a system username contains an underscore (e.g. michal_mikes), opcode reconstructs project paths incorrectly, causing "Failed to send prompt" on every prompt submission in the Projects view.

Root Cause

Claude CLI encodes project paths into directory names under ~/.claude/projects/ by replacing both / and _ with -. For example:

/home/michal_mikes/projects  →  -home-michal-mikes-projects

When opcode reads this directory name and reconstructs the original path, it only performs the reverse of / → -, yielding:

-home-michal-mikes-projects  →  /home/michal/mikes/projects   ❌

The underscore in the username is lost, producing a path that does not exist on disk. Claude CLI then fails to start because the working directory is invalid, and opcode surfaces this as "Failed to send prompt".

The correct path should be /home/michal_mikes/projects ✅

Steps to Reproduce

  1. Use a Linux/macOS system where the username contains an underscore (e.g. john_doe)
  2. Open opcode and navigate to the Projects tab
  3. Select any project
  4. Type any prompt and press Enter

Result: "Failed to send prompt" error immediately.

Workaround

Manually fix the corrupted projectPath values in opcode's localStorage SQLite database:

~/.local/share/opcode.asterisk.so/localstorage/tauri_localhost_0.localstorage

Values are UTF-16LE encoded JSON. Replace occurrences of /home/john/doe/ with /home/john_doe/ in the projectPath fields.

Expected Behavior

The path reconstruction from the Claude project directory name should either:

  • Read the cwd field directly from the session .jsonl files inside the project directory (which contain the correct original path), or
  • Use a reversible encoding that distinguishes / from _ (e.g. encode only / as - and leave _ as-is, or use a different separator)

Environment

  • OS: Ubuntu 22.04 LTS
  • opcode version: 0.2.0
  • Claude Code version: 2.1.139
  • Username: contains underscore

Related Issues

  • #456 (same symptom, root cause not identified)
  • #444 (similar class of bug: special characters in project paths)

mikesmichal avatar May 12 '26 12:05 mikesmichal

Follow-up investigation — bug is broader than the username case

After further testing I found the root cause affects any project whose path contains a dash, not just usernames with underscores. The problem is that opcode converts every - in the Claude project directory name back to /, while Claude CLI originally encoded both / path separators and - dashes in directory names as -.

Full encoding ambiguity

Claude CLI creates project directory names by replacing / with - (and also _ with -).
Example:

/home/michal_mikes/projects/teamio-acnas  →  -home-michal-mikes-projects-teamio-acnas

Opcode reverses this naively (- → /), producing:

-home-michal-mikes-projects-teamio-acnas  →  /home/michal/mikes/projects/teamio/acnas  ❌

Correct path: /home/michal_mikes/projects/teamio-acnas ✅

On a system with 22 Claude projects, all 22 had wrong paths after reconstruction. Every project with a dash in its name is broken (teamio-acnas, alma-career-api-docs, advertplatform-advert-model, …).

Why the localStorage workaround doesn't hold

Opcode rebuilds project paths from directory names every time it starts (the list_projects command runs on startup). Any manual fix to the localStorage SQLite DB is overwritten within seconds.

The session files already have the answer

Each project directory under ~/.claude/projects/<encoded-name>/ contains .jsonl session files. Every session line that has a cwd field contains the original, correct path. The code already has a path for this — the log message "Failed to get project path from sessions for , falling back to decode" confirms it tries session files first. However, newer Claude session files begin with last-prompt or permission-mode entries (no cwd), so the lookup fails and the broken decode is used as fallback.

Fix suggestion: when reading a session file to extract cwd, scan beyond the first line until a line with a non-empty cwd is found (or scan all lines in the file), rather than giving up after the first line.

Minimal reproducible case (no special username needed)

  1. Use any project whose directory name contains a dash, e.g. /home/user/my-project
  2. Claude encodes it as -home-user-my-project
  3. Opcode decodes it as /home/user/my/project — path does not exist → "Failed to send prompt"

This means the bug affects a large share of Linux/macOS users, not just those with underscores in their username.

mikesmichal avatar May 12 '26 12:05 mikesmichal

Yes same here, new install of opcode on Mac OS and the Recents show all my projects replacing - with / and it takes the last word after the hyphen/slash as the project name so not very good.

amityweb avatar Jun 25 '26 15:06 amityweb

Another data point for this: the decode fallback also breaks on hidden (dot-prefixed) directories, not just _ and -.

Claude Code encodes both / and . as - in project folder names, so /Users/me/.projects/myproject is stored as -Users-me--projects-myproject. The naive - → / decode gives /Users/me//projects/myproject, which doesn't exist. The resume then fails with "Failed to send prompt".

Debug log (RUST_LOG=debug):

WARN  Failed to get project path from sessions for -Users-me--projects-myproject: Could not determine project path from session files, falling back to decode
INFO  Resuming Claude Code session: <session-id> in: /Users/me//projects/myproject with model: sonnet

One difference from the report above: in my case every session file in that project has a top-level cwd within its first 8 lines, so the lookup still falls back even though a valid cwd is near the top of every file. I haven't found why. I built from the opcode.sh package, so my code may predate the current repo.

Workaround for dot-prefixed folders (macOS/Linux): ln -s ~/.projects ~/projects. With that link in place, resuming worked. It doesn't help hyphenated names.

Opcode built from source, Claude Code 2.1.308, macOS.

i5dr0id avatar Oct 26 '26 12:10 i5dr0id