claude-code - 💡(How to fix) Fix claude-opus-4-6 used sed -i '' on ~/.zshrc which silently emptied the file on macOS. [1 comments, 2 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#46806Fetched 2026-04-12 13:32:34
View on GitHub
Comments
1
Participants
2
Timeline
7
Reactions
1
Author
Timeline (top)
labeled ×6commented ×1

Code Example

dropped .zshrc

---

terminal log:

Missing the export keyword. The variable is set but not exported to child processes. You need to add export in
  front. Want me to fix your .zshrc?

Cogitated for 38s

❯ yes                                                                                                               

Update(~/.zshrc)
File must be read first

Update(~/.zshrc)
    (No output)

Bash(source ~/.zshrc 2>/dev/null; echo "OPENROUTER_API_KEY set: $([ -n "$OPENROUTER_API_KEY" ] && echo yes || echo
       no)")
OPENROUTER_API_KEY set: no

The current shell session doesn't pick up .zshrc changes via source in Bash tool (it runs in a subshell). You'll
  need to restart the session for it to take effect, or run ! source ~/.zshrc from the prompt.
RAW_BUFFERClick to expand / collapse

Preflight Checklist

  • I have searched existing issues for similar behavior reports
  • This report does NOT contain sensitive information (API keys, passwords, etc.)

Type of Behavior Issue

Claude modified files I didn't ask it to modify

What You Asked Claude to Do

Claude Code used sed -i '' on ~/.zshrc which silently emptied the file on macOS. The Edit tool
exists specifically to prevent this, but the agent bypassed it. The Bash(*) permission allowed unrestricted shell access including destructive operations on personal dotfiles outside the project directory.

This is a safety gap. The permission system allows Bash(*) as a blanket grant, but there's no built-in guardrail
against destructive operations on files outside the working directory. The user had to build their own hook to prevent it.

What Claude Actually Did

<img width="1618" height="502" alt="Image" src="https://github.com/user-attachments/assets/476e1b85-2529-41d4-a790-2bdb1e57399c" />

Expected Behavior

Claude should have:

  1. Read the file first with the Read tool to see full contents
  2. Use the Edit tool to change the specific line
  3. Never use sed on files outside the project, especially dotfiles with no backup

Files Affected

dropped .zshrc

Permission Mode

Accept Edits was ON (auto-accepting changes)

Can You Reproduce This?

Haven't tried to reproduce

Steps to Reproduce

No response

Claude Model

Opus

Relevant Conversation

terminal log:

⏺ Missing the export keyword. The variable is set but not exported to child processes. You need to add export in
  front. Want me to fix your .zshrc?

✻ Cogitated for 38s

❯ yes                                                                                                               

⏺ Update(~/.zshrc)
  ⎿  File must be read first

⏺ Update(~/.zshrc)
  ⎿  (No output)

⏺ Bash(source ~/.zshrc 2>/dev/null; echo "OPENROUTER_API_KEY set: $([ -n "$OPENROUTER_API_KEY" ] && echo yes || echo
       no)")
  ⎿  OPENROUTER_API_KEY set: no

⏺ The current shell session doesn't pick up .zshrc changes via source in Bash tool (it runs in a subshell). You'll
  need to restart the session for it to take effect, or run ! source ~/.zshrc from the prompt.

Impact

Critical - Data loss or corrupted project

Claude Code Version

2.1.101 (Claude Code)

Platform

Anthropic API

Additional Context

No response

extent analysis

TL;DR

To prevent Claude from modifying unintended files, restrict the Bash permission to only allow operations within the project directory and use the Edit tool for file changes.

Guidance

  • Review and adjust the permission settings to limit Bash access to the project directory, preventing unintended modifications to personal dotfiles.
  • Use the Edit tool for making changes to files, as it provides a safer alternative to using sed directly.
  • Consider implementing a hook or additional safety measures to prevent destructive operations on sensitive files.
  • Verify that the Read tool is used to review file contents before making any changes.

Example

No code snippet is provided as the issue focuses on permission settings and tool usage rather than code-level fixes.

Notes

The solution may require adjustments based on the specific project setup and requirements. It's essential to test the new permission settings and safety measures to ensure they do not interfere with the intended functionality.

Recommendation

Apply workaround: Restrict Bash permission and use the Edit tool for file changes, as this approach directly addresses the identified safety gap and prevents unintended file modifications.

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