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

Function maybePersistTokenForSubprocesses

src/utils/authFileDescriptor.ts:30–50  ·  view source on GitHub ↗
(
  path: string,
  token: string,
  tokenName: string,
)

Source from the content-addressed store, hash-verified

28 * put a token on disk that the FD was meant to keep off disk.
29 */
30export function maybePersistTokenForSubprocesses(
31 path: string,
32 token: string,
33 tokenName: string,
34): void {
35 if (!isEnvTruthy(process.env.CLAUDE_CODE_REMOTE)) {
36 return
37 }
38 try {
39 // eslint-disable-next-line custom-rules/no-sync-fs -- one-shot startup write in CCR, caller is sync
40 mkdirSync(CCR_TOKEN_DIR, { recursive: true, mode: 0o700 })
41 // eslint-disable-next-line custom-rules/no-sync-fs -- one-shot startup write in CCR, caller is sync
42 writeFileSync(path, token, { encoding: 'utf8', mode: 0o600 })
43 logForDebugging(`Persisted ${tokenName} to ${path} for subprocess access`)
44 } catch (error) {
45 logForDebugging(
46 `Failed to persist ${tokenName} to disk (non-fatal): ${errorMessage(error)}`,
47 { level: 'error' },
48 )
49 }
50}
51
52/**
53 * Fallback read from a well-known file. The path only exists in CCR (env-manager

Callers 2

getCredentialFromFdFunction · 0.85

Calls 4

mkdirSyncFunction · 0.90
isEnvTruthyFunction · 0.85
logForDebuggingFunction · 0.85
errorMessageFunction · 0.70

Tested by

no test coverage detected