xiaohongshu
xiaohongshu
claude-mobile-cost-tracking
Use when implementing Claude API cost tracking, monitoring token usage, displaying cost metrics in Settings, or user asks about costs - calculates exact costs using $0.003/1k input and $0.015/1k output pricing with per-session aggregation
Full skill instructions
Track and report Claude API usage costs per session with exact pricing, aggregation, and frontend display.
Core principle: Track every call. Use exact pricing. Display to users. Provide /cost command.
Announce at start: "I'm using the claude-mobile-cost-tracking skill for cost tracking implementation."
const PRICING = {
input: 0.003, // $0.003 per 1k input tokens
output: 0.015, // $0.015 per 1k output tokens
};
Source: Anthropic API pricing (verified 2025-10-30)
interface MessageCost {
inputTokens: number;
outputTokens: number;
inputCost: number;
outputCost: number;
totalCost: number;
timestamp: string;
}
function calculateCost(usage: {
input_tokens: number;
output_tokens: number;
}): MessageCost {
const inputCost = (usage.input_tokens / 1000) * PRICING.input;
const outputCost = (usage.output_tokens / 1000) * PRICING.output;
return {
inputTokens: usage.input_tokens,
outputTokens: usage.output_tokens,
inputCost,
outputCost,
totalCost: inputCost + outputCost,
timestamp: new Date().toISOString()
};
}
interface SessionCosts {
sessionId: string;
messages: MessageCost[];
totalInputTokens: number;
totalOutputTokens: number;
totalCost: number;
}
function aggregateSessionCosts(messages: MessageCost[]): SessionCosts {
return {
messages,
totalInputTokens: messages.reduce((sum, m) => sum + m.inputTokens, 0),
totalOutputTokens: messages.reduce((sum, m) => sum + m.outputTokens, 0),
totalCost: messages.reduce((sum, m) => sum + m.totalCost, 0)
};
}
// In session JSON file
interface Session {
id: string;
projectPath: string;
messages: Message[];
costs: SessionCosts; // Add this
createdAt: string;
}
// Settings screen cost section
<View testID="cost-section" style={styles.costSection}>
<Text style={styles.sectionTitle}>API Usage</Text>
<Text testID="message-count">Messages: {session.messages.length}</Text>
<Text testID="input-tokens">Input Tokens: {costs.totalInputTokens.toLocaleString()}</Text>
<Text testID="output-tokens">Output Tokens: {costs.totalOutputTokens.toLocaleString()}</Text>
<Text testID="total-cost" style={styles.cost}>
Total Cost: ${costs.totalCost.toFixed(4)}
</Text>
</View>
// In command.service.ts
if (message.startsWith('/cost')) {
const sessionCosts = getSessionCosts(sessionId);
return {
type: 'slash_command_response',
command: 'cost',
data: sessionCosts
};
}
// cost.service.ts
export class CostService {
calculateMessageCost(usage: {input_tokens: number; output_tokens: number}): MessageCost {
// Implementation from pattern #1
}
aggregateSessionCosts(sessionId: string): SessionCosts {
// Implementation from pattern #2
}
getAllSessionsCosts(): SessionCosts[] {
// Return costs for all sessions
}
exportCostsCSV(): string {
// Export as CSV for analysis
}
}
| Mistake | Reality |
|---|---|
| "Cost tracking is optional" | WRONG. Users need visibility. Required feature. |
| "Approximate costs are fine" | WRONG. Use exact: $0.003/$0.015 per 1k. |
| "Track totals only" | WRONG. Per-session tracking enables analysis. |
| "Backend only is enough" | WRONG. Frontend display is user-facing requirement. |
const stream = await client.messages.stream({...});
// No cost tracking
const stream = await client.messages.stream({...});
stream.on('message', (msg) => {
if (msg.usage) {
const cost = calculateCost(msg.usage);
saveSessionCost(sessionId, cost);
}
});
@anthropic-streaming-patterns (streams provide usage data)xiaohongshu
technical spec
product ux expert
database patterns
Conduct multi-agent task orchestration and workflow coordination.
Initialize project with Conductor artifacts (product definition,
Expert in web animations, transitions, and motion design using Framer Motion and CSS
Creates Mermaid and ASCII diagrams for flowcharts, architecture, ERDs, state machines, mindmaps, and more. Use when user mentions diagram, flowchart, mermaid, ASCII diagram, text diagram, terminal diagram, visualize, C4, mindmap, architecture diagram, sequence diagram, ERD, or needs visual docume...
PostgreSQL bindings for H3 hexagonal grid system. Use when working with H3 cells in Postgres, including spatial indexing, geometry/geography integration, and raster analysis.
Context-Driven Development skill for projects using Conductor. Use this skill when you detect a `conductor/` directory in the project, when working on tasks defined in a `plan.md` file, or when the user asks about tracks, specs, or plans. Automatically applies TDD workflow, tracks task completion...
Display project status, active tracks, and next actions
Official Stakpak application containerization standard operating procedure, a step-by-step guidline to properly dockerize applications. This is a rule book curated by the Stakpak Team.
Generate, edit, and beat-sync AI video with leading models in one workspace.
The world's fastest calendar for remote work
Transform Your Design with AI Designer by ImgCreator.ai
Revolutionizing Video Production with AI-Powered Creativity
Extend an image past the frame and let AI fill the new aspect ratio.
Discover your celebrity doppelgänger with StarByFace!
ChainClarity explains 700+ crypto whitepapers in plain English, with layered summaries, comparisons, research tools, alerts, and a $4.99 Pro plan.
Opus.ai: Revolutionize Your Web Experience