@revenium/claude-code-metering 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. package/CHANGELOG.md +22 -28
  2. package/README.md +321 -139
  3. package/dist/cli/commands/backfill.d.ts +98 -1
  4. package/dist/cli/commands/backfill.d.ts.map +1 -1
  5. package/dist/cli/commands/backfill.js +356 -146
  6. package/dist/cli/commands/backfill.js.map +1 -1
  7. package/dist/cli/commands/setup.d.ts +2 -0
  8. package/dist/cli/commands/setup.d.ts.map +1 -1
  9. package/dist/cli/commands/setup.js +55 -49
  10. package/dist/cli/commands/setup.js.map +1 -1
  11. package/dist/cli/commands/status.d.ts.map +1 -1
  12. package/dist/cli/commands/status.js +2 -11
  13. package/dist/cli/commands/status.js.map +1 -1
  14. package/dist/cli/commands/test.d.ts.map +1 -1
  15. package/dist/cli/commands/test.js +23 -22
  16. package/dist/cli/commands/test.js.map +1 -1
  17. package/dist/cli/index.d.ts +2 -1
  18. package/dist/cli/index.d.ts.map +1 -1
  19. package/dist/cli/index.js +44 -30
  20. package/dist/cli/index.js.map +1 -1
  21. package/dist/core/api/client.d.ts +7 -6
  22. package/dist/core/api/client.d.ts.map +1 -1
  23. package/dist/core/api/client.js +52 -47
  24. package/dist/core/api/client.js.map +1 -1
  25. package/dist/core/config/loader.d.ts +5 -13
  26. package/dist/core/config/loader.d.ts.map +1 -1
  27. package/dist/core/config/loader.js +67 -46
  28. package/dist/core/config/loader.js.map +1 -1
  29. package/dist/core/config/validator.d.ts +5 -1
  30. package/dist/core/config/validator.d.ts.map +1 -1
  31. package/dist/core/config/validator.js +37 -22
  32. package/dist/core/config/validator.js.map +1 -1
  33. package/dist/core/config/writer.d.ts +1 -1
  34. package/dist/core/config/writer.d.ts.map +1 -1
  35. package/dist/core/config/writer.js +76 -72
  36. package/dist/core/config/writer.js.map +1 -1
  37. package/dist/core/shell/detector.d.ts +8 -1
  38. package/dist/core/shell/detector.d.ts.map +1 -1
  39. package/dist/core/shell/detector.js +38 -24
  40. package/dist/core/shell/detector.js.map +1 -1
  41. package/dist/core/shell/profile-updater.d.ts +1 -1
  42. package/dist/core/shell/profile-updater.d.ts.map +1 -1
  43. package/dist/core/shell/profile-updater.js +40 -27
  44. package/dist/core/shell/profile-updater.js.map +1 -1
  45. package/dist/index.d.ts +9 -8
  46. package/dist/index.d.ts.map +1 -1
  47. package/dist/index.js +1 -0
  48. package/dist/index.js.map +1 -1
  49. package/dist/types/index.d.ts +18 -23
  50. package/dist/types/index.d.ts.map +1 -1
  51. package/dist/utils/constants.d.ts +2 -2
  52. package/dist/utils/constants.d.ts.map +1 -1
  53. package/dist/utils/constants.js +21 -21
  54. package/dist/utils/constants.js.map +1 -1
  55. package/dist/utils/hashing.d.ts +18 -0
  56. package/dist/utils/hashing.d.ts.map +1 -0
  57. package/dist/utils/hashing.js +27 -0
  58. package/dist/utils/hashing.js.map +1 -0
  59. package/package.json +6 -3
package/CHANGELOG.md CHANGED
@@ -4,47 +4,41 @@ All notable changes to this project will be documented in this file.
4
4
 
5
5
  ## [Unreleased]
6
6
 
7
- ### Changed
8
- - **BREAKING**: Changed from `OTEL_LOGS_EXPORTER` to `OTEL_METRICS_EXPORTER` in generated config
9
- - If you have an existing `~/.claude/revenium.env`, run `revenium-metering setup` to regenerate it
10
- - The `status` command now detects old configs and warns about migration
7
+ ## [0.1.1] - 2026-01-21
11
8
 
12
- ### Added
13
- - SDK standardization files (LICENSE, SECURITY.md, CONTRIBUTING.md, CODE_OF_CONDUCT.md, CHANGELOG.md)
14
- - Examples directory with usage samples
15
- - Migration detection in `status` command to identify outdated configurations
16
- - Unit tests for config content generation (OTEL exporter type validation)
9
+ ### Fixed
17
10
 
