@revenium/claude-code-metering 0.1.0
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.
- package/CHANGELOG.md +50 -0
- package/LICENSE +21 -0
- package/README.md +274 -0
- package/dist/cli/commands/backfill.d.ts +11 -0
- package/dist/cli/commands/backfill.d.ts.map +1 -0
- package/dist/cli/commands/backfill.js +390 -0
- package/dist/cli/commands/backfill.js.map +1 -0
- package/dist/cli/commands/setup.d.ts +13 -0
- package/dist/cli/commands/setup.d.ts.map +1 -0
- package/dist/cli/commands/setup.js +177 -0
- package/dist/cli/commands/setup.js.map +1 -0
- package/dist/cli/commands/status.d.ts +5 -0
- package/dist/cli/commands/status.d.ts.map +1 -0
- package/dist/cli/commands/status.js +95 -0
- package/dist/cli/commands/status.js.map +1 -0
- package/dist/cli/commands/test.d.ts +9 -0
- package/dist/cli/commands/test.d.ts.map +1 -0
- package/dist/cli/commands/test.js +67 -0
- package/dist/cli/commands/test.js.map +1 -0
- package/dist/cli/index.d.ts +3 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +65 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/core/api/client.d.ts +28 -0
- package/dist/core/api/client.d.ts.map +1 -0
- package/dist/core/api/client.js +127 -0
- package/dist/core/api/client.js.map +1 -0
- package/dist/core/config/loader.d.ts +35 -0
- package/dist/core/config/loader.d.ts.map +1 -0
- package/dist/core/config/loader.js +162 -0
- package/dist/core/config/loader.js.map +1 -0
- package/dist/core/config/validator.d.ts +19 -0
- package/dist/core/config/validator.d.ts.map +1 -0
- package/dist/core/config/validator.js +101 -0
- package/dist/core/config/validator.js.map +1 -0
- package/dist/core/config/writer.d.ts +11 -0
- package/dist/core/config/writer.d.ts.map +1 -0
- package/dist/core/config/writer.js +145 -0
- package/dist/core/config/writer.js.map +1 -0
- package/dist/core/shell/detector.d.ts +14 -0
- package/dist/core/shell/detector.d.ts.map +1 -0
- package/dist/core/shell/detector.js +69 -0
- package/dist/core/shell/detector.js.map +1 -0
- package/dist/core/shell/profile-updater.d.ts +11 -0
- package/dist/core/shell/profile-updater.d.ts.map +1 -0
- package/dist/core/shell/profile-updater.js +101 -0
- package/dist/core/shell/profile-updater.js.map +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +26 -0
- package/dist/index.js.map +1 -0
- package/dist/types/index.d.ts +96 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +3 -0
- package/dist/types/index.js.map +1 -0
- package/dist/utils/constants.d.ts +68 -0
- package/dist/utils/constants.d.ts.map +1 -0
- package/dist/utils/constants.js +73 -0
- package/dist/utils/constants.js.map +1 -0
- package/dist/utils/masking.d.ts +14 -0
- package/dist/utils/masking.d.ts.map +1 -0
- package/dist/utils/masking.js +33 -0
- package/dist/utils/masking.js.map +1 -0
- package/package.json +61 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
## [Unreleased]
|
|
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
|
|
11
|
+
|
|
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)
|
|
17
|
+
|
|
18
|
+
## [0.1.0] - 2026-01-05
|
|
19
|
+
|
|
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
|
|
23
|
+
|
|
24
|
+
### Added
|
|
25
|
+
- Interactive setup wizard (`revenium-metering setup`)
|
|
26
|
+
- Status check command (`revenium-metering status`)
|
|
27
|
+
- Test metric sender (`revenium-metering test`)
|
|
28
|
+
- Shell profile auto-detection (bash, zsh, fish)
|
|
29
|
+
- Subscription tier configuration (Pro, Max, Team, Enterprise, API)
|
|
30
|
+
- Cost multiplier calculation based on subscription tier
|
|
31
|
+
- Non-interactive mode with CLI flags
|
|
32
|
+
- Verbose output option for debugging
|
|
33
|
+
|
|
34
|
+
### Configuration
|
|
35
|
+
- Creates `~/.claude/revenium.env` with OTEL environment variables
|
|
36
|
+
- Automatic shell profile sourcing configuration
|
|
37
|
+
- Support for custom endpoints (for development/testing)
|
|
38
|
+
|
|
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
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Revenium, Inc.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
# @revenium/claude-code-metering
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@revenium/claude-code-metering)
|
|
4
|
+
[](https://nodejs.org/)
|
|
5
|
+
[](https://docs.revenium.io)
|
|
6
|
+
[](https://www.revenium.ai)
|
|
7
|
+
[](https://opensource.org/licenses/MIT)
|
|
8
|
+
|
|
9
|
+
**CLI tool for automatic Revenium usage tracking with Claude Code**
|
|
10
|
+
|
|
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.
|
|
12
|
+
|
|
13
|
+
## Features
|
|
14
|
+
|
|
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
|
|
21
|
+
|
|
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
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
npm install -g @revenium/claude-code-metering
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
Or use npx (no install required):
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
npx @revenium/claude-code-metering setup
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### 2. Run the Setup Wizard
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
revenium-metering setup
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
The wizard will prompt you for:
|
|
56
|
+
- **API Key**: Your Revenium API key (`hak_...`)
|
|
57
|
+
- **Email**: For usage attribution (optional)
|
|
58
|
+
- **Subscription Tier**: Your Claude Code subscription
|
|
59
|
+
|
|
60
|
+
### 3. Restart Your Terminal
|
|
61
|
+
|
|
62
|
+
The setup automatically updates your shell profile. Either:
|
|
63
|
+
- Open a new terminal, OR
|
|
64
|
+
- Run: `source ~/.claude/revenium.env`
|
|
65
|
+
|
|
66
|
+
### 4. Use Claude Code Normally
|
|
67
|
+
|
|
68
|
+
That's it! Telemetry will be sent to Revenium automatically when you use Claude Code.
|
|
69
|
+
|
|
70
|
+
---
|
|
71
|
+
|
|
72
|
+
## What Gets Tracked
|
|
73
|
+
|
|
74
|
+
The tool configures Claude Code to export the following via OpenTelemetry:
|
|
75
|
+
|
|
76
|
+
### **Usage Metrics**
|
|
77
|
+
|
|
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
|
|
82
|
+
|
|
83
|
+
### **Cost Attribution**
|
|
84
|
+
|
|
85
|
+
- **Subscription Tier** - Applied cost multiplier based on your plan
|
|
86
|
+
- **Email** - For per-developer attribution
|
|
87
|
+
- **Organization/Product IDs** - Optional business context
|
|
88
|
+
|
|
89
|
+
---
|
|
90
|
+
|
|
91
|
+
## API Overview
|
|
92
|
+
|
|
93
|
+
### Commands
|
|
94
|
+
|
|
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 |
|
|
100
|
+
|
|
101
|
+
### Setup Options
|
|
102
|
+
|
|
103
|
+
```bash
|
|
104
|
+
revenium-metering setup [options]
|
|
105
|
+
|
|
106
|
+
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
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
**Non-interactive mode (CI/CD):**
|
|
115
|
+
|
|
116
|
+
```bash
|
|
117
|
+
revenium-metering setup \
|
|
118
|
+
--api-key hak_your_key_here \
|
|
119
|
+
--email developer@company.com \
|
|
120
|
+
--tier pro
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
---
|
|
124
|
+
|
|
125
|
+
## Configuration
|
|
126
|
+
|
|
127
|
+
### Environment Variables
|
|
128
|
+
|
|
129
|
+
The setup creates `~/.claude/revenium.env` with:
|
|
130
|
+
|
|
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 |
|
|
139
|
+
|
|
140
|
+
### Subscription Tiers
|
|
141
|
+
|
|
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% |
|
|
150
|
+
|
|
151
|
+
### Optional: Organization & Product IDs
|
|
152
|
+
|
|
153
|
+
For business context tracking, you can set additional environment variables:
|
|
154
|
+
|
|
155
|
+
```bash
|
|
156
|
+
export REVENIUM_ORGANIZATION_ID=your-org-id
|
|
157
|
+
export REVENIUM_PRODUCT_ID=your-product-id
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
---
|
|
161
|
+
|
|
162
|
+
## Examples
|
|
163
|
+
|
|
164
|
+
**For complete examples and usage patterns, see [`examples/README.md`](https://github.com/revenium/revenium-claude-code-sdk/blob/HEAD/examples/README.md).**
|
|
165
|
+
|
|
166
|
+
### Quick Examples
|
|
167
|
+
|
|
168
|
+
```bash
|
|
169
|
+
# Interactive setup
|
|
170
|
+
revenium-metering setup
|
|
171
|
+
|
|
172
|
+
# Non-interactive (CI/CD)
|
|
173
|
+
revenium-metering setup --api-key hak_key --tier pro
|
|
174
|
+
|
|
175
|
+
# Check status
|
|
176
|
+
revenium-metering status
|
|
177
|
+
|
|
178
|
+
# Test the integration
|
|
179
|
+
revenium-metering test --verbose
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
---
|
|
183
|
+
|
|
184
|
+
## Troubleshooting
|
|
185
|
+
|
|
186
|
+
### Telemetry not appearing in Revenium
|
|
187
|
+
|
|
188
|
+
1. **Check configuration:**
|
|
189
|
+
```bash
|
|
190
|
+
revenium-metering status
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
2. **Verify environment variables are loaded:**
|
|
194
|
+
```bash
|
|
195
|
+
echo $OTEL_METRICS_EXPORTER # Should output: otlp
|
|
196
|
+
echo $CLAUDE_CODE_ENABLE_TELEMETRY # Should output: 1
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
3. **Send a test metric:**
|
|
200
|
+
```bash
|
|
201
|
+
revenium-metering test --verbose
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
4. **Restart your terminal** - environment variables only load in new sessions
|
|
205
|
+
|
|
206
|
+
### "API key validation failed"
|
|
207
|
+
|
|
208
|
+
- Verify your API key starts with `hak_`
|
|
209
|
+
- Check that the API key is active in your Revenium dashboard
|
|
210
|
+
- Ensure network connectivity to `api.revenium.ai`
|
|
211
|
+
|
|
212
|
+
### Shell profile not updated
|
|
213
|
+
|
|
214
|
+
Run setup with manual instructions:
|
|
215
|
+
```bash
|
|
216
|
+
revenium-metering setup --skip-shell-update
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
Then manually add to your shell profile:
|
|
220
|
+
|
|
221
|
+
**Bash/Zsh:**
|
|
222
|
+
```bash
|
|
223
|
+
[ -f ~/.claude/revenium.env ] && source ~/.claude/revenium.env
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
**Fish:**
|
|
227
|
+
```fish
|
|
228
|
+
if test -f ~/.claude/revenium.env
|
|
229
|
+
source ~/.claude/revenium.env
|
|
230
|
+
end
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
### Debug Mode
|
|
234
|
+
|
|
235
|
+
Enable detailed logging:
|
|
236
|
+
```bash
|
|
237
|
+
REVENIUM_DEBUG=true revenium-metering status
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
---
|
|
241
|
+
|
|
242
|
+
## Documentation
|
|
243
|
+
|
|
244
|
+
For detailed documentation, visit [docs.revenium.io](https://docs.revenium.io)
|
|
245
|
+
|
|
246
|
+
## Contributing
|
|
247
|
+
|
|
248
|
+
See [CONTRIBUTING.md](https://github.com/revenium/revenium-claude-code-sdk/blob/HEAD/CONTRIBUTING.md)
|
|
249
|
+
|
|
250
|
+
## Code of Conduct
|
|
251
|
+
|
|
252
|
+
See [CODE_OF_CONDUCT.md](https://github.com/revenium/revenium-claude-code-sdk/blob/HEAD/CODE_OF_CONDUCT.md)
|
|
253
|
+
|
|
254
|
+
## Security
|
|
255
|
+
|
|
256
|
+
See [SECURITY.md](https://github.com/revenium/revenium-claude-code-sdk/blob/HEAD/SECURITY.md)
|
|
257
|
+
|
|
258
|
+
## License
|
|
259
|
+
|
|
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.
|
|
261
|
+
|
|
262
|
+
## Support
|
|
263
|
+
|
|
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**
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export interface BackfillOptions {
|
|
2
|
+
since?: string;
|
|
3
|
+
dryRun?: boolean;
|
|
4
|
+
batchSize?: number;
|
|
5
|
+
verbose?: boolean;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Backfill command - imports historical Claude Code usage data.
|
|
9
|
+
*/
|
|
10
|
+
export declare function backfillCommand(options?: BackfillOptions): Promise<void>;
|
|
11
|
+
//# sourceMappingURL=backfill.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"backfill.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/backfill.ts"],"names":[],"mappings":"AAYA,MAAM,WAAW,eAAe;IAC9B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAgRD;;GAEG;AACH,wBAAsB,eAAe,CAAC,OAAO,GAAE,eAAoB,GAAG,OAAO,CAAC,IAAI,CAAC,CA8LlF"}
|