Development-Only Usage
Relevant source files
The following files were used as context for generating this wiki page:react-grab is a developer tool designed to be used exclusively during the development phase of a project. Its primary purpose is to inspect React applications, extract component context including source file paths and line numbers, and integrate with AI coding agents to streamline UI modifications. The tool is conditionally loaded only when process.env.NODE_ENV is set to "development".
The core functionality relies on React's development-only feature that exposes source location data on component fiber nodes. When an element is selected, react-grab traverses the React fiber tree to collect a stack trace of components with their exact source locations. This information is then provided to the developer or an integrated coding agent, eliminating the need for manual codebase searching. In production builds, where this source information is stripped, the tool's capabilities are limited to showing component names without file paths.
Sources: packages/react-grab/README.md:31-48, packages/website/app/blog/intro/page.tsx:288-295, packages/website/app/blog/agent/page.tsx:473-479
Project Setup for Contribution
To contribute to react-grab or run it locally from the source, you must set up the development environment. The project is a monorepo managed with pnpm.
Sources: CONTRIBUTING.md:5-8
Prerequisites
- Node.js version 18 or higher
- pnpm version 8 or higher
Sources: CONTRIBUTING.md:8-9
Initial Setup Workflow
The following diagram illustrates the steps to get the project running locally.
This diagram shows the sequence of commands for setting up the local development environment.
Sources: CONTRIBUTING.md:12-28
Project Structure
The repository is organized into several packages within the packages/ directory. Key packages for development include the core library, various agent providers, and playgrounds for testing.
| Package | Description |
|---|---|
react-grab/ | The core library containing the main logic. |
cli/ | The CLI installer (@react-grab/cli). |
provider-* | A series of packages for integrating with different coding agents (e.g., provider-cursor, provider-claude-code). |
*-playground/ | Development playgrounds for Vite, Next.js, and agent testing. |
website/ | The documentation and marketing website. |
benchmarks/ | Performance benchmarks. |
Sources: CONTRIBUTING.md:31-46
Installation and Integration
react-grab is designed to be injected into a React application only during development. This is typically achieved by checking process.env.NODE_ENV === "development" before importing or adding the script tag.
Sources: README.md:31-33, packages/website/components/install-tabs.tsx:10-17
Automatic Installation (CLI)
The recommended way to install react-grab into a project is by using the CLI command at the project's root.
npx grab@latest init
This command automatically detects the framework (e.g., Next.js, Vite) and injects the necessary scripts.
Sources: README.md:25-29, packages/website/components/install-tabs.tsx:59-64
Manual Installation
For manual setup, you must add the script to your application's entry point, ensuring it only loads in development.
The diagram below shows the conditional loading logic.
This demonstrates how react-grab is only activated in the development environment.
Sources: README.md:31-48, packages/website/components/install-tabs.tsx:73-86
Next.js (App Router)
In app/layout.tsx, add the Script component inside the <head>.
import Script from "next/script";
export default function RootLayout({ children }) {
return (
<html>
<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:36-52, packages/website/components/install-tabs.tsx:73-90
Vite
In index.html, dynamically import the package inside a script tag.
<!doctype html>
<html lang="en">
<head>
<script type="module">
// first npm i react-grab
// then in head:
if (import.meta.env.DEV) {
import("react-grab");
}
</script>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>
Sources: README.md:69-86, packages/website/components/install-tabs.tsx:142-161
Agent Provider Integration
A key development feature is the direct integration with AI coding agents. This allows developers to select a UI element and have an agent automatically apply changes to the codebase. This workflow involves a client-side script that captures context and a local server that interfaces with the agent's CLI or SDK.
Sources: README.md:96-102, packages/website/app/blog/agent/page.tsx:112-121
Agent Workflow
The sequence diagram below details the interaction between the user, react-grab, the local provider server, and the coding agent.
This diagram illustrates the end-to-end process from a user's action in the browser to the code being modified by an AI agent.
Sources: packages/website/app/blog/agent/page.tsx:481-496
Supported Agent Providers
react-grab supports various coding agents through dedicated provider packages. Each provider runs a local server on a specific port.
| Agent | Package | package.json Script | Default Port |
|---|---|---|---|
| Claude Code | @react-grab/claude-code | npx @react-grab/claude-code@latest && next dev | 4567 |
| Cursor CLI | @react-grab/cursor | npx @react-grab/cursor@latest && next dev | 5567 |
| OpenCode | @react-grab/opencode | npx @react-grab/opencode@latest && next dev | 6567 |
| Codex | @react-grab/codex | npx @react-grab/codex@latest && next dev | 7567 |
| Gemini | @react-grab/gemini | npx @react-grab/gemini@latest && next dev | 8567 |
| Amp | @react-grab/amp | npx @react-grab/amp@latest && next dev | 9567 |
| Factory Droid | @react-grab/droid | npx @react-grab/droid@latest && next dev | 10567 |
Sources: README.md:104-282, packages/website/app/blog/agent/page.tsx:216-469
Development Playgrounds
The project includes several playground environments for testing changes to the core library and agent integrations. These are essential for the development workflow.
- Vite Playground:
pnpm --filter vite-playground dev - Next.js Playground:
pnpm --filter next-playground dev - Agent Playground:
pnpm --filter @react-grab/agent-playground dev:<agent_name>(e.g.,dev:claude,dev:cursor)
The agent playground runs at http://localhost:5174 and allows for testing provider integrations with various backends.
Sources: CONTRIBUTING.md:51-66
Development Standards
Contributors are expected to follow a set of coding standards to maintain code quality and consistency.
- TypeScript: Prefer interfaces over types.
- Functions: Use arrow functions over function declarations.
- File Naming: Use kebab-case for file names.
- Variable Naming: Use descriptive names; avoid short or single-character names.
- Comments: Avoid comments unless absolutely necessary. Hacks must be prefixed with
// HACK:.
Sources: AGENTS.md:3-15
Conclusion
react-grab is fundamentally a development-time tool that enhances the frontend workflow. By providing precise component context and integrating directly with AI coding agents, it significantly reduces the friction and time required for UI iteration and debugging. Its architecture is explicitly designed to be active only in development environments, ensuring no performance overhead or exposure of source code information in production.