Skip to content

About

JetBrains IDE plugin to copy file paths, line numbers, and selected code in AI-ready formats for Claude, ChatGPT, and other coding assistants.

Topics

Resources

Contributing

Stars

3 stars

Watchers

0 watching

Forks

Repository files navigation

Copy Selection Context

JetBrains Marketplace Release Downloads Contributors License

English · 한국어 · 简体中文 · 繁體中文 · 日本語

Copy file path + line numbers + code to clipboard in one shortcut — formatted for AI assistants.

Tired of manually typing file paths and line numbers when sharing code context with AI coding assistants like Claude or ChatGPT? Copy Selection Context copies @path#Lline formatted context to your clipboard with a single shortcut.

Get from JetBrains Marketplace

Features

  • One-shortcut copy — Ctrl+Alt+Shift+Z copies file path + line numbers instantly
  • Relative or absolute paths — Choose between project-relative or absolute paths
  • Flexible output formats — Use Claude Code references, Path:Line output, or a custom template
  • Code content included — Optionally include selected code as a markdown code block
  • Copy history — Browse recent copy history from the Copy Selection Context Tools submenu
  • Session context collection — Add selections from several files, open the collection to review and organize frozen captures, then copy the complete output
  • GitHub/GitLab permalink — Copy a Git permalink with the same local history and copy feedback as standard results
  • Copy feedback — Mark the copied lines, show an optional notification, and retain the last copy in the status bar
  • Respectful review path — After demonstrated use, offer one honest-review prompt per version plus a passive Marketplace link
  • Multi-caret context — Format every caret independently and separate its path/code block with a blank line
  • Accurate selection ends — Treat IntelliJ's selectionEnd - 1 as the final included offset, avoiding an extra trailing line
  • Localized IDE UI — Use translated actions, settings, notifications, history, status, and formatting labels in English, Korean, Japanese, Simplified Chinese, and Traditional Chinese
  • Smart line handling — Copies current line number when no text is selected
  • Context menu — Run the main copy directly from the editor right-click menu; other actions live in the Copy Selection Context Tools submenu
  • Cross-platform — Works on Windows, macOS, and Linux

Installation

From JetBrains Marketplace

  1. File → Settings → Plugins
  2. Search for "Copy Selection Context"
  3. Click Install

From Disk

  1. Download the latest .zip from the Releases page
  2. File → Settings → Plugins → ⚙️ → Install Plugin from Disk...
  3. Select the downloaded .zip → Restart IDE

Verifying Release Downloads

The plugin ZIP attached by .github/workflows/release.yml is the canonical release artifact. When signing credentials are configured, this is the signature-verified -signed.zip file also sent unchanged to JetBrains Marketplace. Without signing credentials, the workflow explicitly marks the canonical ZIP as unsigned and skips Marketplace publication. Local builds can be functionally identical without having the same bytes across environments because the IntelliJ Platform Gradle Plugin records the build JVM and operating system in META-INF/MANIFEST.MF. Each GitHub Release therefore includes SHA256SUMS and a GitHub artifact attestation for the exact published ZIP.

Each GitHub vX.Y.Z release records that released plugin version. GitHub release availability does not by itself indicate JetBrains Marketplace approval or public listing; those statuses are separate.

Download both assets and verify the checksum on Linux:

gh release download v1.2.0 \
  --repo hon454/copy-selection-context \
  --pattern '*.zip' \
  --pattern SHA256SUMS
sha256sum --check SHA256SUMS

On macOS, use the standard shasum command instead:

shasum -a 256 --check SHA256SUMS

Then verify that GitHub attested the same ZIP from this repository's canonical release workflow and tag. Use the exact downloaded filename; signed releases have the -signed.zip suffix shown below, while explicitly unsigned releases do not (replace the version when needed):

gh attestation verify copy-selection-context-1.2.0-signed.zip \
  --repo hon454/copy-selection-context \
  --signer-workflow hon454/copy-selection-context/.github/workflows/release.yml \
  --source-ref refs/tags/v1.2.0

Usage

Keyboard Shortcuts

Action Windows/Linux macOS
Copy Selection Context Ctrl+Alt+Shift+Z Cmd+Alt+Shift+Z

Only the main copy has a default shortcut. Assign shortcuts to any other action in Settings → Keymap, or click Configure shortcuts in Keymap… in the plugin settings.

Context Menu

Right-click in the editor → Copy Selection Context copies immediately using your settings. The Copy Selection Context Tools submenu holds the other actions:

Action Description
Copy Relative Path with Line Numbers Copy with project-relative path
Copy Absolute Path with Line Numbers Copy with absolute path
Copy with Code Content Copy path + lines + code block
Copy GitHub/GitLab Permalink Copy Git remote permalink
Show Copy History Show recent copy history popup
Add to Context Collection Capture a selection or current line for the project session
Open Context Collection Open, review and organize the project session collection
Copy All Context Collection Copy the collection without an active editor

Output Format

The main action and explicit path/code actions use the output format selected in settings. Paths are normalized to forward slashes.

