Claude Skills Guide

Claude Code for Weights & Biases Workflow Guide

Integrating Claude Code with Weights & Biases (W&B) transforms your machine learning development workflow by combining powerful experiment tracking with intelligent code assistance. This guide shows you how to set up, configure, and optimize this integration for productive ML experimentation.

Understanding the Weights & Biases Integration

Weights & Biases is a platform for tracking machine learning experiments, visualizing results, and managing model versions. When combined with Claude Code, you get an AI-powered assistant that understands your experiment history, suggests hyperparameter improvements, and helps you navigate complex training workflows.

The integration works through W&B’s Python API, which Claude Code can invoke to read experiment data, log metrics, and manage runs. This creates a seamless workflow where Claude understands context from your past experiments and helps make data-driven decisions.

Setting Up Your Environment

Before integrating Claude Code with W&B, ensure you have the required packages installed:

pip install wandb openai

Configure your W&B account by running:

wandb login

This authenticates your sessions and links all experiments to your W&B project. For Claude Code integration, you’ll want to set environment variables for seamless authentication:

export WANDB_API_KEY=your_api_key_here

Creating a Claude Skill for W&B Workflows

A dedicated Claude skill for Weights & Biases streamlines common ML workflow tasks. Here’s a skill that provides experiment tracking capabilities:

---
name: wandb-workflow
description: "Assist with Weights & Biases experiment tracking and ML workflows"
---

# Weights & Biases Workflow Assistant

You help users with:
- Starting and managing W&B runs
- Logging metrics, parameters, and artifacts
- Querying experiment history
- Comparing runs and analyzing results
- Creating visualizations and reports

## Starting a New Run

When the user wants to start training:
1. First read their training script to understand the structure
2. Suggest appropriate W&B initialization if not present
3. Help add logging statements for key metrics

## Analyzing Experiments

To compare experiments:
1. Use `wandb api` or the Python API to fetch run data
2. Present comparisons in clear tables
3. Identify patterns in successful experiments

Practical Example: Training with W&B Integration

Here’s a complete example showing how Claude Code assists with a W&B-integrated training workflow:

import wandb
import torch
import torch.nn as nn

# Initialize W&B run
wandb.init(
    project="image-classification",
    config={
        "learning_rate": 0.001,
        "batch_size": 32,
        "epochs": 10,
        "optimizer": "adam"
    }
)

# Simple CNN model
class SimpleCNN(nn.Module):
    def __init__(self):
        super().__init__()
        self.conv1 = nn.Conv2d(3, 16, 3, padding=1)
        self.conv2 = nn.Conv2d(16, 32, 3, padding=1)
        self.fc = nn.Linear(32 * 8 * 8, 10)
    
    def forward(self, x):
        x = torch.relu(self.conv1(x))
        x = torch.max_pool2d(x, 2)
        x = torch.relu(self.conv2(x))
        x = torch.max_pool2d(x, 2)
        x = x.view(-1, 32 * 8 * 8)
        return self.fc(x)

model = SimpleCNN()
optimizer = torch.optim.Adam(model.parameters(), lr=wandb.config.learning_rate)

# Training loop with W&B logging
for epoch in range(wandb.config.epochs):
    for batch in train_loader:
        optimizer.zero_grad()
        outputs = model(batch['image'])
        loss = nn.CrossEntropyLoss()(outputs, batch['label'])
        loss.backward()
        optimizer.step()
        
        # Log training metrics
        wandb.log({
            "train_loss": loss.item(),
            "epoch": epoch
        })
    
    # Log epoch-level metrics
    accuracy = evaluate(model, val_loader)
    wandb.log({
        "val_accuracy": accuracy,
        "epoch": epoch
    })

# Log model as artifact
wandb.log_artifact(model.state_dict(), name="final-model", type="model")
wandb.finish()

Querying Experiment History with Claude

Claude Code can help you analyze past experiments by querying W&B’s API. Here’s how to fetch and analyze runs:

import wandb

# Fetch all runs from a project
api = wandb.Api()
runs = api.runs("your-username/image-classification")

