ClaudeMods
☰
ZH-CN
● 0 人在线 · 浏览 0 次
赞助提交作品
GitHub 仓库 · 发布者 0xGondarxyz

active-time

一个计算你真正花在 Claude Code 上的时间的 Claude Code mod(包括打字和 Claude 工作,不包括空闲终端),并在状态栏和 /claude-time 中显示。

0xGondarxyz@0xGondarxyz

0xGondarxyz/claude-code-mods/tree/main/active-time

已翻译

关于这个 mod

active-time

一个统计你真正与 Claude Code 相处时间的 Claude Code mod。打开的终端不计入。后台运行的开发服务器也不计入。

这个 mod 位于名为 active-time 的文件夹中,因为 Claude Code 保留了以 claude- 开头的插件名称。命令仍然是 /claude-time。

安装

/plugin marketplace add 0xGondarxyz/claude-code-mods
/plugin install active-time@claude-code-mods

或者不安装直接试用:

git clone https://github.com/0xGondarxyz/claude-code-mods
claude --plugin-dir claude-code-mods/active-time

Mods 不受沙箱限制。它们拥有与 Claude Code 相同的访问权限。安装任何 mod(包括这个)之前都请先阅读源代码。

什么会被计入

两类活跃时间:

  • you:你在提示框中输入内容。间隔 120 s 或更短的编辑算作同一个区间。更长的暂停会开始新区间。提交提示会关闭区间。
  • claude:Claude 在工作。这是任何代理的每个模型请求和每次工具调用(一次工具调用最多计 10 分钟)。后台子代理工作时也会计入。它们之间间隔 30 s 或更短会合并。一个回合的等待(例如等待问题回答)不计入,只有其中的模型请求和工具调用计入。

总时间是两类时间的并集。重叠部分只计一次。两个同时工作的会话也只计一次。

状态行

CC today 2h14m · week 11h05m

一天的工作日从本地时间 05:00 到 05:00,因此午夜后的工作计入前一天。每周从星期一 05:00 开始。每回合结束后和每 60 s 更新一次。

命令

/claude-time 会显示:

  • 今天、本周和本月,并分别拆分为 you 和 claude
  • 最近 7 天,每天一行
  • 本周按仓库统计(按文件夹名称取前 5 名)

数据在哪里

每个会话都会写入自己的文件,因此会话之间不会互相覆盖:

~/.claude/active-time/<YYYY-MM-DD>_<sessionId>.json

内容:{ "repo": "...", "intervals": [{ "s": ms, "e": ms, "k": "you" | "claude" }] }。跨越 05:00 的会话会为每个工作日写入一个文件,<YYYY-MM-DD> 是工作日。repo 是会话文件夹的 git 顶层目录,或文件夹本身。

要重置,请删除该文件夹:

rm -r ~/.claude/active-time

从转录回填

在 mod 加载前开始的会话,会从 ~/.claude/projects 中最近 40 天的转录重建。这只能提供 Claude 的时间,无法恢复旧会话的打字时间。

  • 每条转录条目都有时间戳。连续两条之间,如果第二条不是实际用户提示且间隔不超过 10 分钟,两者之间的时间计为 claude 时间。提示会开始等待。更长的间隔也算等待。30 s 或更短的间隔会合并。
  • 无头转录(claude -p、SDK)会跳过。
  • 结果写入 ~/.claude/active-time/<YYYY-MM-DD>_<sessionId>.bf.json(形状相同,并加上 "source": "transcript")。不会修改实时文件。总计会对所有文件取并集,因此同时存在两种类型时只计一次。
  • 它会在交互式会话开始时于后台运行,之后每 10 分钟运行一次。只有自上次运行后变更的转录会再次读取。首次运行可能需要一段时间。
  • 需要 python3(/usr/bin/python3)和 find。

无头运行

提示框前没有真人的会话(claude -p、SDK)不会记录任何内容、不会写入文件,也不会显示状态行。

限制

  • Claude Code 崩溃时仍打开的区间会丢失。
  • 等待你回答许可的工具调用会计入 Claude 时间(最多计 10 分钟)。
  • 只会在主提示框中检测打字。
  • 总计是墙钟时间,不是计费时间。

安装

请先查看作者 README 确认 marketplace 和插件名称;命令可能随仓库结构改变。

claude plugin marketplace add 0xGondarxyz/claude-code-mods
claude plugin install active-time
原文 / README

active-time

A Claude Code mod that counts the time you really spend with Claude Code. An open terminal does not count. A dev server running in the background does not count.

The mod lives in a folder named active-time because Claude Code reserves plugin names that start with claude-. The command is still /claude-time.

Install

/plugin marketplace add 0xGondarxyz/claude-code-mods
/plugin install active-time@claude-code-mods

Or try it without installing:

git clone https://github.com/0xGondarxyz/claude-code-mods
claude --plugin-dir claude-code-mods/active-time

Mods are not sandboxed. They run with the same access as Claude Code. Read the source before you install any mod, including this one.

What counts

Two kinds of active time:

  • you: you write in the prompt box. Edits with a gap of 120 s or less form one interval. A longer pause starts a new one. Submitting a prompt closes the interval.
  • claude: Claude works. This is each model request and each tool call of any agent of any agent (one tool call counts at most 10 minutes). Background subagents count while they work. Gaps of 30 s or less between these join. The wait of a turn (for example on a question) does not count, only the model requests and tool calls inside it.

The total is the union of both kinds. Overlaps count once. Two sessions that work at the same time count once.

Status line

CC today 2h14m · week 11h05m

A day is a work day from 05:00 to 05:00 local time, so work after midnight counts for the day before. The week starts on Monday 05:00. It updates after each turn and every 60 s.

Command

/claude-time shows:

  • today, this week and this month, each split into you and claude
  • the last 7 days, one line each
  • this week per repo (top 5, by folder name)

Where the data lives

Each session writes its own file, so sessions never overwrite each other:

~/.claude/active-time/<YYYY-MM-DD>_<sessionId>.json

Content: { "repo": "...", "intervals": [{ "s": ms, "e": ms, "k": "you" | "claude" }] }. A session that crosses 05:00 writes one file per work day, and <YYYY-MM-DD> is the work day. The repo is the git top level of the session folder, or the folder itself.

To reset, delete the folder:

rm -r ~/.claude/active-time

Backfill from transcripts

Sessions that started before the mod loaded are rebuilt from the transcripts in ~/.claude/projects, for the last 40 days. This gives Claude time only. Typing time of old sessions cannot be recovered.

  • Each transcript entry has a timestamp. For two entries in a row, the time between them counts as claude time when the second one is not a real user prompt and the gap is 10 minutes or less. A prompt starts a wait. A longer gap is a wait too. Gaps of 30 s or less join.
  • Headless transcripts (claude -p, the SDK) are skipped.
  • Results go to ~/.claude/active-time/<YYYY-MM-DD>_<sessionId>.bf.json (same shape plus "source": "transcript"). Live files are never touched. Totals take the union of all files, so a session with both kinds counts once.
  • It runs in the background at the start of an interactive session, then every 10 minutes. Only transcripts changed since the last run are read again. The first run can take a while.
  • It needs python3 (/usr/bin/python3) and find.

Headless runs

Sessions without a person at the prompt (claude -p, the SDK) record nothing, write no file and show no status line.

Limits

  • Intervals still open when Claude Code crashes are lost.
  • A tool call that waits for your permission answer counts as Claude time (up to the 10 minute cap).
  • Typing is seen only in the main prompt box.
  • Totals are wall clock, not billed time.

更多类似作品