/rudder-core:rudder-code-first-instrumentationfrom rudder-core
Derives tracking plans from existing codebase types and structures. Use when instrumenting an existing product that wasn't well-instrumented or restructuring existing tracking.
Ships in rudder-core. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
This skill guides instrumentation planning for existing products where you derive tracking plans from the codebase's existing types and structures.
| Scenario | Use This Skill? |
|---|---|
| Existing product needs instrumentation | Yes |
| Codebase has domain types (enums, interfaces) you want to track | Yes |
| Restructuring messy existing tracking | Yes |
| Building new feature, events not yet defined | No — use rudder-design-first-instrumentation |
| LLM chat, AI agent or MCP server usage | No — use rudder-ai-events-setup (standard AI events via the AI SDKs) |
When a product already exists, the code contains valuable type information:
Deriving tracking plans from code types:
"If I say plan, that cannot mean many things. It's the plan. I have to be specific."
┌─────────────────────────────────────────────────────────────────────┐
│ CODE-FIRST INSTRUMENTATION │
└─────────────────────────────────────────────────────────────────────┘
│
▼
┌─────────────────┐
│ 1. DISCOVER │ ← Identify domain types in codebase
│ CODE TYPES │
└────────┬────────┘
▼
┌─────────────────┐
│ 2. MAP TYPES │ ← Translate code types to tracking plan types
│ TO YAML │
└────────┬────────┘
▼
┌─────────────────┐
│ 3. IDENTIFY │ ← What user actions should be tracked?
│ EVENTS │
└────────┬────────┘
▼
┌─────────────────┐
│ 4. BUILD │ ← Create YAML referencing the types
│ TRACKING │
│ PLAN │
└────────┬────────┘
▼
┌─────────────────┐
│ 5. VERIFY │ ← TypeScript compilation validates alignment
└────────┬────────┘
▼
┌─────────────────┐
│ 6. TEST & APPLY │ ← Verify in dev workspace, apply to prod
└─────────────────┘
Scan the codebase for domain types that should flow through to analytics.
| Type Category | Examples | Tracking Plan Equivalent |
|---|---|---|
| Enums | BillingPlan, UserRole, Region | Property with enum config |
| String unions | type Status = 'active' | 'inactive' | Property with enum config |
| Interfaces | Product, Workspace, User | Custom type |
| Constants | PLAN_TYPES, REGIONS | Property enum values |
# Find enums in TypeScript codebase
grep -r "enum " --include="*.ts" --include="*.tsx" src/
# Find type unions
grep -r "type.*=" --include="*.ts" src/ | grep "|"
# Find interfaces that might be tracked
grep -r "interface.*{" --include="*.ts" src/types/
// Found in src/types/workspace.ts
enum BillingPlan {
FREE = 'free',
STARTER = 'starter',
GROWTH = 'growth',
ENTERPRISE = 'enterprise',
}
enum Region {
US = 'us',
EU = 'eu',
}
// Found in src/types/transformation.ts
type TransformationLanguage = 'javascript' | 'python';
// Found in src/types/audience.ts
enum ConditionGroupType {
AND = 'and',
OR = 'or',
AUDIENCE = 'audience',
}
Translate discovered code types to tracking plan YAML.
// Code
enum BillingPlan {
FREE = 'free',
STARTER = 'starter',
GROWTH = 'growth',
ENTERPRISE = 'enterprise',
}
# Tracking plan property
version: "rudder/v1"
kind: "property"
metadata:
name: "properties"
spec:
name: "billing_plan"
type: "string"
description: "Organization billing plan"
config:
enum:
- "free" # Exact match to BillingPlan.FREE
- "starter" # Exact match to BillingPlan.STARTER
- "growth" # Exact match to BillingPlan.GROWTH
- "enterprise" # Exact match to BillingPlan.ENTERPRISE
// Code
type TransformationLanguage = 'javascript' | 'python';
# Tracking plan property
version: "rudder/v1"
kind: "property"
metadata:
name: "properties"
spec:
name: "transformation_language"
type: "string"
description: "Programming language of transformation"
config:
enum:
- "javascript"
- "python"
// Code
interface Product {
id: string;
name: string;
price: number;
category: ProductCategory;
}
# Tracking plan custom type
version: "rudder/v1"
kind: "custom-type"
metadata:
name: "custom-types"
spec:
name: "ProductType"
type: "object"
description: "Product information from catalog"
config:
properties:
- property: "urn:rudder:property/product_id"
required: true
- property: "urn:rudder:property/product_name"
required: true
- property: "urn:rudder:property/product_price"
required: true
- property: "urn:rudder:property/product_category"
required: true
The tracking plan must use the exact string values from the code:
// If code uses lowercase
enum Region {
US = 'us', // lowercase
EU = 'eu',
}
// YAML must match
config:
enum:
- "us" # NOT "US"
- "eu" # NOT "EU"
With types mapped, identify what user actions to track.
Look for:
# Find action handlers
grep -r "async function create" --include="*.ts" src/
grep -r "handleSubmit" --include="*.tsx" src/
# Find API endpoints that modify state
grep -r "router.post\|router.put\|router.delete" --include="*.ts" src/
| Code Pattern | Event Name |
|---|---|
createTransformation() | Transformation Created |
updateAudience() | Audience Updated |
deleteSource() | Source Deleted |
onSubmit in CreateAudienceForm | Audience Creation Started |
Create YAML definitions that reference the mapped types.
1. Properties ← From code enums/unions
2. Custom Types ← From code interfaces
3. Categories ← Group by feature
4. Events ← Reference properties and custom types
5. Tracking Plan ← Bundle for source
# properties/transformation-properties.yaml
version: "rudder/v1"
kind: "property"
metadata:
name: "properties"
spec:
name: "transformation_id"
type: "string"
description: "Unique transformation identifier"
config:
minLength: 1
---
version: "rudder/v1"
kind: "property"
metadata:
name: "properties"
spec:
name: "transformation_language"
type: "string"
description: "Programming language"
config:
enum:
- "javascript"
- "python"
---
# events/transformations.yaml
version: "rudder/v1"
kind: "event"
metadata:
name: "events"
spec:
name: "Transformation Created"
description: "User created a new transformation"
category: "urn:rudder:category/transformations"
rules:
- property: "urn:rudder:property/transformation_id"
required: true
- property: "urn:rudder:property/transformation_language"
required: true
- property: "urn:rudder:property/template_type"
Use TypeScript compilation to verify tracking plan aligns with code.
If using RudderTyper (Swift/Kotlin), it generates type-safe code. For TypeScript, manually create matching types:
// analytics/types.ts (derived from tracking plan)
export type BillingPlan = 'free' | 'starter' | 'growth' | 'enterprise';
export type TransformationLanguage = 'javascript' | 'python';
export type ConditionGroupType = 'and' | 'or' | 'audience';
export interface TransformationCreatedEvent {
transformation_id: string;
transformation_language: TransformationLanguage;
template_type?: string;
}
// This should compile without errors
import { BillingPlan } from './analytics/types';
import { BillingPlan as CodeBillingPlan } from './types/workspace';
// Type assertion - compiler validates they're compatible
const plan: BillingPlan = CodeBillingPlan.GROWTH;
// If tracking plan has 'growth' but code has 'GROWTH'
const plan: BillingPlan = CodeBillingPlan.GROWTH;
// ❌ Type '"GROWTH"' is not assignable to type 'BillingPlan'
"TypeScript for LLMs is the greatest teacher. It puts it in guardrails."
# Apply to dev workspace first. apply writes to the workspace of the
# CLI's token, so check that workspaceID is the dev workspace
rudder-cli workspace info --json
rudder-cli apply -l ./
# Trigger events in dev
# Verify via MCP or live events
# Check live events
Use tool: get_live_events
Filter by source, verify event payload
# Query warehouse
Use tool: sql_agent_query
Query: SELECT * FROM transformations WHERE event = 'Transformation Created' LIMIT 10
# After verification, switch the CLI to the prod workspace. An agent
# asks the user to export that workspace's RUDDERSTACK_ACCESS_TOKEN
# and restart it. Check that workspaceID is prod, then apply
rudder-cli workspace info --json
rudder-cli apply -l ./
For complete end-to-end examples, see:
references/real-world-examples.md - E-Commerce and Subscription Billing examplesIf existing tracking is inconsistent, use transformations for backward compatibility:
// transformation for migration
function transform(event) {
// Normalize old format to new
if (event.properties.workspaces_id) {
event.properties.workspace_id = event.properties.workspaces_id;
}
// Normalize enum case
if (event.properties.plan === 'GROWTH') {
event.properties.billing_plan = 'growth';
}
return event;
}
See rudder-transformations skill for migration patterns.
| Mistake | Problem | Fix |
|---|---|---|
| Enum values don't match code | Type errors, runtime mismatches | Copy exact values from code |
| Case mismatch (GROWTH vs growth) | Inconsistent warehouse data | Use code's exact casing |
| Missing optional properties | Over-constrained tracking | Check code for optional fields |
| Ignoring code changes | Tracking plan drifts | Update tracking plan when code types change |
This skill processes code from the user's codebase. When analyzing external code:
What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
11 skills in this plugin
/rudder-data-catalogCreates and manages events, properties, categories, and custom types for instrumentation schemas. Use when creating or managing events, properties, categories, or custom types for RudderStack instrumentation/rudder-data-graphsProduces Data Graph YAML from RETL sources for Audiences. Use when designing Data Graphs, mapping RETL to entities/events, or assessing customer fit for Audiences./rudder-design-first-instrumentationPlans instrumentation for new features starting from product requirements before code exists. Use when building new features and need to define events as part of product definition.npx claudepluginhub rudderlabs/rudder-agent-skills --plugin rudder-coreOther plugins' skills for the same job