This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
React component library for displaying Claude Code transcripts. Packaged as an ESM library with TypeScript types and compiled CSS, intended for external consumption.
npm run build— Build with tsup (outputs dist/index.js, dist/headless.js, dist/index.d.ts, dist/index.css)npm run dev— Watch mode buildnpm run storybook— Start Storybook dev server on port 6006npm run build-storybook— Build static Storybook tostorybook-static/
No test runner or linter is configured.
The codebase is split into two layers:
src/core/— Environment-agnostic data processing (no React, no DOM). Types, event filtering, event expansion, content utilities.src/react/— React DOM rendering layer. Components, theming, context, styles.
src/index.ts— Main entry. Exports the React component, all types, and processing utilities. Imports CSS.src/headless.ts— Headless entry (./headless). Exports onlycore/types and functions. No React or DOM dependency.
Raw TranscriptEvent[] flows through three stages:
- Filter (
core/filter-events.ts) — Removes internal event types (system, summary, progress, file-history-snapshot) - Expand (
core/expand-events.ts) — Transforms events intoDisplayBlock[]with grouping logic:- Pairs
tool_usewith correspondingtool_resultintotool_groupblocks - Groups
Skilltool invocations with their output intoskill_groupblocks - Groups local
/commandinvocations with output and summary intolocal_command_groupblocks - Extracts display-friendly labels and parameters from tool payloads
- Pairs
- Render (react/) — Renders DisplayBlocks via registry-based renderers
ClaudeCodeTranscript.tsx— Top-level component. Sets upTranscriptProvidercontext with theme, classNames, and callbacks.context.ts—TranscriptContextprovides codeTheme, classNames, customBlockRenderers, and permalink/clipboard callbacks to all descendants. Eliminates prop drilling.components/ContentBlockCard.tsx— Layout and collapse behavior. Delegates content rendering to the renderer registry.components/renderers/index.tsx— Registry that mapsblockType→ renderer component. Custom renderers (by tool name or blockType) are checked first.components/renderers/*.tsx— Individual renderers: TextRenderer, ThinkingRenderer, ToolGroupRenderer, SkillGroupRenderer, LocalCommandRenderer, TodoRenderer, AskUserQuestionRenderer, ToolUseRenderer, FallbackRenderer.components/CodeBlock.tsx— Shared SyntaxHighlighter wrapper. Gets theme from context.components/MarkdownContent.tsx— Shared Markdown renderer. Gets code theme from context.components/block-styles.ts— Container styles, icon selection, prose class constants.components/block-classification.ts— Block type classification (isSecondaryBlock, shouldExpandByDefault).
core/に置くもの: React や DOM に依存しないコード。型定義、データ変換ロジック、文字列操作ユーティリティなど。import Reactや JSX を含んではいけない。react/に置くもの: React コンポーネント、hooks、React Context、CSS、Tailwind クラス文字列など。
依存方向: react/ → core/ は OK。core/ → react/ は禁止。core/ 内のファイルは react/ の存在を知らない。
| 置き場所 | 何を置くか |
|---|---|
react/types.ts |
React に依存する型 (React.CSSProperties を使う型など) |
react/context.ts |
TranscriptContext の定義。新しいコンテキスト値を追加する場合はここ |
react/ClaudeCodeTranscript.tsx |
公開 props の定義、Provider のセットアップ |
react/components/block-classification.ts |
blockType の分類判定 (pure 関数、React 不要) |
react/components/block-styles.ts |
Tailwind クラス文字列定数、アイコン選択、コンテナスタイル |
react/components/*.tsx |
複数のレンダラーから共有されるコンポーネント (CodeBlock, MarkdownContent 等) |
react/components/renderers/*.tsx |
特定 blockType のレンダリングロジック。そのブロック固有のデータ抽出ヘルパーもここ |
core/expand-events.tsで新しい blockType を持つDisplayBlockを生成するロジックを追加react/components/renderers/にXxxRenderer.tsxを作成react/components/renderers/index.tsxのDEFAULT_RENDERERSに登録- (必要なら)
block-classification.tsのSECONDARY_BLOCK_TYPESに追加
react/styles.cssの light テーマ・dark テーマ両方に--cct-xxxを追加- コンポーネントでは
cct-text-[var(--cct-xxx)]のように Tailwind の arbitrary value で参照
新しい設定値をレンダラーに渡す場合:
react/context.tsのTranscriptContextValueにフィールドを追加react/ClaudeCodeTranscript.tsxの props とcontextValueの組み立てに追加- レンダラーでは
useTranscriptContext()で取得
- Config:
.storybook/main.ts(React + Vite framework),.storybook/preview.ts(CSS import, backgrounds) - Stories:
src/stories/ClaudeCodeTranscript.stories.tsx— FullConversation, WithThinking, WithToolGroup, WithTodoList, WithAskUserQuestion, WithSkillGroup, WithLocalCommand, WithCustomRenderer, Empty - Fixtures:
src/stories/fixtures/sample-events.ts— SampleTranscriptEvent[]data covering all renderer types - Deployment:
.github/workflows/deploy-storybook.yml— GitHub Actions workflow deploys to GitHub Pages on push to main. Requires repository Settings → Pages → Source を "GitHub Actions" に設定する。
- Tailwind prefix
cct-: All Tailwind classes use this prefix to avoid conflicts when the component is embedded in host applications. Preflight is disabled for the same reason. Thecn()utility inreact/cn.tshandles merging with this prefix. - CSS custom properties: All colors use
--cct-*variables defined inreact/styles.css, with light/dark theme variants via[data-cct-theme]attribute. - Scoped box-sizing reset:
styles.cssに[data-cct-root] * { box-sizing: border-box; }を定義している。Preflight が無効なため、ブラウザデフォルトのcontent-boxだとwidth: 100%+paddingで親要素をはみ出す問題が発生する。このスコープ付きリセットでホストアプリに影響を与えずに解決している。 - Button element resets: Preflight 無効のため
<button>にブラウザデフォルトの背景・ボーダーが残る。ボタン要素にはcct-appearance-none cct-border-0 cct-bg-transparentを明示的に付与すること。 - TranscriptContext: Theme settings (codeTheme, classNames, customBlockRenderers) are provided via React Context to avoid prop drilling through renderers.
- Renderer registry: blockType → component mapping in
renderers/index.tsx. Adding a new block type = new renderer file + one line in the registry. - Custom block renderers: Consumers can override rendering for specific tools or block types via
customBlockRenderersprop. - Environment-agnostic permalink/clipboard:
generatePermalinkandcopyToClipboardprops allow non-browser environments to provide custom implementations. - Path display: Tool labels show paths relative to
projectPathprop when provided, with smart shortening logic.
Exports: ClaudeCodeTranscript component, processing utilities (filterHiddenEvents, expandEvents, extractMessageBlocks), and all relevant types.
Exports: processing utilities and types only. No React dependency. Useful for React Native, Node.js scripts, or custom renderers.
npm パッケージのリリースは GitHub Release をトリガーに GitHub Actions (OIDC Trusted Publishing) で自動実行される。
package.jsonのversionを更新してコミット・マージ- GitHub で Release を作成:
- Tag:
v<version>(例:v0.2.0)を新規作成 - Title:
v<version> - "Generate release notes" で変更内容を自動生成
- Tag:
- Release を publish すると
.github/workflows/release.ymlがnpm publish --provenance --access publicを実行