|
1 | 1 | # agent-react-devtools |
2 | 2 |
|
3 | | -CLI tool for AI agents to inspect React component trees and profile rendering performance. Connects to running React apps via the React DevTools protocol. |
| 3 | +Give your AI agent eyes into your React app. Inspect component trees, read props and state, and profile rendering performance — all from the command line. Inspired by Vercel's [agent-browser](https://github.com/vercel-labs/agent-browser) and Callstack's [agent-device](https://github.com/callstackincubator/agent-device). |
4 | 4 |
|
5 | | -## Development |
| 5 | +The project is in early development and considered experimental. Pull requests are welcome! |
| 6 | + |
| 7 | +## Features |
| 8 | + |
| 9 | +- Walk the full component tree with props, state, and hooks |
| 10 | +- Search for components by display name |
| 11 | +- Profile renders: find slow components, excessive re-renders, and commit timelines |
| 12 | +- Persistent background daemon that survives across CLI calls |
| 13 | +- Token-efficient output built for LLM consumption |
| 14 | + |
| 15 | +## Install |
| 16 | + |
| 17 | +```sh |
| 18 | +npm install -g agent-react-devtools |
| 19 | +``` |
| 20 | + |
| 21 | +Or run it directly: |
| 22 | + |
| 23 | +```sh |
| 24 | +npx agent-react-devtools start |
| 25 | +``` |
| 26 | + |
| 27 | +## Quick Start |
| 28 | + |
| 29 | +```sh |
| 30 | +agent-react-devtools start |
| 31 | +agent-react-devtools status |
| 32 | +``` |
| 33 | + |
| 34 | +``` |
| 35 | +Daemon: running (port 8097) |
| 36 | +Apps: 1 connected, 24 components |
| 37 | +Uptime: 12s |
| 38 | +``` |
| 39 | + |
| 40 | +Browse the component tree: |
| 41 | + |
| 42 | +```sh |
| 43 | +agent-react-devtools get tree --depth 3 |
| 44 | +``` |
| 45 | + |
| 46 | +``` |
| 47 | +@c1 [fn] "App" |
| 48 | +├─ @c2 [fn] "Header" |
| 49 | +│ ├─ @c3 [fn] "Nav" |
| 50 | +│ └─ @c4 [fn] "SearchBar" |
| 51 | +├─ @c5 [fn] "TodoList" |
| 52 | +│ ├─ @c6 [fn] "TodoItem" key="1" |
| 53 | +│ ├─ @c7 [fn] "TodoItem" key="2" |
| 54 | +│ └─ @c8 [fn] "TodoItem" key="3" |
| 55 | +└─ @c9 [fn] "Footer" |
| 56 | +``` |
| 57 | + |
| 58 | +Inspect a component's props, state, and hooks: |
| 59 | + |
| 60 | +```sh |
| 61 | +agent-react-devtools get component @c6 |
| 62 | +``` |
| 63 | + |
| 64 | +``` |
| 65 | +@c6 [fn] "TodoItem" key="1" |
| 66 | +props: |
| 67 | + id: 1 |
| 68 | + text: "Buy groceries" |
| 69 | + done: false |
| 70 | + onToggle: ƒ |
| 71 | +hooks: |
| 72 | + State: false |
| 73 | + Callback: ƒ |
| 74 | +``` |
| 75 | + |
| 76 | +Find components by name: |
6 | 77 |
|
7 | 78 | ```sh |
8 | | -# Install dependencies |
9 | | -bun install |
| 79 | +agent-react-devtools find TodoItem |
| 80 | +``` |
10 | 81 |
|
11 | | -# Build |
12 | | -bun run build |
| 82 | +``` |
| 83 | +@c6 [fn] "TodoItem" key="1" |
| 84 | +@c7 [fn] "TodoItem" key="2" |
| 85 | +@c8 [fn] "TodoItem" key="3" |
| 86 | +``` |
13 | 87 |
|
14 | | -# Run tests |
15 | | -bun run test |
| 88 | +Profile rendering performance: |
16 | 89 |
|
17 | | -# Type check |
18 | | -bun run typecheck |
| 90 | +```sh |
| 91 | +agent-react-devtools profile start |
| 92 | +# ... interact with the app ... |
| 93 | +agent-react-devtools profile stop |
| 94 | +agent-react-devtools profile slow |
| 95 | +``` |
| 96 | + |
| 97 | +``` |
| 98 | +Slowest (by avg render time): |
| 99 | + TodoList avg:4.2ms max:8.1ms renders:6 cause:props |
| 100 | + SearchBar avg:2.1ms max:3.4ms renders:12 cause:hooks |
| 101 | + Header avg:0.8ms max:1.2ms renders:3 cause:parent |
| 102 | +``` |
| 103 | + |
| 104 | +## Commands |
| 105 | + |
| 106 | +### Daemon |
| 107 | + |
| 108 | +```sh |
| 109 | +agent-react-devtools start [--port 8097] # Start daemon |
| 110 | +agent-react-devtools stop # Stop daemon |
| 111 | +agent-react-devtools status # Connection status |
| 112 | +``` |
| 113 | + |
| 114 | +### Components |
| 115 | + |
| 116 | +```sh |
| 117 | +agent-react-devtools get tree [--depth N] # Component hierarchy |
| 118 | +agent-react-devtools get component <@c1 | id> # Props, state, hooks |
| 119 | +agent-react-devtools find <name> [--exact] # Search by display name |
| 120 | +agent-react-devtools count # Component count by type |
| 121 | +``` |
| 122 | + |
| 123 | +Components are labeled `@c1`, `@c2`, etc. You can use these labels or numeric IDs interchangeably. |
| 124 | + |
| 125 | +### Profiling |
| 126 | + |
| 127 | +```sh |
| 128 | +agent-react-devtools profile start [name] # Begin a profiling session |
| 129 | +agent-react-devtools profile stop # Stop and collect data |
| 130 | +agent-react-devtools profile report <@c1 | id> # Render report for a component |
| 131 | +agent-react-devtools profile slow [--limit N] # Slowest components by avg duration |
| 132 | +agent-react-devtools profile rerenders [--limit N] # Most re-rendered components |
| 133 | +agent-react-devtools profile timeline [--limit N] # Commit timeline |
| 134 | +agent-react-devtools profile commit <N | #N> [--limit N] # Single commit detail |
| 135 | +``` |
| 136 | + |
| 137 | +## Connecting Your App |
| 138 | + |
| 139 | +Install `react-devtools-core` in your app and connect before React renders (e.g. in `src/main.tsx`): |
| 140 | + |
| 141 | +```ts |
| 142 | +import { initialize, connectToDevTools } from 'react-devtools-core'; |
| 143 | +import { createRoot } from 'react-dom/client'; |
| 144 | +import App from './App'; |
| 145 | + |
| 146 | +initialize(); |
| 147 | +connectToDevTools({ port: 8097 }); |
| 148 | + |
| 149 | +createRoot(document.getElementById('root')!).render(<App />); |
| 150 | +``` |
| 151 | + |
| 152 | +## Using with AI Agents |
| 153 | + |
| 154 | +Add something like this to your project's `CLAUDE.md` (or equivalent agent instructions): |
| 155 | + |
| 156 | +```markdown |
| 157 | +## React Debugging |
| 158 | + |
| 159 | +This project uses agent-react-devtools to inspect the running React app. |
| 160 | + |
| 161 | +- `agent-react-devtools start` — start the daemon |
| 162 | +- `agent-react-devtools status` — check if the app is connected |
| 163 | +- `agent-react-devtools get tree` — see the component hierarchy |
| 164 | +- `agent-react-devtools get component @c1` — inspect a specific component |
| 165 | +- `agent-react-devtools find <Name>` — search for components |
| 166 | +- `agent-react-devtools profile start` / `profile stop` / `profile slow` — diagnose render performance |
| 167 | +``` |
| 168 | + |
| 169 | +## Development |
| 170 | + |
| 171 | +```sh |
| 172 | +bun install # Install dependencies |
| 173 | +bun run build # Build |
| 174 | +bun run test # Run tests |
| 175 | +bun run typecheck # Type check |
19 | 176 | ``` |
20 | 177 |
|
21 | 178 | ## License |
|
0 commit comments