ClaudeMods
☰
ZH-TW
● 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.

更多類似作品