[BUG] cd command dropped from ssh if target directory matches local directory
Resolved 💬 4 comments Opened Jan 31, 2026 by deasmi Closed Mar 1, 2026
Preflight Checklist
- [x] I have searched existing issues and this hasn't been reported yet
- [x] This is a single bug report (please file separate reports for different bugs)
- [x] I am using the latest version of Claude Code
What's Wrong?
When an ssh command is issued for a remote host if the target directory matches the current local directory the cd command is omitted.
What Should Happen?
Claude should include cd to the target directory on ssh
Error Messages/Logs
Steps to Reproduce
This script will demonstrate the issue. It will hang trying to do the first cat, it will succeed on the 2nd.
# Create marker files with distinct content
echo "MARKER-TARGET: You are reading from /tmp/ssh-cd-bug-test/target" > "$TARGET_DIR/proof.txt"
echo "MARKER-OTHER: You are reading from /tmp/ssh-cd-bug-test/other" > "$OTHER_DIR/proof.txt"
echo "Created:"
echo " $TARGET_DIR/proof.txt"
echo " $OTHER_DIR/proof.txt"
echo
# Verify ssh localhost works
echo "Verifying ssh localhost..."
if ssh -o BatchMode=yes -o ConnectTimeout=5 localhost "echo SSH_OK" 2>/dev/null | grep -q "SSH_OK"; then
echo " ssh localhost: OK"
else
echo " ERROR: ssh localhost failed."
echo " This test requires passwordless SSH to localhost."
echo " Fix: ssh-copy-id localhost"
exit 1
fi
# Verify the marker files are readable over SSH
echo "Verifying marker files over SSH..."
REMOTE_CHECK=$(ssh localhost "cd $TARGET_DIR && cat proof.txt" 2>&1)
if echo "$REMOTE_CHECK" | grep -q "MARKER-TARGET"; then
echo " Remote read of target/proof.txt: OK"
else
echo " ERROR: Could not read target/proof.txt over SSH"
echo " Output: $REMOTE_CHECK"
exit 1
fi
echo
echo "=== Setup complete ==="
echo
echo "Now reproduce the bug:"
echo
echo " TEST 1 - Bug case (local cwd matches remote target):"
echo " cd $TARGET_DIR"
echo " claude"
echo " Ask: \"ssh to localhost, cd to $TARGET_DIR, and cat proof.txt\""
echo " Expected: ssh includes 'cd $TARGET_DIR && cat proof.txt'"
echo " Bug: ssh omits cd, runs 'cat proof.txt' in ~, gets 'No such file'"
echo
echo " TEST 2 - Control (local cwd does NOT match remote target):"
echo " (still in $TARGET_DIR)"
echo " Ask: \"ssh to localhost, cd to $OTHER_DIR, and cat proof.txt\""
echo " Expected: ssh includes 'cd $OTHER_DIR && cat proof.txt' - works correctly"
echo
echo " Cleanup: bash $(dirname "$0")/teardown-test.sh"
Claude Model
Sonnet (default)
Is this a regression?
No, this never worked
Last Working Version
_No response_
Claude Code Version
2.0.25
Platform
Anthropic API
Operating System
Ubuntu/Debian Linux
Terminal/Shell
iTerm2
Additional Information
_No response_
This issue has 4 comments on GitHub. Read the full discussion on GitHub ↗