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

Function setCwd

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

Source from the content-addressed store, hash-verified

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

Callers 13

resetCwdIfOutsideProjectFunction · 0.85
callFunction · 0.85
submitMessageMethod · 0.85
runFunction · 0.85
setupFunction · 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