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

Function setCwd

src/utils/Shell.ts:447–474  ·  view source on GitHub ↗
(path: string, relativeTo?: string)

Source from the content-addressed store, hash-verified

445 * Set the current working directory
446 */
447export function setCwd(path: string, relativeTo?: string): void {
448 const resolved = isAbsolute(path)
449 ? path
450 : resolve(relativeTo || getFsImplementation().cwd(), path)
451 // Resolve symlinks to match the behavior of pwd -P.
452 // realpathSync throws ENOENT if the path doesn't exist - convert to a
453 // friendlier error message instead of a separate existsSync pre-check (TOCTOU).
454 let physicalPath: string
455 try {
456 physicalPath = getFsImplementation().realpathSync(resolved)
457 } catch (e) {
458 if (isENOENT(e)) {
459 throw new Error(`Path "${resolved}" does not exist`)
460 }
461 throw e
462 }
463
464 setCwdState(physicalPath)
465 if (process.env.NODE_ENV !== 'test') {
466 try {
467 logEvent('tengu_shell_set_cwd', {
468 success: true,
469 })
470 } catch (_error) {
471 // Ignore logging errors to prevent test failures
472 }
473 }
474}
475

Callers 13

submitMessageMethod · 0.85
runFunction · 0.85
setupFunction · 0.85
resetCwdIfOutsideProjectFunction · 0.85
callFunction · 0.85
loadChangesFunction · 0.85
handleSelectFunction · 0.85
execFunction · 0.85
restoreWorktreeForResumeFunction · 0.85
exitRestoredWorktreeFunction · 0.85
clearConversationFunction · 0.85

Calls 5

getFsImplementationFunction · 0.85
isENOENTFunction · 0.85
setCwdStateFunction · 0.85
logEventFunction · 0.85
resolveFunction · 0.70

Tested by

no test coverage detected