Home
Relevant source files
The following files were used as context for generating this wiki page:react-grab is a developer tool designed to select context for AI coding agents directly from a web application's UI. By pointing at any element on a page, it provides the corresponding file name, React component stack, and HTML source code. This process significantly improves the speed and accuracy of AI tools like Cursor, Claude Code, and Copilot, making them up to 3x faster for frontend development tasks.
The core principle is to bridge the gap between visual intent and code implementation. Instead of developers manually searching for components or describing UI elements in prompts, react-grab provides the agent with a direct pointer to the relevant code. This is achieved by inspecting the React fiber tree in development mode to extract component source locations. The tool can be integrated into a project via a simple CLI command or by manually adding a script tag.
Sources: README.md:7-11, packages/website/app/blog/intro/page.tsx:300-308, packages/website/app/blog/agent/page.tsx:160-167
Core Functionality
The primary function of react-grab is to capture the context of a UI element when a user selects it. This is typically triggered by a hotkey.
The process is as follows:
- The user activates
react-graband clicks on a UI element. - The tool walks up the React fiber tree from the selected DOM element.
- It collects the display name and source location (file path, line, and column number) for each component in the hierarchy. This is only available in development mode.
- It captures a small snippet of the surrounding DOM and its attributes.
- This collected information is formatted into a readable context block, which can be copied to the clipboard or sent directly to an integrated coding agent.
Sources: packages/website/app/blog/agent/page.tsx:432-441, packages/website/app/blog/intro/page.tsx:355-364
This diagram illustrates the context-gathering flow.
Installation
react-grab is intended for use only in development environments and can be installed in several ways.
CLI Installation
The recommended method is to use the CLI at the project's root directory. This command automatically detects the framework and injects the necessary scripts.
npx grab@latest init
Sources: README.md:16-18, packages/website/components/install-tabs.tsx:64-68
Manual Installation
Alternatively, react-grab can be installed manually by adding a script to the project. The script should only be loaded when process.env.NODE_ENV === 'development'.
The following table summarizes the manual installation for various frameworks.
| Framework | File to Modify | Code Snippet |
|---|---|---|
| Next.js (App) | app/layout.tsx | <Script src="//unpkg.com/react-grab/dist/index.global.js" strategy="beforeInteractive" /> |
| Next.js (Pages) | pages/_document.tsx | <Script src="//unpkg.com/react-grab/dist/index.global.js" strategy="beforeInteractive" /> |
| Vite | index.html | if (import.meta.env.DEV) { import("react-grab"); } |
| Webpack | src/index.tsx | if (process.env.NODE_ENV === "development") { import("react-grab"); } |
Sources: packages/website/components/install-tabs.tsx:70-221, README.md:23-83
Coding Agent Integration
A key feature of react-grab is its ability to integrate directly with various AI coding agents. This creates a seamless workflow where a developer can select a UI element and have an agent immediately begin making changes to the codebase, without any copying or pasting.
This integration works via a client-server model:
- The
react-grabclient script in the browser sends the selected element's context and the user's prompt to a local server. - This local server, known as an "agent provider," is a small adapter that interfaces with the specific agent's CLI or SDK.
- The agent provider invokes the agent, which edits the codebase directly.
- Status updates from the agent are streamed back to the browser and displayed on the UI.
Sources: packages/react-grab/README.md:88-93, packages/website/app/blog/agent/page.tsx:443-455
The following diagram shows the architecture for agent integration.
Supported Agents
react-grab supports a variety of agents through dedicated provider packages. Each provider runs a local server on a specific port.
| Agent | Provider Package | Local 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: packages/react-grab/README.md:95-316, packages/website/app/blog/agent/page.tsx:238-605
Performance Benefits
By providing precise context, react-grab eliminates the "search phase" where an AI agent guesses which files to edit. This makes the agent significantly faster and more reliable. Benchmarks run on a shadcn/ui dashboard codebase showed that using react-grab made Claude 4.5 Sonnet approximately 3x faster on average across 20 UI editing tasks.
| Metric | Without React Grab (Control) | With React Grab (Treatment) | Improvement |
|---|---|---|---|
| Average Time | ~17 seconds | ~6 seconds | ~3x faster |
The performance gain comes from reducing the number of tool calls and tokens consumed, as the agent can directly access the correct file and line number instead of performing a series of grep or search operations.
Sources: packages/website/app/blog/intro/page.tsx:143-152, 431-436, packages/website/app/blog/visual-edit/page.tsx:191-197
Project Structure
The react-grab repository is a monorepo containing the core library, agent providers, and the project website.
packages/
├── react-grab/ # Core library
├── cli/ # CLI installer (@react-grab/cli)
├── provider-cursor/ # Cursor agent integration
├── provider-claude-code/ # Claude Code integration
├── provider-opencode/ # OpenCode integration
├── provider-codex/ # OpenAI Codex integration
├── provider-gemini/ # Google Gemini CLI integration
├── provider-amp/ # Amp SDK integration
├── provider-ami/ # AMI client
├── website/ # Documentation site (react-grab.com)
├── vite-playground/ # Vite development playground
├── next-playground/ # Next.js development playground
├── agent-playground/ # Agent testing playground
├── benchmarks/ # Performance benchmarks
└── web-extension/ # Browser extension
Sources: CONTRIBUTING.md:21-38
Conclusion
react-grab is a powerful, open-source utility that enhances the workflow of frontend developers using AI coding agents. By providing direct, actionable context from the UI, it dramatically reduces the latency and non-determinism associated with AI-driven code modification. Its simple installation and broad support for popular agents make it an accessible tool for improving developer productivity.
Sources: README.md:7-11, 322-330, packages/grab/README.md:7-11