spacehub

surshar / claude-code

Claude Code is an agentic coding tool that lives in your terminal, understands your codebase, and helps you code faster by executing routine tasks, explaining complex code, and handling git workflows - all through natural language commands.

Built by Anthropic · github.com/anthropics

claude-code / mods / telemetry / hooks / register.ts
47 lines · 1.7 KBRaw
1import type { On } from 'claude-code'
2
3import { telemetryOf } from './telemetry-of'
4
5/**
6 * Registers the plugin's one hook: its engine.create step adds
7 * `$.telemetry` over the nouns beneath, the plugin's own `$` as core built.
8 *
9 * `log` runs after the fold, reaching `$.session` and `$.http` through the
10 * nouns beneath; each is one call on them.
11 *
12 * @param on the engine's registrar
13 */
14export function register(on: On) {
15 on('engine.create', async ($, e, next) => {
16 const beneath = await next(e)
17
18 return {
19 ...beneath,
20 telemetry: telemetryOf({
21 authorize: () => beneath.session.authorize(),
22 id: () => beneath.session.id(),
23 model: () => beneath.session.model(),
24 environment: async () => ({
25 userType: await beneath.env.get('USER_TYPE'),
26 disableTelemetry: await beneath.env.get('DISABLE_TELEMETRY'),
27 disableNonessentialTraffic: await beneath.env.get(
28 'CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC',
29 ),
30 doNotTrack: await beneath.env.get('DO_NOT_TRACK'),
31 customOauthUrl: await beneath.env.get('CLAUDE_CODE_CUSTOM_OAUTH_URL'),
32 useBedrock: await beneath.env.get('CLAUDE_CODE_USE_BEDROCK'),
33 useVertex: await beneath.env.get('CLAUDE_CODE_USE_VERTEX'),
34 useFoundry: await beneath.env.get('CLAUDE_CODE_USE_FOUNDRY'),
35 useAnthropicAws: await beneath.env.get(
36 'CLAUDE_CODE_USE_ANTHROPIC_AWS',
37 ),
38 useAnthropicGoogleCloud: await beneath.env.get(
39 'CLAUDE_CODE_USE_ANTHROPIC_GOOGLE_CLOUD',
40 ),
41 useMantle: await beneath.env.get('CLAUDE_CODE_USE_MANTLE'),
42 }),
43 fetch: (url, init) => beneath.http.fetch(url, init),
44 }),
45 }
46 })
47}