Getting Started
Relevant source files
The following files were used as context for generating this wiki page:
React Grab is a developer tool designed to accelerate frontend development by bridging the gap between your live web application and AI coding agents. It allows you to select any UI element directly in your browser and instantly get its corresponding React component context, including the file name, component stack, and source code. This eliminates the guesswork and search phase for AI agents, making them significantly faster and more accurate for UI-related tasks.
The core principle is to provide precise, actionable context to tools like Cursor, Claude Code, and Copilot, which can improve their performance by up to 3x. This is achieved by walking the React fiber tree in development mode to extract source locations. Beyond simple context copying, React Grab also supports direct integration with various coding agents, enabling a seamless workflow where you can select an element, describe a change, and have the agent modify your codebase without leaving the browser.
Sources: README.md, packages/website/app/blog/intro/page.tsx:213-220, packages/website/app/blog/agent/page.tsx:203-211
Installation
You can add React Grab to your project using the automated CLI or by manually adding a script to your application's entry point. The tool is intended for use only in the development environment.
Sources: README.md:19-25, packages/website/components/install-tabs.tsx:1-10
CLI (Recommended)
The quickest way to install React Grab is by using the init command from the grab CLI. Run this command at the root of your project. The CLI will automatically detect your framework (e.g., Next.js, Vite) and inject the necessary scripts.
npx grab@latest init
Sources: README.md:19-21, packages/website/app/blog/agent/page.tsx:313-318, packages/website/components/install-tabs.tsx:75-80
Manual Installation
If you prefer a manual setup, you can add the React Grab script to your project based on your framework.
Next.js (App Router)
In a Next.js App Router project, add the Script component to your root layout file.
File: app/layout.tsx
import Script from "next/script";
export default function RootLayout({ children }) {
return (
<html>
<head>
{/* Add this script to the <head> */}
{process.env.NODE_ENV === "development" && (
<Script
src="//unpkg.com/react-grab/dist/index.global.js"
crossOrigin="anonymous"
strategy="beforeInteractive"
/>
)}
</head>
<body>{children}</body>
</html>
);
}
Sources: README.md:27-46, packages/website/components/install-tabs.tsx:82-106
Vite
For Vite projects, you first need to install the package and then import it within your index.html file, guarded by a development environment check.
- Install the package:
npm install grab - Modify your
index.html:<!doctype html> <html lang="en"> <head> <script type="module"> // In your <head> after installing 'grab' if (import.meta.env.DEV) { import("grab"); } </script> </head> <body> <div id="root"></div> <script type="module" src="/src/main.tsx"></script> </body> </html>
Sources: packages/grab/README.md:65-85, packages/website/components/install-tabs.tsx:136-163
Coding Agent Integration
React Grab can directly communicate with coding agents, creating a powerful workflow where UI edits are initiated from the browser. This eliminates the need to manually copy and paste context.
Sources: packages/react-grab/README.md:83-87, packages/website/app/blog/agent/page.tsx:298-309
Architecture
The integration works by having the React Grab client script in the browser send the selected element's context and a user prompt to a local server. This server acts as a proxy, forwarding the request to the respective agent's command-line tool, which then performs the code modifications. Status updates are streamed back to the browser.
The following diagram illustrates the agent integration data flow.
Setup
Each agent integration requires two parts: a server-side script added to your package.json and an additional client-side script in your HTML head.
The following agents are supported, each with its own package and default server port:
| Agent | Package | Server Port |
|---|---|---|
| Claude Code | @react-grab/claude-code | 4567 |
| Cursor CLI | @react-grab/cursor | 5567 |
| OpenCode | @react-grab/opencode | 6567 |
| Codex | @react-grab/codex | 7567 |
| Gemini | @react-grab/gemini | 8567 |
| Amp | @react-grab/amp | 9567 |
| Factory Droid | @react-grab/droid | 10567 |
Sources: README.md:89-291, packages/website/app/blog/agent/page.tsx:325-548
Example: Claude Code Integration
-
Server Setup: Modify the
devscript in yourpackage.jsonto start the Claude Code agent server alongside your development server.{ "scripts": { "dev": "npx @react-grab/claude-code@latest && next dev" } } -
Client Setup: Add the Claude Code client script in your
app/layout.tsx(for Next.js) after the mainreact-grabscript.{process.env.NODE_ENV === "development" && ( <> <Script src="//unpkg.com/react-grab/dist/index.global.js" strategy="beforeInteractive" /> <Script src="//unpkg.com/@react-grab/claude-code/dist/client.global.js" strategy="lazyOnload" /> </> )}
The setup process is similar for all other supported agents, using their respective packages.
Sources: packages/react-grab/README.md:92-124, packages/website/app/blog/agent/page.tsx:330-381
Customization API
React Grab exposes a public API for customization, allowing you to change its appearance and behavior. You can access it by importing the init function from grab/core or react-grab/core.
Sources: packages/react-grab/README.md:293-296, packages/grab/README.md:290-293
Configuration Options
The init function accepts a configuration object with the following options:
| Option | Type | Description |
|---|---|---|
theme.enabled | boolean | Set to false to disable all React Grab UI elements. |
theme.hue | number | A value from 0-360 to shift the hue of the UI colors. |
theme.crosshair.enabled | boolean | Set to false to disable the crosshair overlay. |
theme.elementLabel.enabled | boolean | Set to false to disable the label that appears on hover. |
onElementSelect | (element) => void | A callback function that fires when an element is selected. |
onCopySuccess | (elements, content) => void | A callback that fires after context has been successfully copied. |
onStateChange | (state) => void | A callback that fires when the tool's active state changes. |
Sources: packages/react-grab/README.md:298-319
Example Usage
Here is an example of how to initialize React Grab with custom options:
import { init } from "grab/core";
if (process.env.NODE_ENV === "development") {
const api = init({
theme: {
hue: 240, // Change UI color to blue
},
onElementSelect: (element) => {
console.log("Selected:", element);
},
});
// You can also programmatically control the tool
// api.activate();
}
Sources: packages/grab/README.md:295-322
Contributing & Development Setup
If you wish to contribute to React Grab, you will need to set up the development environment.
Sources: CONTRIBUTING.md:3-5
Prerequisites
- Node.js >= 18
- pnpm >= 8
Sources: CONTRIBUTING.md:7-9
Local Setup
- Fork and clone the repository.
- Install dependencies using
@antfu/ni:ni - Build all packages in the monorepo:
nr build - Start the development server for a playground (e.g., Vite):
pnpm --filter vite-playground dev
Sources: CONTRIBUTING.md:12-27
Project Structure
The repository is a monorepo containing the core library, CLI, agent providers, and development playgrounds.
This diagram shows the high-level structure of the packages directory.
Sources: CONTRIBUTING.md:29-45