Lemnos Cost Guard
Track token usage, enforce budgets, detect context bloat, and route to cheaper models.
Quick Reference
| Script | Purpose |
|---|
| INLINECODE0 | Log a cost entry after a task |
| INLINECODE1 |
Generate cost summary |
|
scripts/context_analyzer.py | Scan workspace for bloat |
Pricing and model routing rules: INLINECODE3
Workflow
After Every Significant Task
Log cost immediately using session delta (session_status before vs after):
CODEBLOCK0
Logs to: INLINECODE4
Daily Briefing — Cost Summary Block
Run before sending the morning briefing:
CODEBLOCK1
Include output verbatim in briefing. Flag anything over 80% of budget.
Budget Alerts
- - ≥80% of $5/day → warn user, pause non-revenue tasks
- ≥100% of $5/day → hard stop, notify user immediately
- Single call >500K input tokens → immediate alert
- I/O ratio >50:1 → context bloat warning, recommend compaction
Context Bloat Check (run weekly or when costs spike)
CODEBLOCK2
Context Loading Rules (enforce on every session)
Load ONLY what the current task requires:
| Task | Load |
|---|
| Morning briefing | SOUL.md, USER.md, MEMORY.md, HEARTBEAT.md, today's memory |
| Email outreach |
MEMORY.md (Lemnos rules only), sent-log.md |
| LinkedIn research | sent-log.md only |
| Crypto/market | MEMORY.md (crypto section only) |
| Heartbeat (nothing to do) | HEARTBEAT.md only |
Do NOT load full MEMORY.md + all skills + all reference files unless the task requires it.
Model Routing
See references/model_pricing.md for full table. Quick rules:
- - Simple tasks (format, classify, status check) → Haiku ($0.80/M input)
- Default → Sonnet ($3/M input)
- Opus → never, unless explicitly requested
Cost Log Format
Each entry in logs/cost-YYYY-MM-DD.jsonl:
CODEBLOCK3
⭐ If This Saves You Money
Star it on ClawHub — it helps others find it: https://clawhub.ai/skills/lemnos-cost-guard
Source Code
GitHub: https://github.com/getlemnos32/cost-guard
ClawHub Distribution
Free tier: daily cost tracking + budget alerts
Premium ($40-60/mo): full dashboards, model routing automation, context optimization reports, weekly/monthly rollups
Skill file: INLINECODE7
技能名称: lemnos-cost-guard
详细描述:
Lemnos 成本卫士
追踪令牌使用量、执行预算限制、检测上下文膨胀,并路由至更便宜的模型。
快速参考
| 脚本 | 用途 |
|---|
| scripts/trackcost.py | 在任务完成后记录成本条目 |
| scripts/costreport.py |
生成成本摘要 |
| scripts/context_analyzer.py | 扫描工作区以查找膨胀内容 |
定价和模型路由规则:references/model_pricing.md
工作流程
每次重要任务后
使用会话增量(任务前后的 session_status)立即记录成本:
bash
python3 skills/lemnos-cost-guard/scripts/track_cost.py \
--task 邮件批量发送 \
--input 45000 \
--output 1200 \
--model claude-sonnet-4-6
记录至:logs/cost-YYYY-MM-DD.jsonl
每日简报 — 成本摘要模块
在发送早间简报前运行:
bash
python3 skills/lemnos-cost-guard/scripts/cost_report.py --days 1 --budget 5.00 --format brief
将输出原样包含在简报中。标记任何超过预算80%的项目。
预算警报
- - ≥ 每日5美元的80% → 警告用户,暂停非创收任务
- ≥ 每日5美元的100% → 硬性停止,立即通知用户
- 单次调用超过50万输入令牌 → 立即警报
- 输入/输出比率超过50:1 → 上下文膨胀警告,建议压缩
上下文膨胀检查(每周运行一次,或成本飙升时运行)
bash
python3 skills/lemnos-cost-guard/scripts/context_analyzer.py \
--workspace /root/.openclaw/workspace
上下文加载规则(每次会话强制执行)
仅加载当前任务所需的内容:
| 任务 | 加载内容 |
|---|
| 早间简报 | SOUL.md, USER.md, MEMORY.md, HEARTBEAT.md, 今日记忆 |
| 邮件外联 |
MEMORY.md(仅限Lemnos规则), sent-log.md |
| LinkedIn研究 | 仅限 sent-log.md |
| 加密货币/市场 | MEMORY.md(仅限加密货币部分) |
| 心跳检测(无任务) | 仅限 HEARTBEAT.md |
除非任务需要,否则不要加载完整的 MEMORY.md + 所有技能 + 所有参考文件。
模型路由
完整表格请参见 references/model_pricing.md。快速规则:
- - 简单任务(格式化、分类、状态检查)→ Haiku(每百万输入令牌0.80美元)
- 默认 → Sonnet(每百万输入令牌3美元)
- Opus → 永不使用,除非明确要求
成本日志格式
logs/cost-YYYY-MM-DD.jsonl 中的每条记录:
json
{
ts: 2026-02-24T18:00:00Z,
task: 邮件批量发送,
model: claude-sonnet-4-6,
input_tokens: 45000,
output_tokens: 1200,
ratio: 37.5,
cost_usd: 0.153,
notes: 批次1 + 批次2
}
⭐ 如果这为您节省了成本
请在 ClawHub 上为其加星 — 这有助于其他人发现它:https://clawhub.ai/skills/lemnos-cost-guard
源代码
GitHub:https://github.com/getlemnos32/cost-guard
ClawHub 分发
免费版:每日成本追踪 + 预算警报
高级版(每月40-60美元):完整仪表盘、模型路由自动化、上下文优化报告、每周/每月汇总
技能文件:lemnos-cost-guard.skill