A development-time React inspector for your components.
react-trace-demo.webm
Identify rendered components, find their source locations, and choose what to do:
- Open the file in your editor, on the exact line of your component definition
- Preview the code and edit it directly in the browser
- Add comments and then copy & paste to your AI agents
- Or even send them to your session on OpenCode for a seamless review experience
Use the @react-trace/kit package when you want the standard inspector setup with all official plugins already wired for you.
pnpm add --dev @react-trace/kitPeer requirements:
react >= 18react-dom >= 18
Change your dev script to export the project root e.g.:
- "dev": "vite"
+ "dev": "VITE_ROOT=$(pwd) vite",Then add it next to your app:
import Trace from '@react-trace/kit'
import App from './App'
export function Root() {
return (
<>
<App />
<Trace root={import.meta.env.VITE_ROOT} />
</>
)
}root should be the absolute path to the project being inspected. A common development setup is exporting it in your dev script, for example: VITE_ROOT=$(pwd) vite.
Use @react-trace/core when you want to choose plugins yourself. The official plugins also expect @react-trace/ui-components as a peer dependency.
pnpm add --dev @react-trace/core @react-trace/ui-components @react-trace/plugin-preview @react-trace/plugin-copy-to-clipboard @react-trace/plugin-open-editor @react-trace/plugin-commentsimport { Trace } from '@react-trace/core'
import { CommentsPlugin } from '@react-trace/plugin-comments'
import { CopyToClipboardPlugin } from '@react-trace/plugin-copy-to-clipboard'
import { OpenEditorPlugin } from '@react-trace/plugin-open-editor'
import { PreviewPlugin } from '@react-trace/plugin-preview'
import App from './App'
export function Root() {
return (
<>
<App />
<Trace
root={import.meta.env.VITE_ROOT}
plugins={[
PreviewPlugin(),
CopyToClipboardPlugin(),
OpenEditorPlugin(),
CommentsPlugin(),
]}
/>
</>
)
}| Package | What it adds |
|---|---|
@react-trace/plugin-preview |
Project-folder access, Monaco-based source preview, optional inline editing, and preview settings. |
@react-trace/plugin-copy-to-clipboard |
An action-panel item that copies the selected source as a project-relative path:lineNumber reference. |
@react-trace/plugin-open-editor |
An action-panel item for opening the selected source in supported local editors, plus editor selection in widget settings. |
@react-trace/plugin-comments |
Toolbar comments UI, inline add-comment flow, and "Copy to Clipboard" + "Send to OpenCode" support for collected comments. |
The fastest way to start is with the scaffolding CLI:
pnpm create react-trace-pluginThis generates a complete plugin package with build config, production stubs, and optional toolbar/action-panel/settings scaffolding.
A plugin is a TracePlugin object with a name and optional React components for the widget toolbar, selected-component actionPanel, and settings menu.
Those plugin components receive no props. Instead, read shared state through the public hooks exported by @react-trace/core, including useProjectRoot(), useInspectorActive(), useDeactivateInspector(), useSelectedContext(), useClearSelectedContext(), useSelectedSource(), and useWidgetPortalContainer().
In practice, plugin authors usually read the current selection with useSelectedContext() or useSelectedSource(), and render popovers or menus through useWidgetPortalContainer() so plugin UI stays inside the widget shell.
Clone the repo. Run nvm use and pnpm i.
packages/core—@react-trace/core, theTracecomponent, plugin API, hooks, and utilities.packages/react-trace—@react-trace/kit, the convenience wrapper with all official plugins pre-wired.packages/ui-components—@react-trace/ui-components, shared UI primitives used by the official plugins.packages/plugin-preview—@react-trace/plugin-preview, source preview/editor action panel with project-folder access.packages/plugin-comments—@react-trace/plugin-comments, inline comments and Send to OpenCode flows.packages/plugin-copy-to-clipboard—@react-trace/plugin-copy-to-clipboard, copies the selected source path and line.packages/plugin-open-editor—@react-trace/plugin-open-editor, opens the selected source in a local editor.apps/example— Vite + React demo app that mountsreact-trace.
pnpmworkspaces- Turborepo
- TypeScript
tsdownoxlint/oxfmt- Vitest
Run these from the repository root:
pnpm build
pnpm dev
pnpm test
pnpm lint
pnpm typecheck
pnpm fmt
pnpm fmt:checkUseful package-scoped commands:
pnpm --filter @react-trace/core build
pnpm --filter @react-trace/plugin-comments typecheck
pnpm --filter @react-trace/core exec vitest run src/path.test.ts
pnpm --filter example buildThe example lives in apps/example and depends on the workspace react-trace package. It is the fastest way to try the current widget and plugin bundle locally.
For a production build of the example app:
pnpm --filter example build- Package entry points use conditional exports for development and production builds.
- Each package has a
src/index.prod.tsproduction stub used for zero-cost production aliases. - If you need a full workspace watch across packages, use
pnpm devfrom the repo root.