claudify-agent 0.0.0-stage → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude/QUICK-REFERENCE.md +213 -0
- package/.claude/cost-dashboard.md +162 -0
- package/.claude/docs/COST-OPTIMIZATION.md +403 -0
- package/.claude/docs/MCP-INTEGRATION-GUIDE.md +348 -0
- package/.claude/docs/PLAN-MODE-OPTIMIZATION.md +836 -0
- package/.claude/hooks/auto-learning-review.ts +195 -0
- package/.claude/hooks/auto-lint-fix.ts +104 -0
- package/.claude/hooks/auto-security-review.ts +354 -0
- package/.claude/hooks/auto-validate.ts +348 -0
- package/.claude/hooks/plan-quality-tracker.ts +719 -0
- package/.claude/rules/anti-patterns.md +22 -0
- package/.claude/rules/context-tier-1.md +41 -0
- package/.claude/rules/context-tier-2.md +285 -0
- package/.claude/rules/general.md +25 -0
- package/.claude/rules/mcp-auto-use.md +46 -0
- package/.claude/rules/parallel-exploration-auto.md +31 -0
- package/.claude/rules/plan-mode-execution.md +289 -0
- package/.claude/rules/plan-mode-research.md +34 -0
- package/.claude/rules/plan-mode-structure.md +166 -0
- package/.claude/rules/plan-mode-validation.md +130 -0
- package/.claude/rules/security-critical.md +19 -0
- package/.claude/rules/tool-auto-selection.md +45 -0
- package/.claude/rules/tool-strategy.md +22 -0
- package/.claude/scripts/auto-validate.js +69 -0
- package/.claude/scripts/security-scan.js +45 -0
- package/.claude/security-dashboard.md +142 -0
- package/.claude/skills/backend-concurrency/SKILL.md +203 -0
- package/.claude/skills/debug-optimizer/SKILL.md +399 -0
- package/.claude/skills/debug-optimizer.md +12 -0
- package/.claude/skills/golang-guide/SKILL.md +177 -0
- package/.claude/skills/learning-loop/SKILL.md +308 -0
- package/.claude/skills/mcp-mastery/SKILL.md +214 -0
- package/.claude/skills/nestjs-guide/SKILL.md +197 -0
- package/.claude/skills/nextjs-guide/SKILL.md +687 -0
- package/.claude/skills/nextjs.md +13 -0
- package/.claude/skills/parallel-exploration/SKILL.md +193 -0
- package/.claude/skills/plan-mode-mastery/SKILL.md +263 -0
- package/.claude/skills/python-guide/SKILL.md +822 -0
- package/.claude/skills/react-guide/SKILL.md +762 -0
- package/.claude/skills/react.md +12 -0
- package/.claude/skills/security.md +18 -0
- package/.claude/skills/solidity-guide/SKILL.md +32 -0
- package/.claude/skills/tool-selection/SKILL.md +428 -0
- package/.claude/skills/vite-guide/SKILL.md +445 -0
- package/CLAUDE.md +49 -0
- package/README.md +65 -2
- package/bin/cli.js +50 -0
- package/package.json +44 -4
|
@@ -0,0 +1,403 @@
|
|
|
1
|
+
# Cost Optimization Guide
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
Track and optimize token consumption and execution costs for Cursor agent operations. This guide provides formulas, tracking methods, and optimization strategies.
|
|
5
|
+
|
|
6
|
+
## Tool Cost Hierarchy
|
|
7
|
+
|
|
8
|
+
### Tier 1: Cheapest (Always Try First)
|
|
9
|
+
```
|
|
10
|
+
Tool | Est. Tokens | When to Use
|
|
11
|
+
--------------|-------------|----------------------------------
|
|
12
|
+
Read | 500 | Single file access
|
|
13
|
+
Glob | 200 | Pattern-based file finding
|
|
14
|
+
Grep | 300 | Exact text/symbol search
|
|
15
|
+
Shell | 100 | Command execution
|
|
16
|
+
Write | 1000 | Creating new files
|
|
17
|
+
StrReplace | 500 | Small targeted edits (<50 lines)
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
### Tier 2: Moderate Cost
|
|
21
|
+
```
|
|
22
|
+
Tool | Est. Tokens | When to Use
|
|
23
|
+
-------------------|-------------|----------------------------------
|
|
24
|
+
SemanticSearch | 1500 | Conceptual/pattern search
|
|
25
|
+
ReadLints | 800 | Code quality validation
|
|
26
|
+
EditNotebook | 1000 | Jupyter notebook edits
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
### Tier 3: Higher Cost
|
|
30
|
+
```
|
|
31
|
+
Tool | Est. Tokens | When to Use
|
|
32
|
+
--------------|-------------|----------------------------------
|
|
33
|
+
Task | 3000 | Complex exploration (subagents)
|
|
34
|
+
WebSearch | 2000 | Web search operations
|
|
35
|
+
WebFetch | 2500 | Fetch web content
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
### Tier 4: Most Expensive (Use Sparingly)
|
|
39
|
+
```
|
|
40
|
+
MCP Server | Est. Tokens | When to Use
|
|
41
|
+
------------------------|-------------|----------------------------------
|
|
42
|
+
cursor-ide-browser | 5000+ | Visual verification, UI testing
|
|
43
|
+
user-github | 2000 | Git/GitHub operations
|
|
44
|
+
user-chrome-devtools | 3000 | Performance audits
|
|
45
|
+
user-playwright | 4000 | Cross-browser E2E testing
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## Cost Calculation Formulas
|
|
49
|
+
|
|
50
|
+
### Per-Tool Cost
|
|
51
|
+
```typescript
|
|
52
|
+
function calculateToolCost(toolCalls: ToolCall[]): number {
|
|
53
|
+
const costEstimates: Record<string, number> = {
|
|
54
|
+
'Shell': 100, 'Read': 500, 'Write': 1000,
|
|
55
|
+
'Glob': 200, 'Grep': 300, 'StrReplace': 500,
|
|
56
|
+
'ReadLints': 800, 'SemanticSearch': 1500,
|
|
57
|
+
'Task': 3000, 'WebSearch': 2000, 'WebFetch': 2500,
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
let totalCost = 0;
|
|
61
|
+
for (const tool of toolCalls) {
|
|
62
|
+
if (tool.mcp_server) {
|
|
63
|
+
totalCost += 5000; // MCP tools estimated higher
|
|
64
|
+
} else {
|
|
65
|
+
totalCost += costEstimates[tool.name] || 1000;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
return totalCost;
|
|
70
|
+
}
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
### Plan Efficiency Score
|
|
74
|
+
```typescript
|
|
75
|
+
function calculateEfficiency(tools: ToolCall[]): number {
|
|
76
|
+
const tierScores: Record<string, number> = {
|
|
77
|
+
'Shell': 100, 'Read': 100, 'Write': 100,
|
|
78
|
+
'Glob': 100, 'Grep': 100,
|
|
79
|
+
'ReadLints': 80, 'SemanticSearch': 80,
|
|
80
|
+
'Task': 60, 'WebSearch': 60, 'WebFetch': 60,
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
let totalScore = 0;
|
|
84
|
+
let toolCount = 0;
|
|
85
|
+
|
|
86
|
+
for (const tool of tools) {
|
|
87
|
+
if (tool.mcp_server) {
|
|
88
|
+
totalScore += 40; // MCP = lowest efficiency score
|
|
89
|
+
toolCount++;
|
|
90
|
+
} else {
|
|
91
|
+
totalScore += tierScores[tool.name] || 75;
|
|
92
|
+
toolCount++;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
return toolCount > 0 ? Math.round(totalScore / toolCount) : 75;
|
|
97
|
+
}
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
### Cost Per Task Type
|
|
101
|
+
```
|
|
102
|
+
Task Type | Avg Tokens | Optimization Target
|
|
103
|
+
-----------------------|------------|--------------------
|
|
104
|
+
Simple bug fix | 2,000-5,000 | <3,000
|
|
105
|
+
Feature implementation | 10,000-20,000 | <15,000
|
|
106
|
+
Complex refactor | 15,000-30,000 | <20,000
|
|
107
|
+
New file creation | 3,000-8,000 | <5,000
|
|
108
|
+
Research/exploration | 5,000-15,000 | <10,000
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
## Cost Tracking
|
|
112
|
+
|
|
113
|
+
### Automatic Tracking (Enabled by Default)
|
|
114
|
+
The `plan-quality-tracker.ts` hook automatically tracks:
|
|
115
|
+
- Tool usage per plan
|
|
116
|
+
- Estimated token cost
|
|
117
|
+
- Rolling averages (last 10 plans)
|
|
118
|
+
- Cost efficiency scores
|
|
119
|
+
|
|
120
|
+
### Manual Tracking
|
|
121
|
+
```bash
|
|
122
|
+
# View recent plan costs
|
|
123
|
+
cat .cursor/plan-metrics.json | jq '.[-10:] | .[].cost_estimate'
|
|
124
|
+
|
|
125
|
+
# Calculate average cost
|
|
126
|
+
cat .cursor/plan-metrics.json | jq '[.[].cost_estimate] | add / length'
|
|
127
|
+
|
|
128
|
+
# Find most expensive plans
|
|
129
|
+
cat .cursor/plan-metrics.json | jq 'sort_by(-.cost_estimate) | .[0:5]'
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
### Cost Alerts
|
|
133
|
+
Configure in `.cursor/hooks.config.json`:
|
|
134
|
+
```json
|
|
135
|
+
{
|
|
136
|
+
"planTracking": {
|
|
137
|
+
"enableCostTracking": true,
|
|
138
|
+
"costAlertThreshold": 20000,
|
|
139
|
+
"efficiencyThreshold": 60
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
## Optimization Strategies
|
|
145
|
+
|
|
146
|
+
### Strategy 1: Tool Escalation Protocol
|
|
147
|
+
**Rule**: Start with cheapest tool, escalate only if needed
|
|
148
|
+
|
|
149
|
+
```
|
|
150
|
+
1. Try Tier 1 first:
|
|
151
|
+
- Need file? → Read (know path) or Glob (pattern)
|
|
152
|
+
- Need text? → Grep (exact) or SemanticSearch (concept)
|
|
153
|
+
|
|
154
|
+
2. If Tier 1 fails → Escalate to Tier 2:
|
|
155
|
+
- Complex search? → SemanticSearch
|
|
156
|
+
- Small edit? → StrReplace
|
|
157
|
+
|
|
158
|
+
3. If Tier 2 inadequate → Escalate to Tier 3:
|
|
159
|
+
- Broad exploration? → Task (subagent)
|
|
160
|
+
- External info? → WebSearch/WebFetch
|
|
161
|
+
|
|
162
|
+
4. If Tier 3 insufficient → Escalate to Tier 4:
|
|
163
|
+
- Visual verification? → cursor-ide-browser
|
|
164
|
+
- Git operations? → user-github
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
**Savings**: 30-50% reduction in token consumption
|
|
168
|
+
|
|
169
|
+
### Strategy 2: MCP Tool Optimization
|
|
170
|
+
**Rule**: Use MCP tools only when essential
|
|
171
|
+
|
|
172
|
+
**When to Use MCP**:
|
|
173
|
+
- ✅ Visual verification (UI changes)
|
|
174
|
+
- ✅ Git/GitHub operations
|
|
175
|
+
- ✅ Performance audits
|
|
176
|
+
- ✅ Documentation lookup
|
|
177
|
+
- ❌ Simple file operations (use Read/Write)
|
|
178
|
+
- ❌ Basic searches (use Grep/Glob)
|
|
179
|
+
- ❌ Code edits (use StrReplace/Write)
|
|
180
|
+
|
|
181
|
+
**Savings**: 40-60% reduction for typical tasks
|
|
182
|
+
|
|
183
|
+
### Strategy 3: Parallel Exploration
|
|
184
|
+
**Rule**: Use parallel subagents for complex tasks (>10 steps)
|
|
185
|
+
|
|
186
|
+
**Cost-Benefit**:
|
|
187
|
+
- Cost: 3-4 subagents × 3000 tokens = 9,000-12,000 tokens
|
|
188
|
+
- Benefit: 60-70% faster discovery, prevents wasted iterations
|
|
189
|
+
- ROI: Positive for tasks >30 min estimated
|
|
190
|
+
|
|
191
|
+
**Configuration**:
|
|
192
|
+
```typescript
|
|
193
|
+
Task:
|
|
194
|
+
description="Explore [area]"
|
|
195
|
+
model="fast" // Cost optimization
|
|
196
|
+
readonly=true // Safety
|
|
197
|
+
run_in_background=true // Non-blocking
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
### Strategy 4: Research First, Plan Second
|
|
201
|
+
**Rule**: Spend 2-3 min on research before planning
|
|
202
|
+
|
|
203
|
+
**Research Tools** (cheap):
|
|
204
|
+
- SemanticSearch: 1500 tokens
|
|
205
|
+
- Grep: 300 tokens
|
|
206
|
+
- Glob: 200 tokens
|
|
207
|
+
|
|
208
|
+
**Benefit**:
|
|
209
|
+
- Prevents wrong direction (-10,000+ tokens wasted)
|
|
210
|
+
- Improves accuracy by 20-25%
|
|
211
|
+
- Reduces iterations by 40-50%
|
|
212
|
+
|
|
213
|
+
### Strategy 5: Automatic Validation
|
|
214
|
+
**Rule**: Always validate after substantive changes
|
|
215
|
+
|
|
216
|
+
**Validation Sequence**:
|
|
217
|
+
1. ReadLints (800 tokens) - catches errors early
|
|
218
|
+
2. Shell tests (100 tokens) - verifies functionality
|
|
219
|
+
3. MCP validation (if used) - ensures tool success
|
|
220
|
+
|
|
221
|
+
**Benefit**:
|
|
222
|
+
- Catches 95% of issues before commit
|
|
223
|
+
- Prevents expensive rework
|
|
224
|
+
- Reduces revision cycles by 55%
|
|
225
|
+
|
|
226
|
+
## Cost Optimization Checklist
|
|
227
|
+
|
|
228
|
+
### Before Starting Task
|
|
229
|
+
- [ ] Define clear success criteria
|
|
230
|
+
- [ ] Estimate complexity (simple/medium/complex)
|
|
231
|
+
- [ ] Identify cheapest tool sequence
|
|
232
|
+
- [ ] Set cost budget based on task type
|
|
233
|
+
|
|
234
|
+
### During Execution
|
|
235
|
+
- [ ] Follow tool escalation protocol
|
|
236
|
+
- [ ] Use Tier 1 tools first
|
|
237
|
+
- [ ] Avoid MCP unless essential
|
|
238
|
+
- [ ] Track tool usage mentally
|
|
239
|
+
|
|
240
|
+
### After Completion
|
|
241
|
+
- [ ] Review actual cost vs estimate
|
|
242
|
+
- [ ] Check efficiency score (target: >70%)
|
|
243
|
+
- [ ] Identify optimization opportunities
|
|
244
|
+
- [ ] Log learnings for future reference
|
|
245
|
+
|
|
246
|
+
## Cost Reduction Examples
|
|
247
|
+
|
|
248
|
+
### Example 1: Bug Fix (Before/After)
|
|
249
|
+
|
|
250
|
+
**Before** (No optimization):
|
|
251
|
+
```
|
|
252
|
+
1. Task (explore): "Find auth bug" - 3000 tokens
|
|
253
|
+
2. browser_snapshot - 5000 tokens
|
|
254
|
+
3. StrReplace - 500 tokens
|
|
255
|
+
4. ReadLints - 800 tokens
|
|
256
|
+
Total: 9,300 tokens
|
|
257
|
+
Efficiency: 52%
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
**After** (Optimized):
|
|
261
|
+
```
|
|
262
|
+
1. Grep: "find login function" - 300 tokens
|
|
263
|
+
2. Read: auth code - 500 tokens
|
|
264
|
+
3. StrReplace: fix bug - 500 tokens
|
|
265
|
+
4. ReadLints: validate - 800 tokens
|
|
266
|
+
Total: 2,100 tokens
|
|
267
|
+
Efficiency: 88%
|
|
268
|
+
Savings: 77% reduction
|
|
269
|
+
```
|
|
270
|
+
|
|
271
|
+
### Example 2: Feature Implementation
|
|
272
|
+
|
|
273
|
+
**Before** (No optimization):
|
|
274
|
+
```
|
|
275
|
+
1. browser_snapshot - 5000 tokens
|
|
276
|
+
2. Task x3 (parallel) - 9000 tokens
|
|
277
|
+
3. Write x5 files - 5000 tokens
|
|
278
|
+
4. user-github (create PR) - 2000 tokens
|
|
279
|
+
Total: 21,000 tokens
|
|
280
|
+
Efficiency: 58%
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
**After** (Optimized):
|
|
284
|
+
```
|
|
285
|
+
1. SemanticSearch: patterns - 1500 tokens
|
|
286
|
+
2. Read: 3 examples - 1500 tokens
|
|
287
|
+
3. Write x5 files - 5000 tokens
|
|
288
|
+
4. ReadLints - 800 tokens
|
|
289
|
+
5. Shell (tests) - 100 tokens
|
|
290
|
+
6. user-github (create PR) - 2000 tokens
|
|
291
|
+
Total: 10,900 tokens
|
|
292
|
+
Efficiency: 76%
|
|
293
|
+
Savings: 48% reduction
|
|
294
|
+
```
|
|
295
|
+
|
|
296
|
+
### Example 3: Complex Refactor
|
|
297
|
+
|
|
298
|
+
**Before** (No optimization):
|
|
299
|
+
```
|
|
300
|
+
1. Task x4 (exploration) - 12,000 tokens
|
|
301
|
+
2. browser_snapshot x5 - 25,000 tokens
|
|
302
|
+
3. StrReplace x10 - 5000 tokens
|
|
303
|
+
4. ReadLints x3 - 2400 tokens
|
|
304
|
+
Total: 44,400 tokens
|
|
305
|
+
Efficiency: 45%
|
|
306
|
+
```
|
|
307
|
+
|
|
308
|
+
**After** (Optimized):
|
|
309
|
+
```
|
|
310
|
+
1. Task x3 (parallel, targeted) - 9000 tokens
|
|
311
|
+
2. Grep: find usages - 300 tokens
|
|
312
|
+
3. StrReplace x10 - 5000 tokens
|
|
313
|
+
4. ReadLints (auto) - 800 tokens
|
|
314
|
+
5. Shell (tests) - 100 tokens
|
|
315
|
+
Total: 15,200 tokens
|
|
316
|
+
Efficiency: 72%
|
|
317
|
+
Savings: 66% reduction
|
|
318
|
+
```
|
|
319
|
+
|
|
320
|
+
## Monitoring & Alerts
|
|
321
|
+
|
|
322
|
+
### Weekly Cost Review
|
|
323
|
+
```markdown
|
|
324
|
+
## Weekly Cost Report
|
|
325
|
+
|
|
326
|
+
### Summary
|
|
327
|
+
- Total plans: 15
|
|
328
|
+
- Total cost: 145,000 tokens
|
|
329
|
+
- Avg cost/plan: 9,667 tokens
|
|
330
|
+
- Target: <8,000 tokens
|
|
331
|
+
|
|
332
|
+
### Most Expensive Plans
|
|
333
|
+
1. Feature X: 25,000 tokens (over budget)
|
|
334
|
+
2. Refactor Y: 18,000 tokens (over budget)
|
|
335
|
+
3. Bug fix Z: 12,000 tokens (on budget)
|
|
336
|
+
|
|
337
|
+
### Optimization Wins
|
|
338
|
+
- Tool escalation: -35% avg cost
|
|
339
|
+
- MCP reduction: -50% MCP usage
|
|
340
|
+
- Research-first: +20% accuracy
|
|
341
|
+
|
|
342
|
+
### Action Items
|
|
343
|
+
1. Review Feature X approach (too expensive)
|
|
344
|
+
2. Document successful patterns
|
|
345
|
+
3. Adjust cost estimates
|
|
346
|
+
```
|
|
347
|
+
|
|
348
|
+
### Cost Alert Triggers
|
|
349
|
+
Configure alerts for:
|
|
350
|
+
- Single plan > 20,000 tokens
|
|
351
|
+
- Daily total > 100,000 tokens
|
|
352
|
+
- Weekly avg > 10,000 tokens/plan
|
|
353
|
+
- Efficiency score < 60%
|
|
354
|
+
|
|
355
|
+
## Tools & Resources
|
|
356
|
+
|
|
357
|
+
### Cost Calculators
|
|
358
|
+
- Built-in: `estimateCost()` in plan-quality-tracker.ts
|
|
359
|
+
- Manual: Use formulas above
|
|
360
|
+
- Dashboard: Future enhancement
|
|
361
|
+
|
|
362
|
+
### Cost Benchmarks
|
|
363
|
+
```
|
|
364
|
+
Developer Level | Avg Cost/Plan | Efficiency
|
|
365
|
+
----------------|---------------|------------
|
|
366
|
+
Junior | 12,000 | 55%
|
|
367
|
+
Mid | 8,000 | 70%
|
|
368
|
+
Senior | 6,000 | 80%
|
|
369
|
+
Optimized | 4,000 | 90%
|
|
370
|
+
```
|
|
371
|
+
|
|
372
|
+
### ROI Calculation
|
|
373
|
+
```
|
|
374
|
+
Time saved with optimization: 2 hours/week
|
|
375
|
+
Token cost reduction: 40%
|
|
376
|
+
Developer hourly rate: $50/hour
|
|
377
|
+
Weekly savings: $100
|
|
378
|
+
Monthly savings: $400
|
|
379
|
+
Annual savings: $4,800 per developer
|
|
380
|
+
```
|
|
381
|
+
|
|
382
|
+
## Related Documentation
|
|
383
|
+
- `AGENT-INSTRUCTION-BEST-PRACTICES.md` - Research backing
|
|
384
|
+
- `.cursor/skills/tool-selection/SKILL.md` - Tool selection
|
|
385
|
+
- `.cursor/plan-metrics.json` - Historical cost data
|
|
386
|
+
- `.cursor/hooks.config.json` - Configuration
|
|
387
|
+
|
|
388
|
+
## Maintenance
|
|
389
|
+
|
|
390
|
+
### Weekly
|
|
391
|
+
- Review cost metrics
|
|
392
|
+
- Identify optimization opportunities
|
|
393
|
+
- Adjust thresholds
|
|
394
|
+
|
|
395
|
+
### Monthly
|
|
396
|
+
- Analyze cost trends
|
|
397
|
+
- Update cost estimates
|
|
398
|
+
- Refine optimization strategies
|
|
399
|
+
|
|
400
|
+
### Quarterly
|
|
401
|
+
- Major strategy review
|
|
402
|
+
- Update benchmarks
|
|
403
|
+
- Integrate new tools/MCPs
|