Expense Tracker
Log and track daily expenses in markdown files organized by month.
Quick Start
Log an expense
CODEBLOCK0
Examples:
CODEBLOCK1
View monthly summary
CODEBLOCK2
File Organization
Expenses are stored in expenses/ directory at workspace root:
CODEBLOCK3
Each file contains a markdown table:
CODEBLOCK4
Categories
See references/categories.md for common expense categories. Use existing categories or create custom ones as needed.
Common categories:
- - Housing - Rent, utilities, home expenses
- Vehicle - Gas, maintenance, parking
- Dining - Restaurants, food delivery
- Coffee - Cafes, coffee shops
- Shopping - Clothes, electronics, general purchases
- Entertainment - Movies, games, hobbies
- Healthcare - Medicine, doctor visits
- Subscriptions - Netflix, Spotify, gym, apps
- Savings - Investments, emergency fund
- Debt Payment - Loans, credit cards
- Miscellaneous - Other expenses
Workflow Examples
Log daily expenses from conversation
When the user mentions spending money:
CODEBLOCK5
Monthly review
CODEBLOCK6
Analyze spending patterns
CODEBLOCK7
Auto Backup
Before every write, the script automatically backs up the current expense file to:
CODEBLOCK8
- - Backup runs before any modification (safe even if write fails)
- If the file doesn't exist yet (first entry of the month), backup is skipped
- Backup is overwritten each time with the latest pre-write snapshot
- This protects against accidental
rm -rf or corruption of the workspace
Tips
- - Batch logging: User can tell you multiple expenses at once, log them all
- Category consistency: Use the same category names to enable accurate summaries
- Tags for filtering: Use tags for subcategories (e.g., "work", "weekend", "urgent")
- Descriptions: Add context that helps identify the expense later
- Regular reviews: Suggest monthly summaries to track spending patterns
Integration with Financial Goals
When tracking expenses, consider:
- 1. Budget tracking: Compare monthly totals to target budget
- Spending patterns: Identify high-spend categories
- Emergency fund: Track savings progress
- Debt reduction: Monitor debt payment progress
- Financial ratios: Calculate expenses as % of income
Script Reference
log_expense.py
Commands:
- -
log - Add an expense entry - INLINECODE4 - View monthly summary
Arguments (log):
- -
amount - Amount in VND (required) - INLINECODE6 - Category name (required)
- INLINECODE7 - Optional description
- INLINECODE8 - Optional comma-separated tags
- INLINECODE9 - Optional date (YYYY-MM-DD, defaults to today)
- INLINECODE10 - Optional workspace path (defaults to ~/.openclaw/workspace)
Arguments (summary):
- -
year_month - Optional YYYY-MM (defaults to current month) - INLINECODE12 - Output as JSON
- INLINECODE13 - Optional workspace path
Output:
- - Creates/updates markdown files in
expenses/ directory - Prints confirmation with file location
- Summary shows total, count, and breakdown by category
费用追踪器
按月份整理Markdown文件,记录和追踪每日支出。
快速开始
记录一笔支出
bash
python3 scripts/log_expense.py log <金额> <类别> [--description 描述] [--tags 标签1,标签2] [--date YYYY-MM-DD]
示例:
bash
简单支出
python3 scripts/log_expense.py log 45000 咖啡
带描述
python3 scripts/log_expense.py log 250000 餐饮 --description 团队午餐
带标签
python3 scripts/log_expense.py log 500000 购物 --tags 衣服,促销 --description 新衬衫
指定日期(用于回溯记录)
python3 scripts/log_expense.py log 1200000 交通 --description 加油 --date 2026-02-15
查看月度汇总
bash
当前月份
python3 scripts/log_expense.py summary
指定月份
python3 scripts/log_expense.py summary 2026-02
JSON格式输出(便于解析)
python3 scripts/log_expense.py summary 2026-02 --json
文件组织
支出记录存储在工作区根目录的 expenses/ 文件夹中:
expenses/
├── 2026-01.md
├── 2026-02.md
└── 2026-03.md
每个文件包含一个Markdown表格:
markdown
支出 - 2026-02
| 日期 | 类别 | 金额(越南盾) | 描述 | 标签 |
|---|
| 2026-02-17 | 咖啡 | 45,000 | | |
| 2026-02-17 |
餐饮 | 250,000 | 团队午餐 | |
| 2026-02-17 | 购物 | 500,000 | 新衬衫 | 衣服,促销 |
类别
常见支出类别请参见 references/categories.md。可使用现有类别或根据需要创建自定义类别。
常见类别:
- - 住房 - 房租、水电费、居家开支
- 交通 - 加油、保养、停车费
- 餐饮 - 餐厅、外卖
- 咖啡 - 咖啡馆、咖啡店
- 购物 - 衣服、电子产品、一般购物
- 娱乐 - 电影、游戏、爱好
- 医疗 - 药品、就医
- 订阅 - Netflix、Spotify、健身房、应用
- 储蓄 - 投资、应急基金
- 债务还款 - 贷款、信用卡
- 杂项 - 其他支出
工作流程示例
从对话中记录每日支出
当用户提到花钱时:
bash
用户:刚付了35k买咖啡
python3 scripts/log_expense.py log 35000 咖啡
用户:在Phở 24吃了午餐,花了120k
python3 scripts/log_expense.py log 120000 餐饮 --description Phở 24
用户:加了油,400k
python3 scripts/log_expense.py log 400000 交通 --description 加油
月度回顾
bash
获取汇总
python3 scripts/log_expense.py summary 2026-02
查看支出文件详情
cat expenses/2026-02.md
分析消费模式
bash
获取JSON格式数据进行分析
python3 scripts/log_expense.py summary 2026-02 --json
比较多个月份
python3 scripts/log_expense.py summary 2026-01 --json > jan.json
python3 scripts/log_expense.py summary 2026-02 --json > feb.json
自动备份
每次写入前,脚本会自动将当前支出文件备份到:
~/Documents/expenses_backup/YYYY-MM.md
- - 备份在任何修改之前运行(即使写入失败也是安全的)
- 如果文件尚不存在(该月第一条记录),则跳过备份
- 每次备份都会用最新的写入前快照覆盖
- 这可以防止意外 rm -rf 或工作区损坏
提示
- - 批量记录:用户可以一次性告诉你多笔支出,全部记录下来
- 类别一致性:使用相同的类别名称以确保准确的汇总
- 标签用于筛选:使用标签进行子类别分类(例如工作、周末、紧急)
- 描述:添加上下文,便于日后识别该笔支出
- 定期回顾:建议每月汇总以追踪消费模式
与财务目标的整合
追踪支出时,请考虑:
- 1. 预算追踪:将月度总额与目标预算进行比较
- 消费模式:识别高消费类别
- 应急基金:追踪储蓄进度
- 债务减少:监控债务还款进度
- 财务比率:计算支出占收入的百分比
脚本参考
log_expense.py
命令:
- - log - 添加一笔支出记录
- summary - 查看月度汇总
参数(log):
- - amount - 越南盾金额(必填)
- category - 类别名称(必填)
- --description/-d - 可选描述
- --tags/-t - 可选逗号分隔的标签
- --date - 可选日期(YYYY-MM-DD,默认为今天)
- --workspace - 可选工作区路径(默认为 ~/.openclaw/workspace)
参数(summary):
- - year_month - 可选 YYYY-MM(默认为当前月份)
- --json - 以JSON格式输出
- --workspace - 可选工作区路径
输出:
- - 在 expenses/ 目录中创建/更新Markdown文件
- 打印确认信息及文件位置
- 汇总显示总额、笔数和按类别分类的明细