18
- ## [0.1.0] - 2026-01-05
11
+ - Corrected OTLP endpoint path from `/meter/v2/otel` to `/meter/v2/otlp`
12
+ - Changed payload format from OTEL Metrics to OTLP Logs for correct backend compatibility
13
+ - Updated endpoint URL from `/v1/metrics` to `/v1/logs`
14
+ - Fixed response field from `processedMetrics` to `processedEvents`
19
15
 
20
- ### Fixed
21
- - Changed OTEL endpoint from `/meter/v2/ai/otlp/v1/logs` to `/meter/v2/otel/v1/metrics` (PR #3)
22
- - Changed payload format from OTEL Logs to OTEL Metrics for correct API compatibility
16
+ ### Changed
17
+
18
+ - Updated minimum Node.js version from 18.0.0 to 20.0.0
19
+ - Migrated from OTEL Metrics format to OTLP Logs format
20
+ - Updated test payload structure to match ClaudeCodeMapper backend expectations
21
+ - Added email field support in test payloads for subscriber attribution
23
22
 
24
23
  ### Added
24
+
25
+ - New `hashing.ts` utility module for transaction ID generation
26
+ - Support for `user.email` attribute in log records
27
+ - Improved error message truncation (max 200 chars) for better readability
28
+ - SDK standardization files (LICENSE, SECURITY.md, CONTRIBUTING.md, CODE_OF_CONDUCT.md)
29
+ - Examples directory with usage samples
25
30
  - Interactive setup wizard (`revenium-metering setup`)
26
31
  - Status check command (`revenium-metering status`)
27
32
  - Test metric sender (`revenium-metering test`)
33
+ - Backfill command for historical data import (`revenium-metering backfill`)
28
34
  - Shell profile auto-detection (bash, zsh, fish)
29
35
  - Subscription tier configuration (Pro, Max, Team, Enterprise, API)
30
36
  - Cost multiplier calculation based on subscription tier
31
37
  - Non-interactive mode with CLI flags
32
38
  - Verbose output option for debugging
33
-
34
- ### Configuration
35
- - Creates `~/.claude/revenium.env` with OTEL environment variables
39
+ - Creates `~/.claude/revenium.env` with OTLP environment variables
36
40
  - Automatic shell profile sourcing configuration
37
41
  - Support for custom endpoints (for development/testing)
38
42
 
39
- ### Supported Tiers
40
- | Tier | Cost Multiplier | Effective Discount |
41
- |------|-----------------|-------------------|
42
- | Pro | 0.16 | 84% |
43
- | Max 5x | 0.16 | 84% |
44
- | Max 20x | 0.08 | 92% |
45
- | Team Premium | 0.24 | 76% |
46
- | Enterprise | 0.05 | 95% |
47
- | API | 1.0 | 0% |
48
-
49
- [Unreleased]: https://github.com/revenium/revenium-claude-code-metering/compare/v0.1.0...HEAD
50
- [0.1.0]: https://github.com/revenium/revenium-claude-code-metering/releases/tag/v0.1.0
43
+ [Unreleased]: https://github.com/revenium/revenium-claude-code-sdk/compare/v0.1.1...HEAD
44
+ [0.1.1]: https://github.com/revenium/revenium-claude-code-sdk/releases/tag/v0.1.1
package/README.md CHANGED
@@ -1,202 +1,373 @@
1
1
  # @revenium/claude-code-metering
2
2
 
3
- [![npm version](https://img.shields.io/npm/v/@revenium/claude-code-metering.svg)](https://www.npmjs.com/package/@revenium/claude-code-metering)
4
- [![Node.js](https://img.shields.io/badge/Node.js-18%2B-green)](https://nodejs.org/)
5
- [![Documentation](https://img.shields.io/badge/docs-revenium.io-blue)](https://docs.revenium.io)
6
- [![Website](https://img.shields.io/badge/website-revenium.ai-blue)](https://www.revenium.ai)
7
- [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
3
+ [![Node.js](https://img.shields.io/badge/node-%3E%3D20.0.0-brightgreen)](https://nodejs.org)
4
+ [![License](https://img.shields.io/badge/license-MIT-blue)](LICENSE)
8
5
 
9
- **CLI tool for automatic Revenium usage tracking with Claude Code**
6
+ A CLI tool to configure Claude Code telemetry export to Revenium for AI usage metering and cost tracking.
10
7
 
11
- A professional-grade CLI tool that configures Claude Code to export OpenTelemetry (OTLP) telemetry data to Revenium's metering infrastructure. Enables usage tracking, cost attribution, and subscription optimization for Claude Code API calls.
8
+ ## Overview
12
9
 
13
- ## Features
10
+ This package configures Claude Code CLI to export OpenTelemetry (OTLP) telemetry data to Revenium's metering infrastructure. This enables:
14
11
 
15
- - **Zero-Code Integration** - Simple CLI setup, no code changes required
16
- - **Automatic Tracking** - Captures all Claude Code API calls automatically via OTLP
17
- - **Cost Attribution** - Track AI spend per developer, team, or project
18
- - **Subscription Tiers** - Apply subscription discounts (Pro, Max, Enterprise) to cost calculations
19
- - **Shell Integration** - Automatic shell profile configuration (Bash, Zsh, Fish)
20
- - **Non-Interactive Mode** - CI/CD friendly with command-line options
12
+ - **Usage Tracking**: Monitor Claude Code API calls, token counts, and model usage
13
+ - **Cost Attribution**: Track AI spend per developer, team, or project
14
+ - **Subscription Optimization**: Apply subscription discounts (Pro/Max/Enterprise) to cost calculations
21
15
 
22
- ## Prerequisites
23
-
24
- **Before starting, you'll need:**
25
-
26
- 1. **Node.js 18+** - [Download](https://nodejs.org/)
27
- 2. **Claude Code CLI** - [Installation guide](https://docs.anthropic.com/en/docs/claude-code)
28
- 3. **Revenium API Key** - Obtain from [app.revenium.ai](https://app.revenium.ai):
29
- - Sign up or log in
30
- - Navigate to **Settings → API Keys**
31
- - Create a new API key (starts with `hak_`)
32
-
33
- ---
34
-
35
- ## Getting Started
36
-
37
- ### 1. Install the Package
16
+ ## Installation
38
17
 
39
18
  ```bash
40
19
  npm install -g @revenium/claude-code-metering
41
20
  ```
42
21
 
43
- Or use npx (no install required):
22
+ Or with npx (no install required):
44
23
 
45
24
  ```bash
46
25
  npx @revenium/claude-code-metering setup
47
26
  ```
48
27
 
49
- ### 2. Run the Setup Wizard
28
+ ## Quick Start
29
+
30
+ ### 1. Run the Setup Wizard
50
31
 
51
32
  ```bash
52
33
  revenium-metering setup
53
34
  ```
54
35
 
55
36
  The wizard will prompt you for:
37
+
56
38
  - **API Key**: Your Revenium API key (`hak_...`)
57
39
  - **Email**: For usage attribution (optional)
58
- - **Subscription Tier**: Your Claude Code subscription
40
+ - **Subscription Tier**: Your Claude Code subscription (Pro, Max, Team, Enterprise, or API)
59
41
 
60
- ### 3. Restart Your Terminal
42
+ ### 2. Restart Your Terminal
61
43
 
62
44
  The setup automatically updates your shell profile. Either:
45
+
63
46
  - Open a new terminal, OR
64
47
  - Run: `source ~/.claude/revenium.env`
65
48
 
66
- ### 4. Use Claude Code Normally
49
+ ### 3. Use Claude Code Normally
67
50
 
68
51
  That's it! Telemetry will be sent to Revenium automatically when you use Claude Code.
69
52
 
70
- ---
53
+ > **Using an IDE?** If you use Claude Code through VS Code, Cursor, Windsurf, or JetBrains IDEs, see [IDE Configuration](#ide-configuration) for additional setup steps.
71
54
 
72
- ## What Gets Tracked
55
+ ## Commands
73
56
 
74
- The tool configures Claude Code to export the following via OpenTelemetry:
57
+ ### `revenium-metering setup`
75
58
 
76
- ### **Usage Metrics**
59
+ Interactive setup wizard to configure Claude Code metering.
77
60
 
78
- - **Session ID** - Unique identifier for each Claude Code session
79
- - **Model Information** - Model used (claude-opus-4-5, claude-sonnet-4, etc.)
80
- - **Token Counts** - Input tokens, output tokens, cache read/creation tokens
81
- - **Request Timing** - Request timestamps
61
+ ```bash
62
+ revenium-metering setup [options]
82
63
 
83
- ### **Cost Attribution**
64
+ Options:
65
+ -k, --api-key <key> Revenium API key (hak_...)
66
+ -e, --email <email> Email for usage attribution
67
+ -t, --tier <tier> Subscription tier (pro, max_5x, max_20x, team_premium, enterprise, api)
68
+ -o, --organization <name> Organization name for cost attribution
69
+ -p, --product <name> Product name for cost attribution
70
+ --endpoint <url> Revenium API endpoint URL (default: https://api.revenium.ai)
71
+ --skip-shell-update Skip automatic shell profile update
72
+ ```
84
73
 
85
- - **Subscription Tier** - Applied cost multiplier based on your plan
86
- - **Email** - For per-developer attribution
87
- - **Organization/Product IDs** - Optional business context
74
+ **Non-interactive mode:**
88
75
 
89
- ---
76
+ ```bash
77
+ revenium-metering setup \
78
+ --api-key hak_your_key_here \
79
+ --email developer@company.com \
80
+ --tier pro
90
81
 
91
- ## API Overview
82
+ # With organization and product attribution:
83
+ revenium-metering setup \
84
+ --api-key hak_your_key_here \
85
+ --email developer@company.com \
86
+ --tier pro \
87
+ --organization my-team \
88
+ --product backend-api
89
+ ```
90
+
91
+ ### `revenium-metering status`
92
+
93
+ Check current configuration and endpoint connectivity.
94
+
95
+ ```bash
96
+ revenium-metering status
97
+ ```
92
98
 
93
- ### Commands
99
+ Outputs:
94
100
 
95
- | Command | Description |
96
- |---------|-------------|
97
- | `revenium-metering setup` | Interactive configuration wizard |
98
- | `revenium-metering status` | Check current configuration and connectivity |
99
- | `revenium-metering test` | Send test metric to verify integration |
101
+ - Current configuration settings
102
+ - Endpoint health check
103
+ - Authentication status
100
104
 
101
- ### Setup Options
105
+ ### `revenium-metering test`
106
+
107
+ Send a test metric to verify the integration is working.
102
108
 
103
109
  ```bash
104
- revenium-metering setup [options]
110
+ revenium-metering test [options]
105
111
 
106
112
  Options:
107
- -k, --api-key <key> Revenium API key (hak_...)
108
- -e, --email <email> Email for usage attribution
109
- -t, --tier <tier> Subscription tier
110
- --endpoint <url> Revenium API endpoint (default: https://api.revenium.ai)
111
- --skip-shell-update Skip automatic shell profile update
113
+ -v, --verbose Show detailed payload information
112
114
  ```
113
115
 
114
- **Non-interactive mode (CI/CD):**
116
+ ### `revenium-metering backfill`
117
+
118
+ Import historical Claude Code usage data from local JSONL files stored in `~/.claude/projects/`. This is useful for sending past usage to Revenium when you first set up metering.
115
119
 
116
120
  ```bash
117
- revenium-metering setup \
118
- --api-key hak_your_key_here \
119
- --email developer@company.com \
120
- --tier pro
121
+ revenium-metering backfill [options]
122
+
123
+ Options:
124
+ --since <date> Only backfill records after this date
125
+ --dry-run Show what would be sent without actually sending
126
+ --batch-size <n> Records per API batch (default: 100)
127
+ -v, --verbose Show detailed progress and sample payloads
121
128
  ```
122
129
 
123
- ---
130
+ **Date formats for `--since`:**
124
131
 
125
- ## Configuration
132
+ - Relative: `7d` (7 days), `2w` (2 weeks), `1m` (1 month), `1y` (1 year)
133
+ - ISO format: `2024-01-15` or `2024-01-15T00:00:00Z`
126
134
 
127
- ### Environment Variables
135
+ **Examples:**
128
136
 
129
- The setup creates `~/.claude/revenium.env` with:
137
+ ```bash
138
+ # Preview what would be sent (recommended first step)
139
+ revenium-metering backfill --dry-run
140
+
141
+ # Backfill only the last 30 days
142
+ revenium-metering backfill --since 30d
143
+
144
+ # Backfill since a specific date with verbose output
145
+ revenium-metering backfill --since 2024-12-01 --verbose
146
+
147
+ # Full backfill of all historical data
148
+ revenium-metering backfill
149
+ ```
130
150
 
131
- | Variable | Description |
132
- |----------|-------------|
133
- | `CLAUDE_CODE_ENABLE_TELEMETRY` | Enables Claude Code telemetry export (`1`) |
134
- | `OTEL_EXPORTER_OTLP_ENDPOINT` | Revenium OTLP endpoint URL |
135
- | `OTEL_EXPORTER_OTLP_HEADERS` | Authentication header with API key |
136
- | `OTEL_EXPORTER_OTLP_PROTOCOL` | OTLP protocol (`http/json`) |
137
- | `OTEL_METRICS_EXPORTER` | Set to `otlp` to enable metrics export |
138
- | `OTEL_RESOURCE_ATTRIBUTES` | Cost multiplier based on subscription tier |
151
+ **What it does:**
152
+
153
+ 1. Scans `~/.claude/projects/` for JSONL session files
154
+ 2. Extracts usage records (model, tokens, timestamps) from assistant messages
155
+ 3. Batches records and sends them to Revenium's OTLP endpoint
156
+ 4. Applies your configured subscription tier's cost multiplier
157
+
158
+ ## Configuration
159
+
160
+ The setup wizard creates `~/.claude/revenium.env` with the following environment variables:
161
+
162
+ | Variable | Description |
163
+ | ------------------------------ | ---------------------------------------------------------------------------------- |
164
+ | `CLAUDE_CODE_ENABLE_TELEMETRY` | Enables Claude Code telemetry export (set to `1`) |
165
+ | `OTEL_EXPORTER_OTLP_ENDPOINT` | Revenium OTLP endpoint URL |
166
+ | `OTEL_EXPORTER_OTLP_HEADERS` | Authentication header with API key |
167
+ | `OTEL_EXPORTER_OTLP_PROTOCOL` | OTLP protocol (`http/json`) |
168
+ | `OTEL_LOGS_EXPORTER` | **Required** - Set to `otlp` to enable log export |
169
+ | `OTEL_RESOURCE_ATTRIBUTES` | Comma-separated key=value pairs (cost_multiplier, organization.name, product.name) |
139
170
 
140
171
  ### Subscription Tiers
141
172
 
142
- | Tier | Monthly Cost | Cost Multiplier | Effective Discount |
143
- |------|-------------|-----------------|-------------------|
144
- | Pro | $20/mo | 0.16 | 84% |
145
- | Max 5x | $100/mo | 0.16 | 84% |
146
- | Max 20x | $200/mo | 0.08 | 92% |
147
- | Team Premium | $150/seat | 0.24 | 76% |
148
- | Enterprise | Custom | 0.05 | 95% |
149
- | API (no subscription) | Pay-per-token | 1.0 | 0% |
173
+ | Tier | Monthly Cost | Cost Multiplier | Effective Discount |
174
+ | --------------------- | ------------- | --------------- | ------------------ |
175
+ | Pro | $20/mo | 0.16 | 84% |
176
+ | Max 5x | $100/mo | 0.16 | 84% |
177
+ | Max 20x | $200/mo | 0.08 | 92% |
178
+ | Team Premium | $150/seat | 0.24 | 76% |
179
+ | Enterprise | Custom | 0.05 | 95% |
180
+ | API (no subscription) | Pay-per-token | 1.0 | 0% |
181
+
182
+ #### How Cost Multipliers Are Calculated
183
+
184
+ The cost multiplier represents the effective cost as a percentage of API pricing. These values are **estimates based on fully consuming the monthly token allotment** for each tier compared to API costs for the same usage.
185
+
186
+ **Calculation Basis:** The Max 20x tier provides real usage data as the baseline.
187
+
188
+ - Max 20x: $200 for 20X tokens → $2,500 API equivalent → **$125 per X tokens** at API rates
189
+
190
+ Using this baseline, other tiers are calculated:
191
+
192
+ - **Pro**: $20 for X tokens → $20 / $125 = 0.16 (84% discount)
193
+ - **Max 5x**: $100 for 5X tokens → $100 / $625 = 0.16 (84% discount)
194
+ - **Max 20x**: $200 for 20X tokens → $200 / $2,500 = 0.08 (92% discount - best value per dollar)
195
+ - **Team Premium**: $150 for 5X tokens → $150 / $625 = 0.24 (76% discount)
196
+ - **Enterprise**: Custom pricing with negotiated discounts = 0.05 (95% discount)
197
+
198
+ **Key Insight:** Higher tiers provide better value per dollar. Max 20x offers 4x the usage of Max 5x for only 2x the cost, resulting in a better discount (92% vs 84%).
199
+
200
+ #### Manual Cost Multiplier Override
201
+
202
+ If you want to use a custom cost multiplier instead of the tier defaults, you can manually edit `~/.claude/revenium.env` after running setup:
203
+
204
+ 1. Run the setup wizard first:
205
+
206
+ ```bash
207
+ revenium-metering setup
208
+ ```
209
+
210
+ 2. Edit `~/.claude/revenium.env` and add/modify the cost multiplier:
211
+
212
+ ```bash
213
+ # Add this line with your custom multiplier (e.g., 0.12 for 88% discount)
214
+ export CLAUDE_CODE_COST_MULTIPLIER=0.12
215
+ ```
216
+
217
+ 3. Update the `OTEL_RESOURCE_ATTRIBUTES` line to use your custom value:
218
+
219
+ ```bash
220
+ export OTEL_RESOURCE_ATTRIBUTES="cost_multiplier=0.12"
221
+ ```
222
+
223
+ 4. Reload your environment:
224
+ ```bash
225
+ source ~/.claude/revenium.env
226
+ ```
150
227
 
151
- ### Optional: Organization & Product IDs
228
+ This allows you to set custom discount rates based on negotiated pricing or internal cost allocation policies.
152
229
 
153
- For business context tracking, you can set additional environment variables:
230
+ ### Organization & Product Attribution
231
+
232
+ You can attribute Claude Code costs to specific organizations (customers/teams) and products (projects). This is useful for:
233
+
234
+ - **Consulting firms**: Track AI costs per client project
235
+ - **Internal teams**: Separate costs by product (mobile-app, backend-api, etc.)
236
+ - **Cost centers**: Attribute AI spend to business units
237
+
238
+ #### Option 1: Use CLI Flags (Recommended)
154
239
 
155
240
  ```bash
156
- export REVENIUM_ORGANIZATION_ID=your-org-id
157
- export REVENIUM_PRODUCT_ID=your-product-id
241
+ revenium-metering setup \
242
+ --api-key hak_your_key \
243
+ --tier max_20x \
244
+ --organization engineering \
245
+ --product backend-api
158
246
  ```
159
247
 
160
- ---
248
+ #### Option 2: Edit OTEL_RESOURCE_ATTRIBUTES Directly
249
+
250
+ Add `organization.name` and/or `product.name` to the `OTEL_RESOURCE_ATTRIBUTES` line in `~/.claude/revenium.env`:
251
+
252
+ ```bash
253
+ # Before:
254
+ export OTEL_RESOURCE_ATTRIBUTES="cost_multiplier=0.08"
255
+
256
+ # After:
257
+ export OTEL_RESOURCE_ATTRIBUTES="cost_multiplier=0.08,organization.name=engineering,product.name=backend-api"
258
+ ```
259
+
260
+ Then reload: `source ~/.claude/revenium.env`
261
+
262
+ > **Important**: The backend **only** reads `organization.name` and `product.name` from `OTEL_RESOURCE_ATTRIBUTES`. Do not set them as standalone environment variables - they will not be sent to Revenium.
263
+
264
+ ## How It Works
161
265
 
162
- ## Examples
266
+ 1. **Claude Code CLI** exports OTLP telemetry when configured with the proper environment variables
267
+ 2. **This package** generates the configuration file (`~/.claude/revenium.env`) with the correct settings
268
+ 3. **Revenium's OTLP endpoint** (`/meter/v2/ai/otlp/v1/logs`) receives and translates the telemetry
269
+ 4. **Revenium** processes the data for cost tracking, attribution, and analytics
163
270
 
164
- **For complete examples and usage patterns, see [`examples/README.md`](https://github.com/revenium/revenium-claude-code-sdk/blob/HEAD/examples/README.md).**
271
+ ### Telemetry Data
165
272
 
166
- ### Quick Examples
273
+ Claude Code exports the following data points:
274
+
275
+ - Session ID
276
+ - Model used (claude-opus-4-5, claude-sonnet-4, etc.)
277
+ - Input token count
278
+ - Output token count
279
+ - Cache read/creation tokens
280
+ - Request timestamps
281
+
282
+ ## Manual Configuration
283
+
284
+ If automatic shell profile update fails, add this line to your shell profile:
285
+
286
+ **Bash** (`~/.bashrc` or `~/.bash_profile`):
167
287
 
168
288
  ```bash
169
- # Interactive setup
170
- revenium-metering setup
289
+ [ -f ~/.claude/revenium.env ] && source ~/.claude/revenium.env
290
+ ```
171
291
 
172
- # Non-interactive (CI/CD)
173
- revenium-metering setup --api-key hak_key --tier pro
292
+ **Zsh** (`~/.zshrc`):
174
293
 
175
- # Check status
176
- revenium-metering status
294
+ ```zsh
295
+ [ -f ~/.claude/revenium.env ] && source ~/.claude/revenium.env
296
+ ```
297
+
298
+ **Fish** (`~/.config/fish/config.fish`):
299
+
300
+ ```fish
301
+ if test -f ~/.claude/revenium.env
302
+ source ~/.claude/revenium.env
303
+ end
304
+ ```
305
+
306
+ ## IDE Configuration
307
+
308
+ If you use Claude Code through an IDE's integrated terminal, the shell profile configuration from `revenium-metering setup` should work automatically - just restart your IDE.
309
+
310
+ If telemetry isn't working, configure the environment variables directly in your IDE:
311
+
312
+ ### VS Code, Cursor, Windsurf (and other VS Code-based editors)
177
313
 
178
- # Test the integration
179
- revenium-metering test --verbose
314
+ Add to your `settings.json` (use `terminal.integrated.env.windows` or `.linux` as needed):
315
+
316
+ ```json
317
+ {
318
+ "terminal.integrated.env.osx": {
319
+ "CLAUDE_CODE_ENABLE_TELEMETRY": "1",
320
+ "OTEL_LOGS_EXPORTER": "otlp",
321
+ "OTEL_EXPORTER_OTLP_ENDPOINT": "https://api.revenium.ai/meter/v2/otlp",
322
+ "OTEL_EXPORTER_OTLP_HEADERS": "x-api-key=hak_YOUR_API_KEY_HERE",
323
+ "OTEL_EXPORTER_OTLP_PROTOCOL": "http/json",
324
+ "OTEL_RESOURCE_ATTRIBUTES": "cost_multiplier=0.08,organization.name=my-org,product.name=my-product"
325
+ }
326
+ }
180
327
  ```
181
328
 
182
- ---
329
+ > **Note**: Include `organization.name` and `product.name` in `OTEL_RESOURCE_ATTRIBUTES` if you want cost attribution. See [Organization & Product Attribution](#organization--product-attribution).
330
+
331
+ **Tip:** Run `revenium-metering setup` first, then copy the values from `~/.claude/revenium.env`.
332
+
333
+ ### JetBrains IDEs
334
+
335
+ Go to **Settings** > **Tools** > **Terminal** > **Environment variables** and add the same variables in semicolon-separated format.
336
+
337
+ ### Other IDEs
338
+
339
+ Configure these environment variables in your IDE's terminal settings:
340
+
341
+ | Variable | Value |
342
+ | ------------------------------ | ----------------------------------------------------------------------- |
343
+ | `CLAUDE_CODE_ENABLE_TELEMETRY` | `1` |
344
+ | `OTEL_LOGS_EXPORTER` | `otlp` |
345
+ | `OTEL_EXPORTER_OTLP_ENDPOINT` | `https://api.revenium.ai/meter/v2/otlp` |
346
+ | `OTEL_EXPORTER_OTLP_HEADERS` | `x-api-key=hak_YOUR_API_KEY` |
347
+ | `OTEL_EXPORTER_OTLP_PROTOCOL` | `http/json` |
348
+ | `OTEL_RESOURCE_ATTRIBUTES` | `cost_multiplier=0.08,organization.name=my-org,product.name=my-product` |
349
+
350
+ See [Subscription Tiers](#subscription-tiers) for cost multiplier values and [Organization & Product Attribution](#organization--product-attribution) for attribution options.
183
351
 
184
352
  ## Troubleshooting
185
353
 
186
354
  ### Telemetry not appearing in Revenium
187
355
 
188
356
  1. **Check configuration:**
357
+
189
358
  ```bash
190
359
  revenium-metering status
191
360
  ```
192
361
 
193
362
  2. **Verify environment variables are loaded:**
363
+
194
364
  ```bash
195
- echo $OTEL_METRICS_EXPORTER # Should output: otlp
365
+ echo $OTEL_LOGS_EXPORTER # Should output: otlp
196
366
  echo $CLAUDE_CODE_ENABLE_TELEMETRY # Should output: 1
197
367
  ```
198
368
 
199
369
  3. **Send a test metric:**
370
+
200
371
  ```bash
201
372
  revenium-metering test --verbose
202
373
  ```
@@ -211,64 +382,75 @@ revenium-metering test --verbose
211
382
 
212
383
  ### Shell profile not updated
213
384
 
214
- Run setup with manual instructions:
385
+ Run the setup with manual instructions:
386
+
215
387
  ```bash
216
388
  revenium-metering setup --skip-shell-update
217
389
  ```
218
390
 
219
- Then manually add to your shell profile:
391
+ Then manually add the source line to your shell profile.
392
+
393
+ ## Local Development Testing
394
+
395
+ For testing against local Revenium infrastructure:
220
396
 
221
- **Bash/Zsh:**
222
397
  ```bash
223
- [ -f ~/.claude/revenium.env ] && source ~/.claude/revenium.env
398
+ revenium-metering setup \
399
+ --api-key hak_your_test_key \
400
+ --endpoint http://localhost:8082 \
401
+ --tier pro
224
402
  ```
225
403
 
226
- **Fish:**
227
- ```fish
228
- if test -f ~/.claude/revenium.env
229
- source ~/.claude/revenium.env
230
- end
231
- ```
404
+ Note: The local metering service must be running on port 8082 with Kafka connectivity.
405
+
406
+ ## Requirements
407
+
408
+ - Node.js >= 20.0.0
409
+ - Claude Code CLI installed
410
+ - Revenium API key (obtain from app.revenium.ai)
232
411
 
233
- ### Debug Mode
412
+ ## Development
413
+
414
+ ### Running Tests
234
415
 
235
- Enable detailed logging:
236
416
  ```bash
237
- REVENIUM_DEBUG=true revenium-metering status
417
+ npm test
418
+ npm test -- --coverage
238
419
  ```
239
420
 
240
- ---
421
+ ### CI/CD
241
422
 
242
- ## Documentation
423
+ This project uses GitHub Actions for continuous integration. The CI pipeline runs on every push and pull request to `main`:
243
424
 
244
- For detailed documentation, visit [docs.revenium.io](https://docs.revenium.io)
425
+ **Test Matrix:**
245
426
 
246
- ## Contributing
427
+ - Node.js 20.x (LTS)
428
+ - Linting with ESLint
429
+ - TypeScript compilation
430
+ - Unit and integration tests with coverage
247
431
 
248
- See [CONTRIBUTING.md](https://github.com/revenium/revenium-claude-code-sdk/blob/HEAD/CONTRIBUTING.md)
432
+ **Coverage Requirements:**
249
433
 
250
- ## Code of Conduct
434
+ The CI enforces minimum coverage thresholds via Vitest:
251
435
 
252
- See [CODE_OF_CONDUCT.md](https://github.com/revenium/revenium-claude-code-sdk/blob/HEAD/CODE_OF_CONDUCT.md)
436
+ - `backfill.ts`: >80%
437
+ - `setup.ts`: >80%
438
+ - `detector.ts`: >80%
439
+ - `profile-updater.ts`: >80%
253
440
 
254
- ## Security
441
+ The CI will fail if:
255
442
 
256
- See [SECURITY.md](https://github.com/revenium/revenium-claude-code-sdk/blob/HEAD/SECURITY.md)
443
+ - Linting errors are found
444
+ - TypeScript compilation fails
445
+ - Any test fails
446
+ - Coverage thresholds are not met
257
447
 
258
448
  ## License
259
449
 
260
- This project is licensed under the MIT License - see the [LICENSE](https://github.com/revenium/revenium-claude-code-sdk/blob/HEAD/LICENSE) file for details.
450
+ MIT
261
451
 
262
452
  ## Support
263
453
 
264
- For issues, feature requests, or contributions:
265
-
266
- - **Website**: [www.revenium.ai](https://www.revenium.ai)
267
- - **GitHub Repository**: [revenium/revenium-claude-code-sdk](https://github.com/revenium/revenium-claude-code-sdk)
268
- - **Issues**: [Report bugs or request features](https://github.com/revenium/revenium-claude-code-sdk/issues)
269
- - **Documentation**: [docs.revenium.io](https://docs.revenium.io)
270
- - **Email**: support@revenium.io
271
-
272
- ---
273
-
274
- **Built by Revenium**
454
+ - Issues: https://github.com/revenium/revenium-claude-code-sdk-internal/issues
455
+ - Documentation: https://docs.revenium.ai
456
+ - Dashboard: https://app.revenium.ai