🤖 Add educational note when bash commands use cd #444
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Better UX: Teach instead of block
Instead of blocking redundant cd commands with complex heuristics (which had false positives), we now add an agent-only
notefield to results when commands start with cd. This educates the agent about the execution model without blocking legitimate commands.Approach
Problem: Agents don't understand that cd doesn't persist between bash tool calls, leading to redundant cd commands.
Solution: Inform rather than restrict.
cdExample
Agent executes:
Tool result:
{ "success": true, "output": "file1.txt\nfile2.txt", "exitCode": 0, "wall_duration_ms": 45, "note": "Note: Each bash command starts in ~/workspace/project/branch. Directory changes (cd) do not persist between commands." }User sees in UI:
Agent learns: "Oh, I don't need to cd every time, I'm already in the right directory."
Advantages
Changes
src/types/tools.ts: Addednote?: stringfield to BashToolResult (+2 lines)src/services/tools/bash.ts: Detect cd and add note to success results (+5 lines, -38 lines of heuristics)src/services/tools/bash.test.ts: Removed blocking tests, added note verification tests (-259 lines, +2 new tests)Net change: -275 LoC (much simpler!)
Testing
Test cases:
Why this is better
The original heuristic approach tried to detect redundant cd commands by comparing paths, but:
~/projectmatched/unrelated/project)This approach:
Generated with
cmux