MCPcopy
hub / github.com/codeaashu/claude-code / getEventMetadata

Function getEventMetadata

src/services/analytics/metadata.ts:693–743  ·  view source on GitHub ↗
(
  options: EnrichMetadataOptions = {},
)

Source from the content-addressed store, hash-verified

691 * @returns Promise resolving to enriched metadata object
692 */
693export async function getEventMetadata(
694 options: EnrichMetadataOptions = {},
695): Promise<EventMetadata> {
696 const model = options.model ? String(options.model) : getMainLoopModel()
697 const betas =
698 typeof options.betas === 'string'
699 ? options.betas
700 : getModelBetas(model).join(',')
701 const [envContext, repoRemoteHash] = await Promise.all([
702 buildEnvContext(),
703 getRepoRemoteHash(),
704 ])
705 const processMetrics = buildProcessMetrics()
706
707 const metadata: EventMetadata = {
708 model,
709 sessionId: getSessionId(),
710 userType: process.env.USER_TYPE || '',
711 ...(betas.length > 0 ? { betas: betas } : {}),
712 envContext,
713 ...(process.env.CLAUDE_CODE_ENTRYPOINT && {
714 entrypoint: process.env.CLAUDE_CODE_ENTRYPOINT,
715 }),
716 ...(process.env.CLAUDE_AGENT_SDK_VERSION && {
717 agentSdkVersion: process.env.CLAUDE_AGENT_SDK_VERSION,
718 }),
719 isInteractive: String(getIsInteractive()),
720 clientType: getClientType(),
721 ...(processMetrics && { processMetrics }),
722 sweBenchRunId: process.env.SWE_BENCH_RUN_ID || '',
723 sweBenchInstanceId: process.env.SWE_BENCH_INSTANCE_ID || '',
724 sweBenchTaskId: process.env.SWE_BENCH_TASK_ID || '',
725 // Swarm/team agent identification
726 // Priority: AsyncLocalStorage context (subagents) > env vars (swarm teammates)
727 ...getAgentIdentification(),
728 // Subscription tier for DAU-by-tier analytics
729 ...(getSubscriptionType() && {
730 subscriptionType: getSubscriptionType()!,
731 }),
732 // Assistant mode tag — lives outside memoized buildEnvContext() because
733 // setKairosActive() runs at main.tsx:~1648, after the first event may
734 // have already fired and memoized the env. Read fresh per-event instead.
735 ...(feature('KAIROS') && getKairosActive()
736 ? { kairosActive: true as const }
737 : {}),
738 // Repo remote hash for joining with server-side repo bundle data
739 ...(repoRemoteHash && { rh: repoRemoteHash }),
740 }
741
742 return metadata
743}
744
745
746/**

Callers 2

logEventTo1PAsyncFunction · 0.85
trackDatadogEventFunction · 0.85

Calls 10

getMainLoopModelFunction · 0.85
getRepoRemoteHashFunction · 0.85
buildProcessMetricsFunction · 0.85
getSessionIdFunction · 0.85
getIsInteractiveFunction · 0.85
getClientTypeFunction · 0.85
getAgentIdentificationFunction · 0.85
getSubscriptionTypeFunction · 0.85
featureFunction · 0.85
getKairosActiveFunction · 0.85

Tested by

no test coverage detected