Every caret produces its own 1-based inclusive range and optional code block, with blocks separated by a blank line. Since IntelliJ selection ends are exclusive, selectionEnd - 1 determines the final included line; a selection ending at the next line's start does not include that line.

Claude Code (claude, default):

  • Single line: @src/main/kotlin/App.kt#L42
  • Multiple lines: @src/main/kotlin/App.kt#L250-253

Path:Line (pathline):

  • Single line: src/main/kotlin/App.kt:42
  • Multiple lines: src/main/kotlin/App.kt:250-253

Custom template (template):

  • Start from the Path and Range, Claude Reference, or With Code Block preset, or enter your own template
  • Available variables populated by standard copy actions: {path}, {line}, {range}, {code}, {lang}, and {filename}
  • The settings screen previews the result and flags unknown variables

With code content (Claude Code and Path:Line append a fenced block; custom templates place it with {code}):

 @src/main/kotlin/App.kt#L42-53
```kotlin
fun calculateTotal(items: List<Item>): Double {
    return items.sumOf { it.price }
}
```

The separate Copy GitHub/GitLab Permalink action uses system Git on a background thread to verify the original HEAD file in a normal repository or linked worktree. Only permalinks require Git. It needs Git features available in upstream Git 2.45 or newer, especially --no-lazy-fetch and check-attr --source; the actual executable must support the required options. If Git is missing, cannot run, or rejects a required option, this action reports a distinct localized error. For unsupported Git, upgrade it and confirm the IDE uses the upgraded executable. Standard, collection, history and status-bar copies continue to work. The plugin does not install Git or change PATH or Git settings.

A path absent from HEAD, including a new file or a renamed destination, cannot be copied as a permalink. If the current editor document matches HEAD, copying needs no extra confirmation. If it differs, including unsaved, saved or staged edits, one confirmation explains that HEAD may contain different code at the current line numbers. Cancel is the default. Choosing Copy Permalink uses the captured HEAD SHA and current caret ranges, with no automatic line mapping. Changes detected during verification or confirmation invalidate that request.

Only the latest managed copy request across projects can publish. Git queries read local objects with replacement refs and implicit fetching disabled; unsupported, missing, binary or undecodable objects fail safely. The plugin never saves, commits, stashes, fetches or pushes automatically. A permalink does not guarantee that its commit has been pushed or that the remote is accessible.

History, Notifications, and Status

  • Successful standard path/code and Git permalink copies prepend entries to project-specific history. Show Copy History opens the stored entries, and choosing one copies its full content again.
  • Copy notifications are enabled by default and can be disabled. They are shown after standard path/code copies and Git permalink copies.
  • Only standard copies and Copy All Context Collection made while notifications are enabled in a supported UI context advance the review counter; disabled, test, headless, and unsupported contexts leave both counter and prompt state unchanged. The tenth eligible copy in one IDE session may show one non-modal honest-review request for that plugin version. Review on Marketplace opens the official Marketplace review page, Later skips the rest of the current version, and Don't ask again permanently suppresses prompts. Opening the review page once, from the prompt or the settings link, also stops future prompts. When notifications are disabled, only the passive settings link is available.
  • The exact session count is never persisted. Only lastPromptedVersion, permanent suppression choices, and whether the Marketplace page was opened are kept in local, non-roaming copySelectionReview.xml; no copied content, file data, analytics, review outcome, telemetry, or automatic network request is involved.
  • A successful standard or Git permalink copy replaces the gutter markers in the active editor and updates the status-bar widget with a single-line, Unicode-safe, markup-escaped preview capped at 40 characters including its prefix. Click the widget to copy the full latest successful plugin value again. Permalinks never increment local analytics or review-prompt accounting.
  • Optional local usage analytics count successful standard copies and Copy All Context Collection by output format and detected file language (a collection with several languages counts as Mixed languages). Settings shows an immutable snapshot of every counter and provides a confirmed reset. Analytics are disabled by default, stored only in local IDE application settings, and never transmitted.

Settings

Settings → Tools → Copy Selection Context:

  • Path type — Absolute (default) or Relative
  • Output format — Claude Code (default), Path:Line, or Custom Template
  • Custom format template — Choose a preset or edit a six-row multiline template with a focusable six-row live preview, accessible labels, and variable validation
  • Include code content — Include selected code, or the current line when nothing is selected (off by default)
  • Trim whitespace from code — Remove leading and trailing whitespace from included code (off by default)
  • Show copy notification — Show a balloon after supported copy actions (on by default)
  • Review on Marketplace — Open the official review page manually without forcing a prompt
  • Configure shortcuts in Keymap… — Open Keymap filtered to this plugin's actions to assign your own shortcuts
  • Copy history size — Keep 0–100 entries per project (default: 10); set 0 to disable and clear history
  • Local usage analytics — Inspect and reset opt-in total, output-format, and language counters stored only on this machine (off by default; never transmitted)

