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
66 lines · 2.6 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 * The engine's version, base version and build time are as it answered
16 * them, absent where it did not.
17 *
18 * @param probe what was gathered for the session
19 * @returns the block
20 */
21export function environmentFieldsOf(probe: Probe): EnvironmentFields {
22 const { facts, machine, platform } = probe
23 const isGithubAction = IsAnalyticsOff.isEnvTruthy(facts.githubActions)
24 const isLinux = machine.platformRaw === 'linux'
25
26 return {
27 platform,
28 platformRaw: machine.platformRaw,
29 arch: machine.arch,
30 terminal: terminalOf(facts, platform, probe.isInteractive),
31 shell: shellOf(facts.shellPath),
32 packageManagers: machine.packageManagers,
33 runtimes: machine.runtimes,
34 isCi: IsAnalyticsOff.isEnvTruthy(facts.ci),
35 isClaubbit: IsAnalyticsOff.isEnvTruthy(facts.claubbit),
36 isGithubAction,
37 isClaudeCodeAction: IsAnalyticsOff.isEnvTruthy(facts.claudeCodeAction),
38 isClaudeCodeRemote: IsAnalyticsOff.isEnvTruthy(facts.claudeCodeRemote),
39 isLocalAgentMode: facts.entrypoint === 'local-agent',
40 isConductor: facts.bundleIdentifier === 'com.conductor.app',
41 deploymentEnvironment: Deployment.deploymentOf(probe.signals, platform),
42 remoteEnvironmentType: facts.remoteEnvironmentType,
43 claudeCodeContainerId: facts.containerId,
44 claudeCodeRemoteSessionId: facts.remoteSessionId,
45 tags: tagsOf(facts.tags),
46 githubEventName: isGithubAction ? facts.githubEventName : undefined,
47 githubActionsRunnerEnvironment: isGithubAction
48 ? facts.runnerEnvironment
49 : undefined,
50 githubActionsRunnerOs: isGithubAction ? facts.runnerOs : undefined,
51 githubActionRef: isGithubAction
52 ? actionRefOf(facts.githubActionPath)
53 : undefined,
54 githubActionsMetadata: isGithubAction
55 ? githubActionsFieldsOf(facts)
56 : undefined,
57 wslVersion: probe.wslVersion,
58 linuxDistroId: probe.distro.id,
59 linuxDistroVersion: probe.distro.version,
60 linuxKernel: isLinux ? machine.kernel : undefined,
61 vcs: probe.vcs,
62 version: probe.engine?.version,
63 versionBase: probe.engine?.base,
64 buildTime: probe.engine?.builtAt,
65 }
66}