npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

astro-grab

v0.2.1

Published

Grab context for coding agents directly from your astro site.

Downloads

168

Readme

Astro Grab (Alpha)

Visual element targeting for Astro projects - Hold Cmd/Ctrl+G to target any element and copy its source code to your clipboard.

What is Astro Grab?

Astro Grab is a dev-only tool that helps you quickly locate and grab source code from your Astro components. Simply hold Cmd+G (Mac) or Ctrl+G (Windows/Linux) for one second, then click any element to copy its source snippet to your clipboard - perfect for pasting into AI assistants like Claude.

Features (Alpha)

  • 🎯 Visual targeting mode: Hold Cmd/Ctrl+G to enter targeting mode with visual highlights
  • 📋 Instant clipboard copy: Click any element to copy its source code snippet
  • 🔍 Source attribution: Automatically tracks elements to their .astro files
  • Dev-only: Zero impact on production builds
  • 🎨 Non-intrusive: Overlay doesn't interfere with page interaction

Quick Start

Installation

bun install

Development

Start all package watchers and the demo app:

bun run dev

This will:

  • Build and watch all packages in packages/
  • Start the Astro dev server for the demo in apps/demo
  • Enable hot reload for client code changes

Builds are optimized with Turborepo:

  • Automatic parallel execution when dependencies allow
  • Local caching speeds up subsequent builds
  • Dependency graph ensures correct build order

Visit http://localhost:4321 and try the targeting mode:

  1. Hold Cmd+G (Mac) or Ctrl+G (Win/Linux) for 1 second
  2. Move your mouse over elements to see them highlighted
  3. Click an element to copy its source code
  4. Press Escape to exit targeting mode

Building

Build all packages with Turborepo:

bun run build

Turborepo automatically:

  • Builds packages in dependency order (shared → server/client → integration)
  • Caches build outputs for faster rebuilds
  • Runs packages in parallel when dependencies allow

Build specific packages:

bun run turbo run build --filter astro-grab-shared

Testing

Run all tests:

bun run test

Watch mode:

bun run test:watch

Run tests in specific package:

bun run turbo run test --filter astro-grab-shared

Project Structure

This is a Bun monorepo with the following packages:

  • packages/astro-grab: Main Astro integration (what users install)
  • packages/astro-grab-client: Client-side overlay and keybind logic
  • packages/astro-grab-server: Vite dev server middleware and snippet endpoint
  • packages/astro-grab-shared: Shared types and utilities
  • apps/demo: Demo Astro site for testing

Usage in Your Project

  1. Install the integration:
bun add astro-grab
  1. Add to your astro.config.mjs:
import { defineConfig } from "astro/config";
import { astroGrab } from "astro-grab";

export default defineConfig({
  integrations: [
    astroGrab({
      enabled: true, // Enable in dev mode (default: true)
      holdDuration: 1000, // Hold time in ms (default: 1000)
      contextLines: 10, // Lines of context around target (default: 5)
      template: `Source: {{file}}:{{targetLine}}\n\n\`\`\`{{language}}\n{{snippet}}\n\`\`\``, // Custom clipboard template
    }),
  ],
});

Custom Clipboard Template

You can customize the format of the copied snippet using the template option with {{variable}} interpolation:

astroGrab({
  template: `File: {{file}}
Line: {{targetLine}}

{{snippet}}`,
});

Available variables:

| Variable | Description | Example | | ---------------- | -------------------------- | --------------------------- | | {{file}} | Path to the .astro file | src/components/Card.astro | | {{snippet}} | The extracted code snippet | <div>...</div> | | {{startLine}} | First line of snippet | 12 | | {{endLine}} | Last line of snippet | 18 | | {{targetLine}} | The line clicked on | 15 | | {{language}} | Language identifier | astro |

  1. Run your dev server:
npm run dev
  1. Hold Cmd/Ctrl+G and click elements to grab their source!

Production Usage (Demo Sites)

By default, astro-grab only works in development mode. For demo sites or production deployments that need to showcase the feature, you can force-enable it:

# Build with astro-grab enabled
ASTRO_GRAB_DANGEROUSLY_FORCE_ENABLE=true npm run build

⚠️ Security Warning: This exposes source code snippets to end users. Only enable this on demo sites where sharing component source is intentional.

How It Works

  1. Instrumentation: During dev, the Vite plugin transforms .astro files to add data-astro-grab="file:line:col" attributes to HTML elements
  2. Client injection: The integration automatically injects a client script that listens for Cmd/Ctrl+G
  3. Targeting mode: Holding the keybind for 1s activates an overlay that highlights elements under the cursor
  4. Snippet extraction: Clicking an element fetches a code snippet from the dev server and copies it to clipboard

Known Limitations (Alpha)

  • HMR: Client changes require page reload; server/integration changes require dev server restart
  • Parser: Only .astro files (no .jsx, .vue, etc.)
  • Snippets: Fixed context window (±40 lines), no dependency resolution
  • Browser: Requires modern browser with Clipboard API (HTTPS or localhost)

Development

See DEVELOPMENT.md for detailed development instructions, architecture notes, and contribution guidelines.

License

MIT