@revenium/claude-code-metering 0.1.0 → 0.1.2

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