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 / context / environment-fields-of / environment-fields-of.ts
60 lines · 2.4 KBRaw
1import Deployment from '../../deployment'
2import IsAnalyticsOff from '../../is-analytics-off'
3import type { EnvironmentFields } from '../environment-fields'
4import type { Probe } from '../probe'
5import { shellOf } from '../shell-of'
6import { terminalOf } from '../terminal-of'
7import { actionRefOf } from './action-ref-of'
8import { githubActionsFieldsOf } from './github-actions-fields-of'
9import { tagsOf } from './tags-of'
10
11/**
12 * The rows' `env` block from what was probed, valued as the CLI's own is;
13 * the GitHub Actions fields only inside a workflow, the Linux ones on Linux.
14 *
15 * @param probe what was gathered for the session
16 * @returns the block
17 */
18export function environmentFieldsOf(probe: Probe): EnvironmentFields {
19 const { facts, machine, platform } = probe
20 const isGithubAction = IsAnalyticsOff.isEnvTruthy(facts.githubActions)
21 const isLinux = machine.platformRaw === 'linux'
22
23 return {
24 platform,
25 platformRaw: machine.platformRaw,
26 arch: machine.arch,
27 terminal: terminalOf(facts, platform, probe.isInteractive),
28 shell: shellOf(facts.shellPath),
29 packageManagers: machine.packageManagers,
30 runtimes: machine.runtimes,
31 isCi: IsAnalyticsOff.isEnvTruthy(facts.ci),
32 isClaubbit: IsAnalyticsOff.isEnvTruthy(facts.claubbit),
33 isGithubAction,
34 isClaudeCodeAction: IsAnalyticsOff.isEnvTruthy(facts.claudeCodeAction),
35 isClaudeCodeRemote: IsAnalyticsOff.isEnvTruthy(facts.claudeCodeRemote),
36 isLocalAgentMode: facts.entrypoint === 'local-agent',
37 isConductor: facts.bundleIdentifier === 'com.conductor.app',
38 deploymentEnvironment: Deployment.deploymentOf(probe.signals, platform),
39 remoteEnvironmentType: facts.remoteEnvironmentType,
40 claudeCodeContainerId: facts.containerId,
41 claudeCodeRemoteSessionId: facts.remoteSessionId,
42 tags: tagsOf(facts.tags),
43 githubEventName: isGithubAction ? facts.githubEventName : undefined,
44 githubActionsRunnerEnvironment: isGithubAction
45 ? facts.runnerEnvironment
46 : undefined,
47 githubActionsRunnerOs: isGithubAction ? facts.runnerOs : undefined,
48 githubActionRef: isGithubAction
49 ? actionRefOf(facts.githubActionPath)
50 : undefined,
51 githubActionsMetadata: isGithubAction
52 ? githubActionsFieldsOf(facts)
53 : undefined,
54 wslVersion: probe.wslVersion,
55 linuxDistroId: probe.distro.id,
56 linuxDistroVersion: probe.distro.version,
57 linuxKernel: isLinux ? machine.kernel : undefined,
58 vcs: probe.vcs,
59 }
60}