MCPcopy
hub / github.com/claude-code-best/claude-code / getEnvironmentOverrides

Function getEnvironmentOverrides

src/utils/shell/bashProvider.ts:208–253  ·  view source on GitHub ↗
(
      command: string,
    )

Source from the content-addressed store, hash-verified

206 },
207
208 async getEnvironmentOverrides(
209 command: string,
210 ): Promise<Record<string, string>> {
211 // TMUX SOCKET ISOLATION (DEFERRED):
212 // We initialize Claude's tmux socket ONLY AFTER the Tmux tool has been used
213 // at least once, OR if the current command appears to use tmux.
214 // This defers the startup cost until tmux is actually needed.
215 //
216 // Once the Tmux tool is used (or a tmux command runs), all subsequent Bash
217 // commands will use Claude's isolated socket via the TMUX env var override.
218 //
219 // See tmuxSocket.ts for the full isolation architecture documentation.
220 const commandUsesTmux = command.includes('tmux')
221 if (
222 process.env.USER_TYPE === 'ant' &&
223 (hasTmuxToolBeenUsed() || commandUsesTmux)
224 ) {
225 await ensureSocketInitialized()
226 }
227 const claudeTmuxEnv = getClaudeTmuxEnv()
228 const env: Record<string, string> = {}
229 // CRITICAL: Override TMUX to isolate ALL tmux commands to Claude's socket.
230 // This is NOT the user's TMUX value - it points to Claude's isolated socket.
231 // When null (before socket initializes), user's TMUX is preserved.
232 if (claudeTmuxEnv) {
233 env.TMUX = claudeTmuxEnv
234 }
235 if (currentSandboxTmpDir) {
236 let posixTmpDir = currentSandboxTmpDir
237 if (getPlatform() === 'windows') {
238 posixTmpDir = windowsPathToPosixPath(posixTmpDir)
239 }
240 env.TMPDIR = posixTmpDir
241 env.CLAUDE_CODE_TMPDIR = posixTmpDir
242 // Zsh uses TMPPREFIX (default /tmp/zsh) for heredoc temp files,
243 // not TMPDIR. Set it to a path inside the sandbox tmp dir so
244 // heredocs work in sandboxed zsh commands.
245 // Safe to set unconditionally — non-zsh shells ignore TMPPREFIX.
246 env.TMPPREFIX = posixJoin(posixTmpDir, 'zsh')
247 }
248 // Apply session env vars set via /env (child processes only, not the REPL)
249 for (const [key, value] of getSessionEnvVars()) {
250 env[key] = value
251 }
252 return env
253 },
254 }
255}

Callers

nothing calls this directly

Calls 5

hasTmuxToolBeenUsedFunction · 0.85
ensureSocketInitializedFunction · 0.85
getClaudeTmuxEnvFunction · 0.85
getPlatformFunction · 0.85
getSessionEnvVarsFunction · 0.85

Tested by

no test coverage detected