( path: string, token: string, tokenName: string, )
| 28 | * put a token on disk that the FD was meant to keep off disk. |
| 29 | */ |
| 30 | export 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 |
no test coverage detected