Skip to content

x repo code replaces the active VS Code window and shows a dialog #3

Description

@lunrenyi

Problem Description

The x repo code <id> command currently uses the vscode://file/... URI scheme to open VS Code, which causes the following issues:

  1. Replaces the active VS Code window: Instead of opening the project in a new window, it replaces the content of the currently active VS Code window.
  2. Shows a confirmation dialog: The URI scheme trigger pops up a confirmation dialog.
  3. Interrupts running tasks: Long-running tasks such as claude-code running in the VS Code integrated terminal may be interrupted unexpectedly.
Image

Related Code

Call Chain

x repo code <id>
  → ___x_cmd_repo_code()          # mod/repo/lib/main:114-126
    → ___x_cmd code "$x_"         # line 125
      → ___x_cmd_code___main()    # mod/code/lib/main:5-15
        → ___x_cmd_code___open()  # mod/code/lib/main:17-23
          → x open "vscode://file/$x_"  # line 22

Core Problem Code

___x_cmd_code___open(){
    local x_
    ___x_cmd_abspath_ "$1"
    [ -n "$x_" ] || return
    code:info "x open vscode://file/$x_"
    x open "vscode://file/$x_"      # ← The problem
}

The current implementation uses the vscode://file/... URI scheme protocol to open VS Code. On macOS, x open eventually invokes the system's open command, which hands the URI off to VS Code. VS Code's default behavior is to replace the content of the current window with the given path and may pop up a confirmation dialog.

Proposed Solution

In ___x_cmd_repo_code, replace ___x_cmd code "$x_" with ___x_cmd_cmds code "$x_" so VS Code is opened via the code CLI binary directly, bypassing the vscode:// URI handler. The code CLI opens a new VS Code window for the given path, which avoids window replacement, the confirmation dialog, and interruption of long-running terminal tasks (e.g. claude-code).

Modified Code

mod/repo/lib/main:114-126:

___x_cmd_repo_code(){
    case "${1-}" in
        -h|--help)  ___x_cmd help -m repo code "$@" ; return 0 ;;
    esac

    local id="$1"
    local x_
    ___x_cmd_repo_resolve_ "$id"

    [ -d "$x_" ] || ___x_cmd_repo_update "$id"

    ___x_cmd_cmds code "$x_"        # ← was: ___x_cmd code "$x_"
}

Why this works

  • ___x_cmd_cmds code "$x_" resolves and invokes the code CLI binary directly (PATH lookup). The CLI tells VS Code to open a new window rooted at $x_, instead of having the OS dispatch the URI and replace the active window.
  • This is the same code path already used by ___x_cmd_code___bin() (mod/code/lib/main:25-29), which prefers ___x_cmd_cmds code "$@" whenever the code binary is on PATH. By calling it directly we skip the URI dispatch entirely.
  • No new confirmation dialog, no window takeover, and no interference with long-running terminal tasks like claude-code.

Scope note

The user-facing entrypoint x code <path> still goes through ___x_cmd_code___main → ___x_cmd_code___open and uses the URI scheme. Aligning x code <path> with the same CLI-based behavior is a separate change (e.g. having ___x_cmd_code___main prefer ___x_cmd_code___bin when the CLI is available). The single-line change above is the minimal, targeted fix for x repo code <id>.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    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