Skip to content

Add keybinding action to insert @file#line reference from IDE selection in CLI #26993

Description

@Mr-Beek

Description

When running Claude Code CLI in a VS Code integrated terminal, the IDE selection context is passed automatically as a system reminder (e.g., "The user selected lines 76 to 82 from ..."). However, there's no way to explicitly insert multiple @file#L-L reference into the prompt text via a keyboard shortcut.

The VS Code extension supports Option+K to insert selection references, but users who prefer the CLI (for access to full slash commands, etc.) don't have an equivalent.

Proposed Solution

Add a new keybinding action (e.g., chat:insertSelection or chat:insertFileReference) that:

  1. Reads the current IDE selection context (file path + line range)
  2. Inserts an @path/to/file#L76-82 reference into the prompt input at the cursor position

This would allow users to configure it in ~/.claude/keybindings.json:

{
  "bindings": [
    {
      "context": "Chat",
      "bindings": {
        "option+k": "chat:insertSelection"
      }
    }
  ]
}

Motivation

The CLI has features not available in the VS Code extension panel. Users who prefer the CLI for its full feature set currently lose the convenience of explicitly referencing selected code via a shortcut. This bridges that gap.

Alternatives Considered

  • Using the VS Code extension instead: Loses access to CLI-only features
  • Manually typing @file#L-L references: Works but is slow and error-prone

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