1- # codetime
1+ < div align = " center " >
22
3- CLI for [ codetime] ( https://codetime.dev ) . Detects local AI-agent installs
4- (Claude Code, Codex, OpenCode, Pi), installs hooks, and ships
5- pre-aggregated session rollups to ` /v3/agent/ingest ` .
3+ <img src =" https://codetime.dev/icon.svg " alt =" codetime " width =" 96 " height =" 96 " />
4+
5+ # codetime-cli
6+
7+ ** Track AI-agent coding time across Claude Code, Codex, OpenCode, and Pi.**
8+
9+ [ ![ npm] ( https://img.shields.io/npm/v/codetime-cli?color=1874A8&label=npm )] ( https://www.npmjs.com/package/codetime-cli )
10+ [ ![ license] ( https://img.shields.io/npm/l/codetime-cli?color=1874A8 )] ( ./packages/cli/package.json )
11+ [ ![ node] ( https://img.shields.io/node/v/codetime-cli?color=1874A8 )] ( https://nodejs.org )
12+
13+ [ codetime.dev] ( https://codetime.dev ) · [ Dashboard] ( https://codetime.dev/dashboard ) · [ Issues] ( https://github.com/codetime-dev/codetime-cli/issues )
14+
15+ </div >
16+
17+ ---
18+
19+ The official CLI for [ codetime] ( https://codetime.dev ) . It detects local
20+ AI-agent installs, wires up their hooks, and ships pre-aggregated session
21+ rollups to ` /v3/agent/ingest ` — so the same dashboard that tracks your
22+ editor time also tracks your agent time.
23+
24+ > Privacy: only ** metadata** leaves your machine. Prompt text, command
25+ > output, source code, and diffs are never imported or uploaded.
26+ > See [ Privacy & data collected] ( #privacy--data-collected ) for the full
27+ > field-level breakdown.
28+
29+ ## Features
30+
31+ - ** Zero-config detection** — ` codetime detect ` finds installed agents.
32+ - ** Hook installation** — one command wires each agent's hook into codetime.
33+ - ** History backfill** — import past sessions from local JSONL transcripts.
34+ - ** Incremental sync** — watermarked, throttled, runs in the background.
35+ - ** Multi-machine** — every host is a named machine in your dashboard.
36+ - ** Token reuse** — same upload token as the VSCode plugin; no extra login.
37+
38+ ## Supported agents
39+
40+ | Agent | id | Source |
41+ | --- | --- | --- |
42+ | Claude Code | ` claude ` | ` ~/.claude/projects/** ` |
43+ | Codex CLI | ` codex ` | ` ~/.codex/sessions/** ` |
44+ | OpenCode | ` opencode ` | ` ~/.local/share/opencode/** ` |
45+ | Pi | ` pi ` | ` ~/.pi/sessions/** ` |
646
747## Install
848
949``` sh
10- npm i -g codetime-cli # bin is `codetime`
50+ npm i -g codetime-cli # bin: `codetime`
51+ ```
52+
53+ Requires Node.js ≥ 20.
1154
12- # 1. Copy your upload token from https://codetime.dev/dashboard/settings.
13- # 2. Tell the CLI about it (writes ~/.codetime/config.json).
55+ ## Quick start
56+
57+ ``` sh
58+ # 1. Copy your upload token from https://codetime.dev/dashboard/settings
1459codetime token set < token>
1560
16- # 3. Install integrations for whichever agents you use.
61+ # 2. See which agents are installed locally
1762codetime detect
18- codetime install --target claude
19- ```
2063
21- The CLI reuses the upload token you already use for the VSCode plugin —
22- there's no separate "agent login". Identity is sent on each upload via
23- the ` X-Machine-Id ` header (a UUID minted once and persisted under
24- ` ~/.codetime/machine-id ` ).
64+ # 3. Wire up the hooks (auto-detects, or pass --target / --all)
65+ codetime install
2566
26- ## Packages
67+ # 4. (Optional) Backfill past sessions
68+ codetime backfill import --source all
69+ ```
2770
28- - ` packages/cli ` — the published ` codetime-cli ` npm package (bin: ` codetime ` ).
29- - ` packages/shared ` — internal ` @ codetime/shared ` types, inlined into
30- the published bundle .
71+ Identity is sent on each upload via the ` X-Machine-Id ` header — a UUID
72+ minted once and persisted at ` ~/. codetime/machine-id ` . Rename machines
73+ from ` codetime machine rename --name "..." ` or the dashboard .
3174
32- ## Environment
75+ ## Commands
3376
34- | Variable | Purpose |
77+ | Command | Purpose |
3578| --- | --- |
36- | ` CODETIME_API_URL ` | Override API host (default ` https://codetime.dev ` ). |
37- | ` CODETIME_TOKEN ` | Bearer token (same value as the upload token in Settings). |
38- | ` CODETIME_DEBUG ` | Print verbose hook + import logs. |
79+ | ` codetime detect ` | List supported targets and install status. |
80+ | ` codetime install [--target <id>] [--all] [--force] [--dry-run] ` | Install hooks into detected or requested targets. |
81+ | ` codetime backfill <plan\|import\|discover\|verify> [--source <id>] [--since] [--until] [--project] [--force] ` | Import local agent history. |
82+ | ` codetime token <set\|show\|clear> ` | Manage the upload token (stored in ` ~/.codetime/config.json ` ). |
83+ | ` codetime machine <ls\|rename\|delete> ` | Manage registered machines. |
84+ | ` codetime hook --agent <name> ` | Internal — invoked by installed hook files. |
85+ | ` codetime version ` / ` codetime help ` | Self-explanatory. |
86+
87+ Add ` --json ` to most commands for machine-readable output, or ` --dry-run `
88+ to preview without writing or uploading.
89+
90+ ## Privacy & data collected
91+
92+ codetime-cli is ** metadata-only** . We never read or upload the contents
93+ of your code, prompts, or tool output. Below is the exact set of fields
94+ that leave your machine.
95+
96+ ### What IS collected
97+
98+ ** Identity & host**
99+
100+ - Machine UUID (` ~/.codetime/machine-id ` ), hostname, OS platform, and
101+ the display name you set via ` codetime machine rename ` .
102+ - Your upload token, sent as ` Authorization: Bearer ` on every request.
103+
104+ ** Session shape** (per agent session)
105+
106+ - Agent name (` claude ` / ` codex ` / ` opencode ` / ` pi ` ), session id,
107+ turn ids, timestamps, durations.
108+ - Workspace / project name — typically the basename of the working
109+ directory the agent was launched in (e.g. ` codetime-cli ` ).
110+ - The working directory ** path** (` cwd ` ) and a derived ` workspaceId `
111+ hash. Absolute paths may include your username (e.g.
112+ ` /home/alice/work/myproject ` ).
113+ - Model identifiers (e.g. ` claude-opus-4-7 ` ) and per-model call counts.
114+ - Tool names invoked (e.g. ` Bash ` , ` Edit ` , ` Read ` ) and how often they
115+ ran or failed — ** never the arguments or results** .
116+ - Token usage: input / output / cache / reasoning, plus estimated cost.
117+ - Prompt ** character count** per turn (not the prompt text).
118+
119+ ** File activity** (per touched file)
120+
121+ - File path within the workspace (e.g. ` src/cli.ts ` ) and a stable
122+ ` pathHash ` — useful for dashboards that group by file.
123+ - File language, kind (` source ` / ` test ` / ` config ` / ` docs ` / ` data ` ),
124+ bytes / chars / lines ** read / added / removed** — counts only.
125+
126+ ### What is NEVER collected
127+
128+ - ❌ Source code, file contents, or diffs.
129+ - ❌ Prompt text, assistant replies, system prompts, or any chat
130+ message bodies.
131+ - ❌ Shell command text, command output, or stdout / stderr.
132+ - ❌ Tool-call arguments or tool-call responses.
133+ - ❌ Environment variables, secrets, tokens, or API keys.
134+ - ❌ Filesystem contents outside the agent's session transcripts.
135+ - ❌ Browser history, clipboard, keystrokes, screenshots, microphone,
136+ camera — none of that is touched.
137+
138+ ### Verify it yourself
139+
140+ Every command supports a dry-run that prints the exact payload without
141+ sending it:
142+
143+ ``` sh
144+ codetime backfill plan --source all --json # see planned events
145+ codetime backfill import --source all --dry-run # see, don't upload
146+ echo ' {}' | codetime hook --agent claude --dry-run
147+ ```
148+
149+ Source of truth for the wire format: ` packages/shared/src/index.ts `
150+ (` CanonicalEvent ` , ` SessionRollup ` , ` FileActivityRecord ` ). If a field
151+ isn't in those interfaces, it isn't uploaded.
152+
153+ ### Controls
154+
155+ - Stop uploading: ` codetime token clear ` removes the token; hooks
156+ become no-ops without one.
157+ - Remove an existing machine and its rollups: ` codetime machine delete --id <id> ` .
158+ - Uninstall hooks: remove the files listed by ` codetime detect ` , or
159+ delete the codetime block from your agent's settings.
160+ - Self-host: point ` CODETIME_API_URL ` at your own ingest server.
161+
162+ ## Configuration
163+
164+ | Variable | Purpose | Default |
165+ | --- | --- | --- |
166+ | ` CODETIME_API_URL ` | Override API host. | ` https://codetime.dev ` |
167+ | ` CODETIME_TOKEN ` | Bearer token (same value as the upload token). | — |
168+ | ` CODETIME_DEBUG ` | Print verbose hook + import logs. | — |
169+
170+ Token precedence (highest first): ` --token ` flag → ` CODETIME_TOKEN ` env →
171+ saved config in ` ~/.codetime/config.json ` .
172+
173+ ## Repository layout
174+
175+ - ` packages/cli ` — the published ` codetime-cli ` npm package.
176+ - ` packages/shared ` — internal ` @codetime/shared ` types, inlined at build.
39177
40178## Development
41179
@@ -52,6 +190,13 @@ CODETIME_API_URL=http://localhost:3002 \
52190 tsx packages/cli/src/main.ts detect
53191```
54192
193+ Link the in-repo build globally:
194+
195+ ``` sh
196+ pnpm hooks:link # build + link as `codetime`
197+ pnpm hooks:unlink # undo
198+ ```
199+
55200## Publish
56201
57202``` sh
@@ -60,15 +205,8 @@ pnpm prepublishOnly # bundles shared into bin/codetime.mjs
60205pnpm publish
61206```
62207
63- ## Commands
208+ See ` scripts/release.sh ` for the automated release flow ( ` pnpm release ` ).
64209
65- - ` codetime detect ` — list supported local targets and install status.
66- - ` codetime install --target <id> ` — install integration files.
67- - ` codetime token set <token> ` — store the upload token.
68- - ` codetime hook --agent <name> ` — read hook JSON from stdin; used by
69- installed integrations, not invoked directly.
70- - ` codetime backfill plan|import --source <id> ` — import local agent
71- history.
72- - ` codetime machine ls|rename|delete ` — manage registered machines.
210+ ## License
73211
74- See ` packages/cli/src/cli.ts ` for the full command surface.
212+ [ MIT ] ( ./ packages/cli/package.json ) © codetime
0 commit comments