MCPcopy Index your code
hub / github.com/codeaashu/claude-code / resetCwdIfOutsideProject

Function resetCwdIfOutsideProject

src/tools/BashTool/utils.ts:170–192  ·  view source on GitHub ↗
(
  toolPermissionContext: ToolPermissionContext,
)

Source from the content-addressed store, hash-verified

168 `${stderr.trim()}\nShell cwd was reset to ${getOriginalCwd()}`
169
170export function resetCwdIfOutsideProject(
171 toolPermissionContext: ToolPermissionContext,
172): boolean {
173 const cwd = getCwd()
174 const originalCwd = getOriginalCwd()
175 const shouldMaintain = shouldMaintainProjectWorkingDir()
176 if (
177 shouldMaintain ||
178 // Fast path: originalCwd is unconditionally in allWorkingDirectories
179 // (filesystem.ts), so when cwd hasn't moved, pathInAllowedWorkingPath is
180 // trivially true — skip its syscalls for the no-cd common case.
181 (cwd !== originalCwd &&
182 !pathInAllowedWorkingPath(cwd, toolPermissionContext))
183 ) {
184 // Reset to original directory if maintaining project dir OR outside allowed working directory
185 setCwd(originalCwd)
186 if (!shouldMaintain) {
187 logEvent('tengu_bash_tool_reset_to_original_dir', {})
188 return true
189 }
190 }
191 return false
192}
193
194/**
195 * Creates a human-readable summary of structured content blocks.

Callers 2

callFunction · 0.85
callFunction · 0.85

Calls 6

getCwdFunction · 0.85
getOriginalCwdFunction · 0.85
pathInAllowedWorkingPathFunction · 0.85
setCwdFunction · 0.85
logEventFunction · 0.85

Tested by

no test coverage detected