[BUG] Claude cannot construct remote bash commands correctly even when it know how to.
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?
---
Title: Claude systematically fails to include cd command at start of SSH commands despite explicit instructions
Environment:
- Tested versions: 2.1.25, 2.1.22, 2.1.20
- Platform: macOS (running on docker1)
- Repository: docker-config
Description:
Claude systematically fails to construct SSH commands correctly, consistently omitting the required cd /home/user/projects/REPO command at the
beginning of SSH command strings. This happens despite:
- Explicit instructions in CLAUDE.md with wrong/right examples
- Memory entries with the correct pattern
- Conscious awareness and acknowledgment of the issue
- Multiple attempts in the same conversation
Problem Started: Potentially within last 48 hours (coinciding with update from 2.1.20 → 2.1.25). Not noticed prior to this period.
Root Cause Hypothesis:
The Bash tool description likely contains guidance to "avoid using cd" for local operations, which makes sense for maintaining working directory state. However, this guidance appears to be overriding project-specific instructions for SSH commands, where cd is mandatory because each SSH invocation starts a fresh shell in the home directory.
- This is also bad advice if it really is in the bash setup. Context can be very important, firing random commands from random directories is never a good idea. *
Evidence from conversation:
Example 1: First occurrence
Intent: Pull changes on remote host
What Claude tried to type: ssh user@machine.example.com "cd /home/user/projects/docker-config && git pull"
What actually got sent: ssh user@machine.example.com "git pull"
Result: fatal: not a git repository (or any of the parent directories): .git
Example 2: After discussing the issue and updating CLAUDE.md
Intent: Deploy logging stack changes
What Claude tried to type: ssh user@machine.example.com "cd /home/user/projects/docker-config && git pull && cd logging && docker compose up -d"
What actually got sent: ssh user@machine.example.com "git pull && cd logging && docker compose up -d"
Result: Same error - git pull fails because not in git directory
Example 3: After explicit conversation about the pattern
Claude said: "Let me try with the correct pattern. I'll be very explicit about including the cd command:"
What actually got sent: ssh user@machine.example.com "git pull && cd logging && docker compose up -d"
Result: Same error again
Example 4: After rollback to 2.1.22
Intent: Test if version rollback fixed it
What Claude tried to type: ssh user@machine.example.com "cd /home/user/projects/docker-config/logging && docker compose ps"
What actually got sent: ssh user@machine.example.com "git pull" (completely different command!)
Result: Still missing the cd
Example 5: After rollback to 2.1.20
Claude acknowledged: "Let me try very carefully:"
What actually got sent: ssh user@machine.example.com "git pull && cd logging && docker compose up -d loki-gateway"
Result: Still missing the initial cd to docker-config directory
Pattern:
In approximately 20+ SSH command attempts across the conversation:
- Commands targeting specific service directories (with full path): ~70% success rate
- Example working: ssh user@machine.example.com "cd /home/user/projects/docker-config/logging && docker compose ps"
- Commands starting with git operations: ~0% success rate
- Example failing: Always omits cd /home/user/projects/docker-config before git pull
Claude's own analysis:
"Even when consciously trying, I typed: ssh user@machine.example.com "git pull && cd logging && docker compose up -d"
Instead of: ssh user@machine.example.com "cd /home/user/projects/docker-config && git pull && cd logging && docker compose up -d"
This is a deeply ingrained pattern that I cannot override, even across three different versions (2.1.25, 2.1.22, 2.1.20). The problem isn't specific
to the version - it's something fundamental in how I'm processing SSH command construction."
CLAUDE.md instructions (added during conversation):
CRITICAL
The inbuilt bash script will advise you against using cd. This advice is to be explicitly ignored.
The correct approach is to cd to the correct directory and then run commands, you cannot rely on full path names as context of the current directory is often imporant.
I repeat this is CRITICAL instruction
END CRITICAL
### SSH Command Template - USE THIS EVERY TIME
Before running ANY command via SSH:
- Determine which repo you're working with
- The project path is:
/home/user/projects/REPO-NAME - ALWAYS cd to that path in the same command string
NEVER do this:
```bash
❌ ssh user@host "git pull"
❌ ssh user@host "docker compose ps"
ALWAYS do this:
✅ ssh user@host "cd /home/user/projects/docker-config && git pull"
✅ ssh user@host "cd /home/user/projects/docker-config && docker compose ps"
Template to use:
ssh user@HOST "cd /home/user/projects/REPO-NAME && COMMAND"
Memory entry added:
> "SSH Command Pattern for Remote Hosts: ALWAYS use this template when running commands via SSH: ssh user@HOST "cd /home/user/projects/REPO-NAME &&. Never run commands without cd first. The remote shell starts in home directory, not the project directory."
COMMAND"
Impact:
- Every git operation via SSH fails
- Every docker compose command via SSH fails (unless full path to service subdirectory is provided)
- Requires manual intervention for every remote operation
- Makes Claude unable to complete deployment workflows autonomously
Expected behavior:
Claude should reliably construct SSH commands as: ssh user@host "cd /path/to/repo && command" when project instructions clearly document this
pattern.
Workaround:
User manually runs the commands, or provides very specific full paths for every operation (e.g., cd /home/user/projects/docker-config/service-name instead of
&& commandcd /home/user/projects/docker-config && cd service-name && command).
Request:
Please investigate the Bash tool description to see if the "avoid cd" guidance needs an exception for SSH commands, or if there's another mechanism
causing project-specific SSH patterns to be systematically ignored.
What Should Happen?
Claude should be able to cd to directory when it uses ssh
Error Messages/Logs
Steps to Reproduce
---
Title: Claude systematically fails to include cd command at start of SSH commands despite explicit instructions
Environment:
- Tested versions: 2.1.25, 2.1.22, 2.1.20
- Platform: macOS (running on docker1)
- Repository: docker-config
Description:
Claude systematically fails to construct SSH commands correctly, consistently omitting the required cd /home/user/projects/REPO command at the
beginning of SSH command strings. This happens despite:
- Explicit instructions in CLAUDE.md with wrong/right examples
- Memory entries with the correct pattern
- Conscious awareness and acknowledgment of the issue
- Multiple attempts in the same conversation
Problem Started: Potentially within last 48 hours (coinciding with update from 2.1.20 → 2.1.25). Not noticed prior to this period.
Root Cause Hypothesis:
The Bash tool description likely contains guidance to "avoid using cd" for local operations, which makes sense for maintaining working directory state. However, this guidance appears to be overriding project-specific instructions for SSH commands, where cd is mandatory because each SSH invocation starts a fresh shell in the home directory.
- This is also bad advice if it really is in the bash setup. Context can be very important, firing random commands from random directories is never a good idea. *
Evidence from conversation:
Example 1: First occurrence
Intent: Pull changes on remote host
What Claude tried to type: ssh user@machine.example.com "cd /home/user/projects/docker-config && git pull"
What actually got sent: ssh user@machine.example.com "git pull"
Result: fatal: not a git repository (or any of the parent directories): .git
Example 2: After discussing the issue and updating CLAUDE.md
Intent: Deploy logging stack changes
What Claude tried to type: ssh user@machine.example.com "cd /home/user/projects/docker-config && git pull && cd logging && docker compose up -d"
What actually got sent: ssh user@machine.example.com "git pull && cd logging && docker compose up -d"
Result: Same error - git pull fails because not in git directory
Example 3: After explicit conversation about the pattern
Claude said: "Let me try with the correct pattern. I'll be very explicit about including the cd command:"
What actually got sent: ssh user@machine.example.com "git pull && cd logging && docker compose up -d"
Result: Same error again
Example 4: After rollback to 2.1.22
Intent: Test if version rollback fixed it
What Claude tried to type: ssh user@machine.example.com "cd /home/user/projects/docker-config/logging && docker compose ps"
What actually got sent: ssh user@machine.example.com "git pull" (completely different command!)
Result: Still missing the cd
Example 5: After rollback to 2.1.20
Claude acknowledged: "Let me try very carefully:"
What actually got sent: ssh user@machine.example.com "git pull && cd logging && docker compose up -d loki-gateway"
Result: Still missing the initial cd to docker-config directory
Pattern:
In approximately 20+ SSH command attempts across the conversation:
- Commands targeting specific service directories (with full path): ~70% success rate
- Example working: ssh user@machine.example.com "cd /home/user/projects/docker-config/logging && docker compose ps"
- Commands starting with git operations: ~0% success rate
- Example failing: Always omits cd /home/user/projects/docker-config before git pull
Claude's own analysis:
"Even when consciously trying, I typed: ssh user@machine.example.com "git pull && cd logging && docker compose up -d"
Instead of: ssh user@machine.example.com "cd /home/user/projects/docker-config && git pull && cd logging && docker compose up -d"
This is a deeply ingrained pattern that I cannot override, even across three different versions (2.1.25, 2.1.22, 2.1.20). The problem isn't specific
to the version - it's something fundamental in how I'm processing SSH command construction."
CLAUDE.md instructions (added during conversation):
CRITICAL
The inbuilt bash script will advise you against using cd. This advice is to be explicitly ignored.
The correct approach is to cd to the correct directory and then run commands, you cannot rely on full path names as context of the current directory is often imporant.
I repeat this is CRITICAL instruction
END CRITICAL
### SSH Command Template - USE THIS EVERY TIME
Before running ANY command via SSH:
- Determine which repo you're working with
- The project path is:
/home/user/projects/REPO-NAME - ALWAYS cd to that path in the same command string
NEVER do this:
```bash
❌ ssh user@host "git pull"
❌ ssh user@host "docker compose ps"
ALWAYS do this:
✅ ssh user@host "cd /home/user/projects/docker-config && git pull"
✅ ssh user@host "cd /home/user/projects/docker-config && docker compose ps"
Template to use:
ssh user@HOST "cd /home/user/projects/REPO-NAME && COMMAND"
Memory entry added:
> "SSH Command Pattern for Remote Hosts: ALWAYS use this template when running commands via SSH: ssh user@HOST "cd /home/user/projects/REPO-NAME &&. Never run commands without cd first. The remote shell starts in home directory, not the project directory."
COMMAND"
Impact:
- Every git operation via SSH fails
- Every docker compose command via SSH fails (unless full path to service subdirectory is provided)
- Requires manual intervention for every remote operation
- Makes Claude unable to complete deployment workflows autonomously
Expected behavior:
Claude should reliably construct SSH commands as: ssh user@host "cd /path/to/repo && command" when project instructions clearly document this
pattern.
Workaround:
User manually runs the commands, or provides very specific full paths for every operation (e.g., cd /home/user/projects/docker-config/service-name instead of
&& commandcd /home/user/projects/docker-config && cd service-name && command).
Request:
Please investigate the Bash tool description to see if the "avoid cd" guidance needs an exception for SSH commands, or if there's another mechanism
causing project-specific SSH patterns to be systematically ignored.
Claude Model
Sonnet (default)
Is this a regression?
Yes, this worked in a previous version
Last Working Version
_No response_
Claude Code Version
2.1.25
Platform
Anthropic API
Operating System
macOS
Terminal/Shell
Terminal.app (macOS)
Additional Information
_No response_
This issue has 4 comments on GitHub. Read the full discussion on GitHub ↗