claude-code - 💡(How to fix) Fix Bug: Claude Code Installer Improperly Modifies ~/.zshrc Without Newline Separation [1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
anthropics/claude-code#54923Fetched 2026-05-01 05:50:52
View on GitHub
Comments
0
Participants
1
Timeline
4
Reactions
0
Author
Participants
Timeline (top)
labeled ×4

Claude Code CLI auto-update process appends export PATH="$HOME/.local/bin:$PATH" to ~/.zshrc without a preceding newline, causing shell syntax errors.

Root Cause

Claude Code CLI auto-update process appends export PATH="$HOME/.local/bin:$PATH" to ~/.zshrc without a preceding newline, causing shell syntax errors.

Code Example

esac
}

---

esac
}export PATH="$HOME/.local/bin:$PATH"

---

# Ensure file ends with newline before appending
if [ -s ~/.zshrc ] && [ "$(tail -c1 ~/.zshrc | wc -l)" -eq 0 ]; then
    echo "" >> ~/.zshrc
fi
echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.zshrc
RAW_BUFFERClick to expand / collapse

Bug Report: Claude Code Installer Improperly Modifies ~/.zshrc

Summary

Claude Code CLI auto-update process appends export PATH="$HOME/.local/bin:$PATH" to ~/.zshrc without a preceding newline, causing shell syntax errors.

Environment

  • OS: macOS Darwin 24.6.0
  • Shell: zsh
  • Claude Code Version: 2.1.123 (auto-updated from 2.1.121/2.1.122)
  • Date: April 29-30, 2026

Bug Description

During automatic updates (versions 2.1.121 → 2.1.122 → 2.1.123), the installer appended the PATH export line directly after the closing brace } of an existing function in ~/.zshrc without adding a newline separator.

Before (working):

  esac
}

After (broken):

  esac
}export PATH="$HOME/.local/bin:$PATH"

This created invalid shell syntax: }export on the same line, preventing ~/.zshrc from loading and causing "claude: command not found" errors.

Impact

  • Complete shell startup failure
  • Claude CLI inaccessible until manual fix
  • Potential data loss risk if users don't understand the issue

Reproduction

  • Have an existing ~/.zshrc with functions
  • Allow Claude Code to auto-update
  • Shell configuration gets corrupted

Expected Behavior

Installer should:

  1. Check for existing content in shell config files
  2. Add proper newline separation before appending
  3. Validate shell syntax after modification

Actual Behavior

Installer blindly appends without newline separation, breaking shell syntax.

Suggested Fix

Add newline validation to installation scripts:

# Ensure file ends with newline before appending
if [ -s ~/.zshrc ] && [ "$(tail -c1 ~/.zshrc | wc -l)" -eq 0 ]; then
    echo "" >> ~/.zshrc
fi
echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.zshrc

Additional Context

  • This appears to be a common installer antipattern
  • Similar issues reported with other CLI tools
  • Binary signature verified as legitimate Anthropic release

Verification Details

  • Binary Hash: 44597dff0f1c11e37c1954d4ac3965909be376e5961b558345723357253bcc90
  • Code Signature: Valid, Team ID Q6L2SF6YDW
  • Timestamp: Apr 29 02:57:58 2026

extent analysis

TL;DR

The issue can be fixed by modifying the Claude Code installer to add a newline character before appending the export PATH line to the ~/.zshrc file.

Guidance

  • Verify the issue by checking the ~/.zshrc file for the }export syntax error after a Claude Code auto-update.
  • To mitigate the issue, manually add a newline character before the export PATH line in the ~/.zshrc file.
  • The suggested fix involves adding a check to ensure the ~/.zshrc file ends with a newline before appending the export PATH line.
  • Test the fix by allowing Claude Code to auto-update and verifying that the ~/.zshrc file is modified correctly.

Example

The suggested fix can be implemented using the following code:

# Ensure file ends with newline before appending
if [ -s ~/.zshrc ] && [ "$(tail -c1 ~/.zshrc | wc -l)" -eq 0 ]; then
    echo "" >> ~/.zshrc
fi
echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.zshrc

Notes

This fix assumes that the issue is caused by the Claude Code installer not adding a newline character before appending the export PATH line. If the issue persists after applying the fix, further investigation may be necessary.

Recommendation

Apply the suggested fix to the Claude Code installer to ensure that the ~/.zshrc file is modified correctly during auto-updates. This will prevent shell syntax errors and allow the Claude CLI to function properly.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

claude-code - 💡(How to fix) Fix Bug: Claude Code Installer Improperly Modifies ~/.zshrc Without Newline Separation [1 participants]