cc-safe-setup 3.8.0 → 3.8.1
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/README.md +2 -0
- package/examples/cost-tracker.sh +56 -0
- package/index.mjs +2 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -224,6 +224,8 @@ Or browse all available examples in [`examples/`](examples/):
|
|
|
224
224
|
- **session-handoff.sh** — Auto-save git state and session info to `~/.claude/session-handoff.md` on session end
|
|
225
225
|
- **diff-size-guard.sh** — Warn/block when committing too many files at once (default: warn at 10, block at 50)
|
|
226
226
|
- **dependency-audit.sh** — Warn when installing packages not in manifest (npm/pip/cargo supply chain awareness)
|
|
227
|
+
- **cost-tracker.sh** — Estimate session token cost and warn at thresholds ($1, $5)
|
|
228
|
+
- **read-before-edit.sh** — Warn when editing files not recently read (prevents old_string mismatches)
|
|
227
229
|
|
|
228
230
|
## Safety Checklist
|
|
229
231
|
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
# ================================================================
|
|
3
|
+
# cost-tracker.sh — Estimate session token cost
|
|
4
|
+
# ================================================================
|
|
5
|
+
# PURPOSE:
|
|
6
|
+
# Claude Code doesn't show token costs. This hook tracks
|
|
7
|
+
# tool calls and estimates cumulative cost, warning at thresholds.
|
|
8
|
+
#
|
|
9
|
+
# TRIGGER: PostToolUse
|
|
10
|
+
# MATCHER: ""
|
|
11
|
+
#
|
|
12
|
+
# HOW IT WORKS:
|
|
13
|
+
# Counts tool calls as a proxy for token usage.
|
|
14
|
+
# Average tool call ≈ 2K tokens input + 1K output.
|
|
15
|
+
# Opus: $15/M input, $75/M output
|
|
16
|
+
# Sonnet: $3/M input, $15/M output
|
|
17
|
+
#
|
|
18
|
+
# CONFIGURATION:
|
|
19
|
+
# CC_COST_MODEL=opus (default) or sonnet
|
|
20
|
+
# CC_COST_WARN=1.00 warn at $1 (default)
|
|
21
|
+
# CC_COST_BLOCK=5.00 warn at $5 (default, doesn't block)
|
|
22
|
+
# ================================================================
|
|
23
|
+
|
|
24
|
+
COUNTER_FILE="/tmp/cc-cost-tracker-calls"
|
|
25
|
+
LAST_WARN="/tmp/cc-cost-tracker-warned"
|
|
26
|
+
|
|
27
|
+
COUNT=$(cat "$COUNTER_FILE" 2>/dev/null || echo 0)
|
|
28
|
+
COUNT=$((COUNT + 1))
|
|
29
|
+
echo "$COUNT" > "$COUNTER_FILE"
|
|
30
|
+
|
|
31
|
+
MODEL="${CC_COST_MODEL:-opus}"
|
|
32
|
+
WARN="${CC_COST_WARN:-1.00}"
|
|
33
|
+
BLOCK="${CC_COST_BLOCK:-5.00}"
|
|
34
|
+
|
|
35
|
+
# Estimate: ~2K input + ~1K output tokens per tool call
|
|
36
|
+
if [ "$MODEL" = "opus" ]; then
|
|
37
|
+
# Opus: $15/M in, $75/M out → ~$0.105 per tool call
|
|
38
|
+
COST=$(echo "scale=2; $COUNT * 0.105" | bc 2>/dev/null || echo "0")
|
|
39
|
+
else
|
|
40
|
+
# Sonnet: $3/M in, $15/M out → ~$0.021 per tool call
|
|
41
|
+
COST=$(echo "scale=2; $COUNT * 0.021" | bc 2>/dev/null || echo "0")
|
|
42
|
+
fi
|
|
43
|
+
|
|
44
|
+
# Graduated warnings (with cooldown)
|
|
45
|
+
WARNED=$(cat "$LAST_WARN" 2>/dev/null || echo "0")
|
|
46
|
+
|
|
47
|
+
if [ "$(echo "$COST >= $BLOCK" | bc 2>/dev/null)" = "1" ] && [ "$WARNED" != "block" ]; then
|
|
48
|
+
echo "COST: ~\$${COST} estimated ($COUNT tool calls, $MODEL)" >&2
|
|
49
|
+
echo "Consider finishing current task and compacting." >&2
|
|
50
|
+
echo "block" > "$LAST_WARN"
|
|
51
|
+
elif [ "$(echo "$COST >= $WARN" | bc 2>/dev/null)" = "1" ] && [ "$WARNED" = "0" ]; then
|
|
52
|
+
echo "COST: ~\$${COST} estimated ($COUNT tool calls, $MODEL)" >&2
|
|
53
|
+
echo "warn" > "$LAST_WARN"
|
|
54
|
+
fi
|
|
55
|
+
|
|
56
|
+
exit 0
|
package/index.mjs
CHANGED
|
@@ -356,6 +356,8 @@ function examples() {
|
|
|
356
356
|
'commit-quality-gate.sh': 'Warn on vague or too-long commit messages',
|
|
357
357
|
'diff-size-guard.sh': 'Warn/block on large diffs (10+ files warn, 50+ block)',
|
|
358
358
|
'dependency-audit.sh': 'Warn on new package installs not in manifest',
|
|
359
|
+
'cost-tracker.sh': 'Estimate session token cost ($1 warn, $5 alert)',
|
|
360
|
+
'read-before-edit.sh': 'Warn when editing files not recently read',
|
|
359
361
|
},
|
|
360
362
|
};
|
|
361
363
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cc-safe-setup",
|
|
3
|
-
"version": "3.8.
|
|
3
|
+
"version": "3.8.1",
|
|
4
4
|
"description": "One command to make Claude Code safe for autonomous operation. 8 built-in + 36 examples. 21 commands: create, audit, lint, diff, share, benchmark, watch, learn. 2,500+ daily npm downloads.",
|
|
5
5
|
"main": "index.mjs",
|
|
6
6
|
"bin": {
|