# Find best performing runs
best_runs = sorted(
    [r for r in runs if r.state == "finished"],
    key=lambda r: r.summary.get("val_accuracy", 0),
    reverse=True
)[:5]

# Display results
for run in best_runs:
    print(f"Run: {run.name}")
    print(f"  Accuracy: {run.summary.get('val_accuracy'):.4f}")
    print(f"  Learning Rate: {run.config.get('learning_rate')}")
    print(f"  Batch Size: {run.config.get('batch_size')}")

Best Practices for W&B + Claude Code Workflows

When integrating Claude Code with Weights & Biases, follow these practices for maximum productivity:

1. Use Structured Configurations

Store all hyperparameters in W&B config rather than hardcoding values. This makes it easy for Claude to understand your experimental setup and suggest improvements.

2. Log Meaningful Metrics

Track both training and validation metrics at appropriate intervals. Claude can better assist with debugging when it has access to comprehensive metric history.

3. Use Artifacts for Model versioning

Store model checkpoints and datasets as W&B artifacts. This enables reproducibility and makes it simple to retrieve previous models for comparison or fine-tuning.

4. Document Experiments

Add notes and tags to your W&B runs. Claude uses this context to provide more relevant suggestions based on your experimental history.

Advanced: Custom W&B Skills for Specific Use Cases

You can create specialized Claude skills for particular ML domains. For example, a skill focused on hyperparameter tuning:

---
name: hyperparameter-tuning
description: "Assist with ML hyperparameter optimization using W&B"
---

# Hyperparameter Tuning Assistant

Help users optimize their ML experiments using W&B Sweeps:

1. Analyze current hyperparameters and suggest ranges
2. Set up W&B Sweeps for automated tuning
3. Monitor sweep progress and identify promising configurations
4. Analyze sweep results and recommend optimal settings

When user mentions "tune" or "optimize":
- Read their training script
- Suggest appropriate search strategy (grid, random, bayesian)
- Help configure the sweep YAML
- Explain how to interpret results

You can also configure a sweep directly with a YAML file and run it from Claude Code:

program: train.py
method: bayes
metric:
  name: validation_loss
  goal: minimize
parameters:
  learning_rate:
    distribution: log_uniform
    min: 0.0001
    max: 0.1
  batch_size:
    values: [32, 64, 128]

Run the sweep controller from your terminal within Claude Code, then monitor results in the W&B dashboard while Claude assists with code modifications between runs.

Integrating Claude Skills with Your W&B Workflow

Several Claude skills enhance W&B workflows beyond the core W&B skill itself.

The tdd skill helps you write tests for training pipelines before implementation. When building model training code, invoke it and describe your training logic. Claude applies test-driven development principles, generating test cases for data loading, model forward passes, and metric calculations. This approach catches bugs before they affect your experiment runs:

/tdd

The pdf skill becomes useful when generating reports from W&B data. After completing experiments, use it to create documentation summarizing run results, comparison charts, or hyperparameter tables:

/pdf

The supermemory skill complements W&B by tracking context across sessions. When working on long ML projects, invoke it to maintain notes about experiment configurations, key findings, and model decisions:

/supermemory

This creates a persistent knowledge base that connects your Claude sessions with your W&B experiment history. The docx skill helps when documenting workflows for team distribution, generating status reports that reference specific W&B run IDs.

Project Structure for Claude Code and W&B

Organize your ML projects to use both tools effectively:

When starting a new ML project in Claude Code, create a wandb.env file containing your API key (add it to .gitignore) and source it in your shell:

source wandb.env

Conclusion

Integrating Claude Code with Weights & Biases creates a powerful development environment for machine learning. Claude understands your experiment history, helps you log relevant metrics, and assists with analyzing results. This combination enables data-driven decision-making while maintaining the productivity benefits of AI-assisted coding.

Start by setting up basic W&B logging in your training scripts, then progressively adopt more advanced features like sweeps and artifacts as your workflow matures. With Claude Code as your assistant, you’ll make better use of your experiment data and accelerate your ML development cycle.

The key is to establish good logging practices early and use Claude’s understanding of your project context. This creates a virtuous cycle where each experiment becomes more informative than the last.

Built by theluckystrike — More at zovo.one