The best way to control Claude Code, Codex and more from any computer or phone
| 1 | // @effect-diagnostics nodeBuiltinImport:off |
| 2 | import * as NodePath from "node:path"; |
| 3 | |
| 4 | // Spawned processes lack shell expansion and would treat literal ~/ paths as relative. |
| 5 | export function expandHomePath(value: string, home: string): string { |
| 6 | if (!value) return value; |
| 7 | if (value === "~") return home; |
| 8 | if (value.startsWith("~/") || value.startsWith("~\\")) { |
| 9 | return NodePath.join(home, value.slice(2)); |
| 10 | } |
| 11 | return value; |
| 12 | } |
| 13 | |
| 14 | const HOME_PATH_VARIABLES = new Set(["CODEX_HOME", "CLAUDE_CONFIG_DIR", "GROK_HOME"]); |
| 15 | |
| 16 | export function expandHomeVariable(name: string, value: string, home: string): string { |
| 17 | return HOME_PATH_VARIABLES.has(name) ? expandHomePath(value, home) : value; |
| 18 | } |