Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions packages/agent-sdk/src/tools/bashTool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -432,28 +432,27 @@ The working directory persists between commands. Try to maintain your current wo
}

// If CWD changed, call the onCwdChange callback and add notification
let cwdResetMessage: string | undefined;
let cwdMessage: string | undefined;
if (newCwd && newCwd !== context.workdir && context.onCwdChange) {
const isInSafeZone =
context.permissionManager?.isPathInSafeZone?.(newCwd) ?? true;

if (isInSafeZone) {
context.onCwdChange(newCwd);
} else if (context.originalWorkdir) {
if (!isInSafeZone && context.originalWorkdir) {
context.onCwdChange(context.originalWorkdir);
cwdResetMessage = `Shell cwd was reset to ${context.originalWorkdir}`;
cwdMessage = `Shell cwd was reset to ${context.originalWorkdir}`;
} else {
context.onCwdChange(newCwd);
cwdMessage = `Shell working directory changed to ${newCwd}`;
}
}

const exitCode = code ?? 0;
const combinedOutput =
outputBuffer + (errorBuffer ? "\n" + errorBuffer : "");

// Prepend CWD reset message to output if present (like Claude Code's stderr approach)
// Prepend CWD change message to output if present
const finalOutput =
(cwdResetMessage ? cwdResetMessage + "\n" : "") +
(cwdMessage ? cwdMessage + "\n" : "") +
(combinedOutput || `Command executed with exit code: ${exitCode}`);
const content = processToolResult(
finalOutput,
Expand Down