Skip to content

biground/Send-to-Copilot-Chat

Repository files navigation

Send to Copilot Chat

English | 中文

A VS Code extension that sends your selected code to GitHub Copilot Chat as a native file attachment with a single keyboard shortcut.

Features

  • One key shortcut — Press Ctrl+L (Windows/Linux) or Cmd+L (Mac) to attach selected code directly to Copilot Chat.
  • Toggle focus — Press the same shortcut while Copilot Chat input is focused to return focus to the editor.
  • Native attachment chips — Uses VS Code's built-in attachFiles API so attachments appear as clickable label chips, fully understood by Copilot.
  • Multi-selection support — Hold Alt and select multiple ranges; each becomes a separate attachment chip.
  • Two modesSimple (chip only) or Full (chip + selected text pre-filled as a query).
  • Smart path resolution — Uses workspace-relative paths when available, falls back to absolute paths for files outside the workspace.

Requirements

Usage

  1. Open any file in the editor.
  2. Select the code you want to send (single or multiple selections).
  3. Press Ctrl+L / Cmd+L.
  4. Copilot Chat opens (or gains focus) with your file attachment chip ready — type your question and press Enter.
  5. Press Ctrl+L / Cmd+L again while in the chat input to return focus to the editor.

Keyboard Shortcuts

Platform Default Shortcut
Windows/Linux Ctrl+L
macOS Cmd+L

Tip: The keybinding only fires when the text editor has focus and text is selected, so it won't conflict with terminal or other panel shortcuts.

To customize the shortcut, open File → Preferences → Keyboard Shortcuts and search for Copilot: Send to Copilot Chat.

Recommended Keybindings

The extension registers keybindings in package.json, but other extensions (e.g. GitHub Copilot Chat itself) may override Cmd+L / Ctrl+L. If the shortcut doesn't work, add the following to your user keybindings.json (open via Command Palette → Preferences: Open Keyboard Shortcuts (JSON)):

// Send selected code to Copilot Chat
{
    "key": "cmd+l",          // Windows/Linux: "ctrl+l"
    "command": "sendToCopilot.send",
    "when": "editorTextFocus && editorHasSelection"
},
// Toggle: return focus to editor from chat input
{
    "key": "cmd+l",          // Windows/Linux: "ctrl+l"
    "command": "workbench.action.focusActiveEditorGroup",
    "when": "inChatInput"
}

Note: User-level keybindings have the highest priority and will override any conflicting bindings from extensions.

Extension Settings

Setting Type Default Description
sendToCopilot.mode string simple simple — attachment chip only.
full — chip + selected text as query.

Changing the mode

Open Settings (Ctrl+,) and search for sendToCopilot.mode, or add to settings.json:

"sendToCopilot.mode": "full"

Troubleshooting

Problem Solution
Nothing happens when pressing Ctrl+L Make sure the text editor has focus and text is selected.
Shortcut doesn't work / conflicts Add the recommended keybindings to your user keybindings.json.
"GitHub Copilot Chat is not installed" error Install the GitHub Copilot Chat extension.
Chat opens but no attachment chip appears Ensure your VS Code version is ≥ 1.85 and Copilot Chat is up to date.

Development

# Install dependencies
npm install

# Compile TypeScript
npm run compile

# Watch for changes
npm run watch

# Press F5 in VS Code to launch Extension Development Host

License

MIT

About

A VS Code extension that sends your selected code to **GitHub Copilot Chat** as a native file attachment with a single keyboard shortcut.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors