better-auth-add-plugin
Add a better-auth plugin to an existing project. Configures server and client plugins with proper imports.
Interactive Durable Objects performance optimization assistant. Analyzes existing DO code and provides specific optimization recommendations with implementation guidance.
$ npx -y skills add secondsky/claude-skills --agent claude-codeHow it fires
How this command gets triggered: by you, by Claude, or both.
/do-optimizeContext preview
What this command does when you run it.
Interactive Durable Objects performance optimization assistant. Analyzes existing DO code and provides specific optimization recommendations with implementation guidance.
name: cloudflare-durable-objects:optimize description: Interactive Durable Objects performance optimization assistant. Analyzes existing DO code and provides specific optimization recommendations with implementation guidance.
Interactive assistant that analyzes your Durable Objects code and provides targeted performance optimizations.
This command: 1. Analyzes existing DO implementations 2. Identifies performance bottlenecks 3. Provides specific optimization recommendations 4. Generates optimized code 5. Measures potential performance improvements
Use AskUserQuestion tool:
**header**: "Issue Type" **question**: "What performance issue are you experiencing?" **multiSelect**: false **options**:
description: "DO takes too long to start up or respond to first request"
description: "SQL queries are taking too long"
description: "DO is using too much memory or hitting limits"
description: "WebSocket messages have high latency or dropped connections"
description: "Alarms are slow, failing, or not executing"
description: "Want to improve overall performance"
**header**: "Scale" **question**: "What is your current scale?" **multiSelect**: false **options**:
description: "Local testing, small dataset"
description: "Early production, limited users"
description: "Growing user base"
description: "High traffic, many active instances"
**header**: "Priority" **question**: "What is most important to optimize?" **multiSelect**: false **options**:
description: "Reduce time to first response"
description: "Handle more concurrent requests"
description: "Reduce CPU time and costs"
description: "Reduce memory usage"
Read and analyze DO class files:
Check for common anti-patterns:
❌ **Bad Pattern**: Expensive operations in constructor
constructor(ctx: DurableObjectState, env: Env) {
super(ctx, env);
this.ctx.blockConcurrencyWhile(async () => {
// ❌ Multiple slow operations block all requests
this.config = await this.loadConfigFromAPI();
this.cache = await this.buildLargeCache();
this.data = await this.loadAllData();
});
}✅ **Optimized Pattern**: Minimal constructor, lazy initialization
constructor(ctx: DurableObjectState, env: Env) {
super(ctx, env);
// ✅ Only initialize synchronously
this.config = null;
this.cache = new Map();
this.initialized = false;
}
private async ensureInitialized() {
if (!this.initialized) {
// ✅ Load on demand, only once
this.config = await this.loadConfig();
this.initialized = true;
}
}
async handleRequest(request: Request) {
await this.ensureInitialized();
// Process request...
}Check for inefficient queries:
❌ **Bad Pattern**: Missing indexes, N+1 queries
// ❌ No index on user_id - full table scan
const messages = await this.ctx.storage.sql.exec(
'SELECT * FROM messages WHERE user_id = ?',
userId
);
// ❌ N+1 query pattern
for (const message of messages.rows) {
const user = await this.ctx.storage.sql.exec(
'SELECT * FROM users WHERE id = ?',
message.user_id
);
}✅ **Optimized Pattern**: Proper indexes, batch queries
// ✅ Create index for common queries
await this.ctx.storage.sql.exec(`
CREATE INDEX IF NOT EXISTS idx_user_messages
ON messages(user_id, created_at DESC)
`);
// ✅ Single query with JOIN
const result = await this.ctx.storage.sql.exec(`
SELECT
m.*,
u.username,
u.avatar
FROM messages m
JOIN users u ON m.user_id = u.id
WHERE m.user_id = ?
ORDER BY m.created_at DESC
LIMIT 50
`, userId);Check for hibernation blockers:
❌ **Bad Pattern**: Synchronous processing, setTimeout usage
async webSocketMessage(ws: WebSocket, message: string) {
// ❌ Blocks hibernation with heavy processing
const result = await this.heavyProcessing(message);
await this.saveToDatabase(result);
ws.send(JSON.stringify(result));
}
// ❌ setTimeout prevents hibernation
setTimeout(() => {
this.cleanup();
}, 60000);✅ **Optimized Pattern**: Fast wake, async processing, alarms
async webSocketMessage(ws: WebSocket, message: string) {
// ✅ Minimal processing, queue for async
this.messageQueue.push({ ws, message });
// ✅ Process asynchronously, doesn't block hibernation
this.ctx.waitUntil(this.processQueue());
}
private async processQueue() {
while (this.messageQueue.length > 0) {
const { ws, message } = this.messageQueue.shift()!;
const result = await this.heavyProcessing(message);
await this.saveToDatabase(result);
ws.send(JSON.stringify(result));
}
}
// ✅ Use alarms instead of setTimeout
async alarm() {
await this.cleanup();
await this.ctx.storage.setAlarm(Date.now() + 60000);
}Check for memory leaks:
❌ **Bad Pattern**: Unbounded growth, large in-memory cache
class MyDO extends DurableObject {
// ❌ Grows unbounded
private allMessages: any[] = [];
private userCache: Map<string, any> = new Map();
async addMessage(message: any) {
this.allMessages.push(message); // ❌ Never cleaned up
this.userCache.set(message.userId, message.user); // ❌ Unbounded145 production-ready skills for Claude Code CLI 🔌 Platform / Harness Support These plugins ship as Claude Code marketplace plugins (.claude-plugin/ manifests) and Codex CLI plugins (.codex-plugin/ manifests).
Repo: secondsky/claude-skills
Add a better-auth plugin to an existing project. Configures server and client plugins with proper imports.
Interactive setup wizard for better-auth authentication. Guides through database, framework, OAuth providers, and plugin configuration.
Explain Better Auth error codes and provide solutions with code examples
Display Better Auth available authentication providers and their configuration