Agent: Claude Code Integration
Relevant source files
The following files were used as context for generating this wiki page:The Claude Code integration is an agent provider for React Grab that connects the in-browser element selection tool directly to the Claude Agent SDK. Its purpose is to enable a seamless workflow where a developer can select a UI element, provide a prompt, and have the Claude Code agent make changes to the codebase directly, without leaving the browser or manually copying context.
This integration consists of a client-side script that captures user intent and a local Node.js server that acts as a bridge to the Claude agent. This architecture streamlines the development loop for UI tasks by eliminating the agent's need to search for code, making the process significantly faster and more accurate.
Sources: packages/website/app/blog/agent/page.tsx:169-176, 442-463, packages/provider-claude-code/README.md
Architecture and Data Flow
The integration operates through a three-part architecture: a client script running in the browser, a local Node.js server, and the Claude Code agent itself. The client sends context to the server via an HTTP POST request, and the server communicates with the Claude agent via its SDK. Status updates are streamed back to the client using Server-Sent Events (SSE).
This diagram illustrates the data flow between the components.
Setup and Configuration
The Claude Code integration can be installed and configured automatically using the grab CLI or set up manually.
Sources: packages/cli/src/commands/init.ts, packages/cli/src/commands/add.ts
CLI Installation
The recommended way to install is using the grab CLI, which handles package installation and script configuration.
- Initialize React Grab: If not already installed, run the init command in your project root.
npx grab@latest init - Add Claude Code Agent: During the
initprocess, you can select "Claude Code" as an agent integration. If React Grab is already installed, you can add the agent with theaddcommand.npx grab@latest add claude-code
The CLI will automatically modify your package.json and the relevant layout file (e.g., app/layout.tsx for Next.js) to include the necessary scripts.
Sources: packages/cli/src/commands/init.ts:104-106, 611-623, packages/cli/src/commands/add.ts:71-73
Server Setup
The local server interfaces with the Claude Agent SDK and runs on port 4567 by default.
package.json Script
You can add a command to your package.json dev script to start the server alongside your development server.
{
"scripts": {
"dev": "npx @react-grab/claude-code@latest && next dev"
}
}
Note: When using this method, the server runs as a detached background process and must be stopped manually with pkill -f "react-grab.*server".
Sources: packages/provider-claude-code/README.md:16-25, packages/website/app/blog/agent/page.tsx:216-224
Config File (Recommended)
For better lifecycle management, you can import and run startServer directly within your framework's configuration file. This ensures the server stops when the dev server stops.
Next.js (next.config.mjs):
import { startServer } from "@react-grab/claude-code/server";
if (process.env.NODE_ENV === "development") {
startServer();
}
// Your Next.js config...
Sources: packages/provider-claude-code/README.md:27-41
Client Setup
The client-side script must be added to your application to enable the in-browser UI.
HTML Script Tag
Include the core react-grab script and the claude-code client script in your HTML's <head>.
<script src="//unpkg.com/react-grab/dist/index.global.js"></script>
<script src="//unpkg.com/@react-grab/claude-code/dist/client.global.js"></script>
Sources: packages/provider-claude-code/README.md:45-48, packages/website/app/blog/agent/page.tsx:234-238
Next.js Script Component
In a Next.js App Router project, add the scripts to your app/layout.tsx file.
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"
strategy="beforeInteractive"
/>
<Script
src="//unpkg.com/@react-grab/claude-code/dist/client.global.js"
strategy="lazyOnload"
/>
</>
)}
</head>
<body>{children}</body>
</html>
);
}
Sources: packages/react-grab/README.md:104-123, packages/website/app/blog/agent/page.tsx:246-267
Workflow
The end-to-end workflow from user interaction to code modification is designed to be seamless and entirely contained within the browser.
This sequence diagram shows the interaction between the user, the client, the server, and the agent.
This process allows for rapid, iterative UI development. The user can even initiate multiple tasks on different elements, with each task's progress tracked independently.
Sources: packages/website/app/blog/agent/page.tsx:169-186, packages/provider-claude-code/README.md:65-76
Summary
The @react-grab/claude-code package is a provider that bridges the gap between the react-grab in-browser tool and the Claude Code agent. By providing precise context (component stack, file paths, line numbers) directly from the UI, it allows the agent to bypass the error-prone search phase and begin editing code immediately. This results in a faster, more reliable, and more intuitive workflow for frontend development tasks, keeping the developer in the flow and within the context of their application.
Sources: packages/website/app/blog/agent/page.tsx:442-463, packages/website/app/blog/intro/page.tsx:249-261