An Astro integration that enables click-to-source functionality during development. Hold Alt (or another modifier) and click any element to instantly open its source file in your editor at the exact line and column.
- Alt+Click to open source - Jump directly to the component source in your editor
- Visual highlighting - See which element you're about to open when holding the modifier key
- Tooltip preview - Shows the file path and line number before you click
- Clipboard mode - Copy the source path instead of opening the editor
- Multi-editor support - Works with VS Code, Neovim, WebStorm, and more
- HMR-aware - Maintains source mappings across hot module reloads
- Zero config - Works out of the box with sensible defaults
npm install astro-click-to-sourceAdd the integration to your astro.config.mjs:
import { defineConfig } from 'astro/config';
import { clickToSource } from 'astro-click-to-source';
export default defineConfig({
integrations: [clickToSource()]
});Then run your dev server and Alt+Click (or Option+Click on Mac) any element to open its source file.
| Option | Type | Default | Description |
|---|---|---|---|
modifier |
'alt' | 'ctrl' | 'meta' | 'shift' |
'alt' |
Modifier key to hold while clicking |
showHighlight |
boolean |
true |
Show visual highlight on hover when modifier is held |
annotate |
boolean |
auto | Inject data-astro-source-* attributes ourselves instead of relying on Astro's compiler. Auto-enabled on Astro 7+ (see Compatibility). Leave unset unless you need to force it on or off. |
import { clickToSource } from 'astro-click-to-source';
export default defineConfig({
integrations: [
clickToSource({
modifier: 'ctrl', // Use Ctrl+Click instead of Alt+Click
showHighlight: false // Disable visual highlighting
})
]
});Set this environment variable to customize the behavior:
| Value | Behavior |
|---|---|
code (default) |
Open in VS Code |
cursor |
Open in Cursor |
windsurf |
Open in Windsurf |
antigravity |
Open in Antigravity |
trae |
Open in Trae |
nvim |
Open in Neovim |
vim |
Open in Vim |
webstorm |
Open in WebStorm |
phpstorm |
Open in PhpStorm |
idea |
Open in IntelliJ IDEA |
sublime |
Open in Sublime Text |
atom |
Open in Atom |
clipboard |
Copy path to clipboard instead of opening editor |
Any CLI command on your
PATHthat accepts afile:line:columnargument will work — the value is forwarded tolaunch-editor. So if your editor ships a shell binary (e.g. theantigravitycommand installed by the Antigravity IDE), just setCLICK_TO_SOURCEto its name.
# Open in Neovim
CLICK_TO_SOURCE=nvim npm run dev
# Open in Antigravity IDE
CLICK_TO_SOURCE=antigravity npm run dev
# Copy to clipboard
CLICK_TO_SOURCE=clipboard npm run dev- Source Mapping: Elements carry
data-astro-source-fileanddata-astro-source-locattributes in development mode. On Astro 4–6 these come from Astro's compiler; on Astro 7+ this integration injects them itself (see Compatibility) - Caching: The integration caches these mappings to survive HMR updates
- Click Handling: When you Alt+Click, it finds the nearest element with source info
- Editor Opening: Uses
launch-editorto open your editor at the exact location
Click-to-source relies on each element carrying a data-astro-source-file /
data-astro-source-loc attribute that points back at its position in the
.astro source.
- Astro 4–6 emit these attributes from the compiler (
@astrojs/compiler, Go/WASM), so the integration just reads them. - Astro 7 replaced that compiler with the Rust
@astrojs/compiler-rs, which no longer emits the attributes — so without this integration the feature silently stops working. To fix it, the integration adds a dev-only Viteloadhook that parses each.astrofile with the standalone@astrojs/compilerand injects the attributes back into the template before Astro compiles it. This is auto-enabled on Astro 7+ and runs only inastro dev(production output is untouched).
You can override the auto-detection with the annotate option.
The integration uses launch-editor which automatically detects your editor from:
CLICK_TO_SOURCEenvironment variableLAUNCH_EDITORenvironment variableEDITORenvironment variable- Running editor processes
- Astro 4, 5, 6, or 7
- Node.js 18.17.0 or higher (Astro 7 / Vite 8 require Node.js 20.19.0+)
MIT
