Hover any UI element, copy its source context for AI agents. Built for Svelte 5.
svelte-lens gives your AI coding agent eyes inside your running app. Activate it, hover any DOM element, and press Cmd+C to copy the element's HTML preview and component source stack straight to your clipboard. Your agent gets precise, grounded context about what's on screen instead of guessing from file listings.
Inspired by react-grab by Aiden Bai — the same "hover and copy" concept, adapted for Svelte 5 with source resolution via __svelte_meta, a plugin system, and built-in MCP + CLI.
Cmd+Alt+G (macOS) or Ctrl+Alt+G (Linux/Windows)Cmd+C / Ctrl+C to copy the element's context to your clipboardThe copied context includes:
__svelte_meta through element-sourcenpm install @gear-null/svelte-lens
Add to your root layout — it auto-initializes in dev mode:
<!-- +layout.svelte -->
<script lang="ts">
import { dev } from "$app/environment";
import { onMount } from "svelte";
onMount(() => {
if (dev) {
void import("@gear-null/svelte-lens");
}
});
</script>
Or use the CLI to scaffold it automatically:
npx @gear-null/svelte-lens init
Connect svelte-lens directly to your AI agent via the built-in MCP server:
{
"mcpServers": {
"svelte-lens": {
"command": "npx",
"args": ["-y", "@gear-null/svelte-lens", "--mcp"]
}
}
}
Works with Claude Code, Cursor, Windsurf, and any MCP-compatible agent.
| Action | macOS | Linux/Windows |
|---|---|---|
| Toggle on/off | Cmd+Alt+G |
Ctrl+Alt+G |
| Deactivate | Escape |
Escape |
| Copy element context | Cmd+C |
Ctrl+C |
import { init } from "@gear-null/svelte-lens";
const api = init();
api.activate(); // Turn on the overlay
api.deactivate(); // Turn off and clean up
api.setEnabled(false); // Disable entirely
api.dispose(); // Tear down everything
// Plugin system — 8 hooks
api.registerPlugin({
name: "my-plugin",
onElementSelect: (ctx) => {
/* element was hovered */
},
transformCopyContent: (content) => {
// Modify what gets copied to clipboard
return content;
},
onAfterCopy: (content) => {
/* content was copied */
},
onCopyError: (err) => {
/* copy failed */
},
onContextMenu: (ctx, actions) => {
/* right-click menu */
},
});
Available hooks: onActivate, onDeactivate, onElementSelect, onBeforeCopy, transformCopyContent, onAfterCopy, onCopyError, onContextMenu.
Built-in plugins: copyPlugin (clipboard copy), openPlugin (open source in editor).
$state, $derived, $props throughout__svelte_meta via element-source to trace any element back to its component, file, and linenpx @gear-null/svelte-lens init auto-detects SvelteKit or Vite+Svelte and wires the import into your layoutsvelte-lens is a Svelte 5 port of react-grab by Aiden Bai. React-grab introduced the idea of hovering a UI element to grab its source context for AI agents — svelte-lens brings that same workflow to the Svelte ecosystem with Svelte 5-specific source resolution, a plugin architecture, and native MCP + CLI support.
MIT