Copy history may contain copied code. It is stored only in the IDE's local, non-roaming workspace data and is not written to shareable project settings. Each stored entry is limited to 256 KiB of UTF-8 content, and total history per project is limited to 2 MiB. Results over 256 KiB are still copied in full but are not added to history. When either the configured entry count or total byte budget is exceeded, the oldest entries are removed immediately. Use Clear all history at the bottom of the history popup to remove every entry. Existing history, including data migrated from copySelectionHistory.xml, is normalized to the same limits when loaded; the legacy file is then cleaned up by the IDE.

Settings Screen

Copy Selection Context settings screen

Configure path type, output and templates, code handling, notifications, review access, history, and local analytics from one place.

Session context collection (available since 1.5.0)

Use Add to Context Collection in the editor's Copy Selection Context Tools submenu or Find Action to collect selections from several files. Every caret captures its selection or current line, including unsaved text, without changing the clipboard or moving editor focus. The action has no default shortcut and can be assigned in Keymap.

Captures freeze the original code, path, filename, language, range, capture number and time. Unchanged recaptures are skipped; changed code creates a separate snapshot. Switching relative/absolute path preferences alone remains a duplicate and preserves the original display path. Rename/delete status is tracked separately from captured content.

The project session retains at most 100 items, 256 KiB of raw UTF-8 code per item and 2 MiB in total. An oversized multi-caret batch is rejected in full; nothing is truncated or evicted. Collection data and its independent, initially enabled code-inclusion option are never persisted. Project close/plugin unload discards them. Collection capture does not modify existing copy history, status, review counters or analytics; OS and external clipboard history have their own policies.

After adding, use Open Context Collection from the submenu or Find Action to open the right tool window even without an editor. Adding keeps editor focus and does not open the window automatically. The open action has no default shortcut; assign it in Keymap if desired. The existing one-shot shortcut remains separate.

Review the ordered captures by their fixed number, capture time, path and range. Arrow keys select; Move Up/Down preserves the selected capture; Delete removes only when the list has focus. Clear All defaults to Cancel and requires a fresh confirmation if the collection changes. Both read-only viewers support focus, selection and normal text copying. Go to Source (or Enter, or a row double-click) opens the current file at the captured starting line; its code may have changed.

Toggle Include code independently of one-shot settings. Format Settings… opens the existing formatter settings. The raw-code and final-output UTF-8 byte counts are separate. Calculating clears stale output; blank item output and output above 4 MiB block Copy All. Warning reasons are shown before the shared confirmation.

Capture-time code stays available after source changes or deletion; source labels describe observed changes, not proof of equality. Copying and hiding the window retain the collection. Project/plugin close discards it. Collections never enter persistent copy history; OS and external clipboard history are separate.

When the captures are ready, use Copy All Context Collection from the submenu or Find Action without an active editor; it has no default shortcut. The current format, template and trimming settings apply to captured paths and code. Built-in formats label snapshots of the same location with fixed capture numbers and UTC times; custom templates keep their original substitutions. Blank item output blocks copying. Output above 256 KiB requires confirmation and above 4 MiB is blocked; snapshot/reference and size warnings share one confirmation. Copy retains the collection, never adds history or gutter markers, follows notification preferences, and counts toward opt-in analytics and the review prompt like a standard copy. The newest managed plugin copy wins across projects, including history/status re-copy; native Copy and external clipboard history remain outside this ordering. See the output contract implemented in #75 and sample selections.

Context Collection beside the editor with multiple captured files and byte counts

Multiple files beside the editor with retained raw and final-output byte counts.

Captured code and final output showing before and after snapshot labels

Before/after snapshots keep their original code and receive built-in capture labels in the final output.

Actual size confirmation for one item and 262145 UTF-8 bytes

One 262144-byte capture produces 262145 UTF-8 output bytes; the shared confirmation defaults to Cancel.

Compatible IDEs

Works with all IDEs based on IntelliJ Platform 2024.3+:

IntelliJ IDEA · Android Studio · PyCharm · WebStorm · PhpStorm · CLion · GoLand · Rider · RubyMine

Development

git clone https://github.com/hon454/copy-selection-context.git
cd copy-selection-context

# Unix / macOS
./gradlew buildPlugin    # Build plugin ZIP
./gradlew runIde         # Run dev IDE with plugin
./gradlew allTests       # Run the complete test suite

# Windows
gradlew.bat buildPlugin
gradlew.bat runIde
gradlew.bat allTests

See CONTRIBUTING.md for detailed development and release guides.

The test suite includes CopySelectionActionFixtureTest for real IntelliJ editor/action/clipboard and async permalink flows. CI runs the full tests, project and structure checks, verifyPlugin compatibility verification, plugin packaging, ZIP checks, and uploads diagnostics before publishing artifacts.

Support

If you find this plugin useful, consider buying me a coffee!

Buy Me A Coffee

License

Apache License 2.0 — see LICENSE for details.

Author

Made by @hon454

About

JetBrains IDE plugin to copy file paths, line numbers, and selected code in AI-ready formats for Claude, ChatGPT, and other coding assistants.

Topics

Resources

Contributing

Stars

3 stars

Watchers

0 watching

Forks

Releases

Contributors

Languages