This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
This is a Yarn workspaces monorepo using Turbo for task orchestration. It contains:
/docs- Docusaurus documentation site for Primer's Beta SDK Components/examples- Multiple standalone integration examples demonstrating@primer-io/primer-jsSDK usage- Root workspace - Shared tooling (Prettier, Turbo, git hooks) and monorepo coordination
Note: The /docs directory has its own CLAUDE.md with detailed documentation-specific guidelines. When working on documentation, refer to /docs/CLAUDE.md.
yarn dev- Start all development servers (docs + examples) in parallelyarn lint:es- Run ESLint across all workspacesyarn lint:ts- Run TypeScript type checking across all workspacesyarn format- Format all files with Prettier (auto-fix)yarn lint:format- Check Prettier formatting without fixing
Navigate to the specific workspace directory and run:
cd docs && yarn dev- Start docs site on port 9000cd examples/primer-checkout-basic && yarn dev- Start specific example
Pre-commit hook runs lint-staged which formats staged files with Prettier automatically.
Turbo manages task dependencies via turbo.json:
buildtasks depend on dependencies being built first (^build)devtasks run persistently without cachinglintandcheck-typesdepend ontransittasks
Workspaces are defined in root package.json:
packages/*- Shared utilities (currently empty)docs- Documentation site workspaceexamples/*- Each example is an independent workspace
Nohoist configuration prevents hoisting of React, TypeScript, and related packages to ensure version consistency per workspace.
Each example in /examples is a standalone demonstration:
- Build Tool: Vite with TypeScript
- SDK Version:
@primer-io/primer-js0.3.3 - Entry Point:
index.html→src/main.ts - Client Token Utility: Most examples include
fetchClientToken.tshelper - Standard Commands:
yarn dev,yarn build,yarn preview
-
Basic Examples (
primer-checkout-basic)- Vanilla TypeScript + Vite
- Minimal dependencies
- Focus on SDK fundamentals
-
React Examples (
primer-checkout-custom-layout,primer-checkout-custom-form)- React 19 + Vite + TypeScript
- Include ESLint configuration
- Demonstrate component integration patterns
- Commands:
yarn dev,yarn build,yarn lint,yarn check-types
-
Theme/Customization Examples (
primer-checkout-themes,primer-checkout-vaulted)- Show styling and theming capabilities
- Demonstrate advanced SDK features
When creating or modifying examples:
- Follow the existing structure pattern (Vite + TypeScript)
- Include README.md with setup instructions
- Use
@primer-io/primer-jsSDK for payment integrations - Ensure examples are self-contained and runnable
- Test with
yarn devbefore committing
- Use TypeScript for all code (examples and docs components)
- Strict mode enabled in most workspaces
- Define explicit types for Props and function returns
- 2-space indentation (enforced by Prettier)
- Single quotes for strings (except JSX attributes)
- Trailing commas in multi-line structures
- Pre-commit hook auto-formats staged files
- Functional components with arrow functions
- Named exports preferred
- Import order: React → third-party → local
- PascalCase for components, camelCase for functions/variables
- Install dependencies:
yarn install(run at root) - Start everything:
yarn dev(starts all workspaces) - Or start specific workspace:
cd docs && yarn dev
- Type checking:
yarn lint:ts(root) oryarn check-types(workspace) - Linting:
yarn lint:es(root) oryarn lint(workspace with ESLint) - Format checking:
yarn lint:format - Build verification: Navigate to workspace and run
yarn build
- Create new directory in
/examples - Set up Vite + TypeScript with standard structure
- Add workspace to root
package.json(auto-detected via glob) - Include README.md with setup instructions
- Use consistent commands:
dev,build,preview
The @primer-io/primer-js SDK requires:
- Client token from Primer API (obtain via backend)
- Modern browser (ES2020+ features)
- Checkout session for payment flows
- Event handlers for payment lifecycle
The Primer SDK uses web components, NOT class constructors. When writing documentation or examples:
❌ WRONG - DO NOT USE THIS PATTERN:
// This is INCORRECT and should NEVER appear in docs or examples
import { PrimerCheckout } from '@primer-io/primer-js';
const checkout = new PrimerCheckout({ clientToken: 'token', ...options });✅ CORRECT - ALWAYS USE THIS PATTERN:
// This is the CORRECT web component pattern
const checkout = document.querySelector('primer-checkout');
checkout.setAttribute('client-token', 'your-client-token');
checkout.options = {
// SDK options here (locale, enabledPaymentMethods, etc.)
};Key points:
- There is NO
PrimerCheckoutclass to import client-tokenis set viasetAttribute()(it's a component property)- SDK options are set via the
optionsproperty (NOT in a constructor) - Do NOT mix component properties with SDK options
This pattern must be consistent across ALL documentation, examples, and code snippets.
- Runs on port 9000 in development
- Uses MDX for interactive documentation
- Supports Mermaid.js diagrams
- Includes custom search via
@easyops-cn/docusaurus-search-local
- Clear Turbo cache:
rm -rf .turbo - Clear Docusaurus cache:
cd docs && yarn clear - Reinstall dependencies:
rm -rf node_modules && yarn install
- Ensure workspace has TypeScript installed locally
- Check
nohoistconfiguration if React types are missing - Run
yarn installafter adding new dependencies
- Check port availability (docs uses 9000, examples use 5173 by default)
- Clear Vite cache: Delete
node_modules/.vitein affected workspace - Restart dev server with clean cache