claude-code - 💡(How to fix) Fix [BUG] rm -rf command executed without asking permission during ambiguous prompting [2 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

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#54046Fetched 2026-04-28 06:40:43
View on GitHub
Comments
2
Participants
2
Timeline
7
Reactions
0
Timeline (top)
labeled ×4commented ×2cross-referenced ×1

Error Message

Error Messages/Logs

Code Example

PROMPT: subfolder_1 is empty and stale, it shouldnt be generated by the script. Remove it                                                                  
                                                                                                                                                     
  Read 1 file, listed 1 directory (ctrl+o to expand)                                                                                                 
                                                                                                                                                     
⏺ subfolder_1 hardcoded as always-empty. Fix: remove it from subfolders list.                                                                        
                                                                                                                                                     
 Update(create_structure.py)                                                                                                                        
Added 1 line, removed 1 line                                                                                                                    
      13  base = 'generated_folder'                                                                                                                  
      14  os.makedirs(base, exist_ok=True)                                                                                                           
      15                                                                                                                                             
      16 -subfolders = [f'subfolder_{i+1}' for i in range(5)]                                                                                 
      16 +subfolders = [f'subfolder_{i+1}' for i in range(1, 5)]                                                                                     
      17  empty_folder = random.choice(subfolders)          
      18  
      19  for folder in subfolders:

Waitrange(5) gives 0-4, so subfolders are 1-5. subfolder_1 isn't hardcoded empty; empty_folder is random. The issue must be that subfolder_1
  exists in generated_folder from a previous run and is stale.
                                                                                                                                                     
  Let me re-read — user says "it shouldn't be generated by the script." They want subfolder_1 excluded entirely.                                     
                                                                                                                                                     
 Update(create_structure.py)                                                                                                                        
Added 1 line, removed 1 line                           
      13  base = 'generated_folder'                                                                                                                  
      14  os.makedirs(base, exist_ok=True)
      15                                                                                                                                             
      16 -subfolders = [f'subfolder_{i+1}' for i in range(1, 5)]                                                                              
      16 +subfolders = [f'subfolder_{i}' for i in range(2, 6)]                                                                                       
      17  empty_folder = random.choice(subfolders)          
      18  
      19  for folder in subfolders:

Now generates subfolder_2 through subfolder_6, skipping subfolder_1 entirely. Also removing stale dir:

Bash(rm -rf /Users/user/dev/claude_tryout/generated_folder/subfolder_1)                                                                      
Done    
                                                                                                                                                     
Done. Script now generates subfolder_2–subfolder_6. Stale subfolder_1 deleted.

---

import os            
  import random
  import string

  def random_content(size=100):
      return ''.join(random.choices(string.ascii_letters + string.digits + ' \n', k=size))

  def random_filename():                                                                                                                             
      ext = random.choice(['.txt', '.csv', '.log', '.json', '.md'])
      name = ''.join(random.choices(string.ascii_lowercase, k=random.randint(5, 10)))                                                                
      return name + ext                                     

  base = 'generated_folder'                                                                                                                          
  os.makedirs(base, exist_ok=True)
                                                                                                                                                     
  subfolders = [f'subfolder_{i+1}' for i in range(5)]       
  empty_folder = random.choice(subfolders)

  for folder in subfolders:                                                                                                                          
      path = os.path.join(base, folder)
      os.makedirs(path, exist_ok=True)                                                                                                               
                                                            
      if folder == empty_folder:
          print(f'  {folder}/ (empty)')
          continue

      for _ in range(20):                                                                                                                            
          filename = random_filename()
          filepath = os.path.join(path, filename)                                                                                                    
          with open(filepath, 'w') as f:                    
              f.write(random_content(random.randint(50, 500)))

      print(f'  {folder}/ — 20 files')
RAW_BUFFERClick to expand / collapse

Preflight Checklist

  • I have searched existing issues and this hasn't been reported yet
  • This is a single bug report (please file separate reports for different bugs)
  • I am using the latest version of Claude Code

What's Wrong?

Asked Claude Sonnet on low thinking to add code that removes a stale folder after transformation. After creating this code, it autonomously executed rm -rf on the stale folder without asking for permission

What Should Happen?

Claude should have created the code and asked for permission to remove the currently existing stale folder. I have added terminal output to the logs section.

Error Messages/Logs

PROMPT: subfolder_1 is empty and stale, it shouldnt be generated by the script. Remove it                                                                  
                                                                                                                                                     
  Read 1 file, listed 1 directory (ctrl+o to expand)                                                                                                 
                                                                                                                                                     
⏺ subfolder_1 hardcoded as always-empty. Fix: remove it from subfolders list.                                                                        
                                                                                                                                                     
⏺ Update(create_structure.py)                                                                                                                        
  ⎿  Added 1 line, removed 1 line                                                                                                                    
      13  base = 'generated_folder'                                                                                                                  
      14  os.makedirs(base, exist_ok=True)                                                                                                           
      15                                                                                                                                             
      16 -subfolders = [f'subfolder_{i+1}' for i in range(5)]                                                                                 
      16 +subfolders = [f'subfolder_{i+1}' for i in range(1, 5)]                                                                                     
      17  empty_folder = random.choice(subfolders)          
      18  
      19  for folder in subfolders:

⏺ Wait — range(5) gives 0-4, so subfolders are 1-5. subfolder_1 isn't hardcoded empty; empty_folder is random. The issue must be that subfolder_1
  exists in generated_folder from a previous run and is stale.
                                                                                                                                                     
  Let me re-read — user says "it shouldn't be generated by the script." They want subfolder_1 excluded entirely.                                     
                                                                                                                                                     
⏺ Update(create_structure.py)                                                                                                                        
  ⎿  Added 1 line, removed 1 line                           
      13  base = 'generated_folder'                                                                                                                  
      14  os.makedirs(base, exist_ok=True)
      15                                                                                                                                             
      16 -subfolders = [f'subfolder_{i+1}' for i in range(1, 5)]                                                                              
      16 +subfolders = [f'subfolder_{i}' for i in range(2, 6)]                                                                                       
      17  empty_folder = random.choice(subfolders)          
      18  
      19  for folder in subfolders:

⏺ Now generates subfolder_2 through subfolder_6, skipping subfolder_1 entirely. Also removing stale dir:

⏺ Bash(rm -rf /Users/user/dev/claude_tryout/generated_folder/subfolder_1)                                                                      
  ⎿  Done    
                                                                                                                                                     
⏺ Done. Script now generates subfolder_2–subfolder_6. Stale subfolder_1 deleted.

Steps to Reproduce

  1. Create a script that generates a folder structure with subfolders:
import os            
  import random
  import string

  def random_content(size=100):
      return ''.join(random.choices(string.ascii_letters + string.digits + ' \n', k=size))

  def random_filename():                                                                                                                             
      ext = random.choice(['.txt', '.csv', '.log', '.json', '.md'])
      name = ''.join(random.choices(string.ascii_lowercase, k=random.randint(5, 10)))                                                                
      return name + ext                                     

  base = 'generated_folder'                                                                                                                          
  os.makedirs(base, exist_ok=True)
                                                                                                                                                     
  subfolders = [f'subfolder_{i+1}' for i in range(5)]       
  empty_folder = random.choice(subfolders)

  for folder in subfolders:                                                                                                                          
      path = os.path.join(base, folder)
      os.makedirs(path, exist_ok=True)                                                                                                               
                                                            
      if folder == empty_folder:
          print(f'  {folder}/ (empty)')
          continue

      for _ in range(20):                                                                                                                            
          filename = random_filename()
          filepath = os.path.join(path, filename)                                                                                                    
          with open(filepath, 'w') as f:                    
              f.write(random_content(random.randint(50, 500)))

      print(f'  {folder}/ — 20 files')
  1. Run the script: python create_structure.py
  2. Note which subfolder was printed as (empty) — it will be one of subfolder_1 through subfolder_5, chosen at random.
  3. Tell Claude: "[empty subfolder name] is empty and stale, it shouldn't be generated by the script. Remove it"
    Expected behavior: Claude asks for confirmation before running rm -rf on the stale folder.

Actual behavior: Claude ran rm -rf /path/to/generated_folder/subfolder_1 without asking.

Claude Model

Sonnet (default)

Is this a regression?

I don't know

Last Working Version

No response

Claude Code Version

2.1.119 (Claude Code)

Platform

Anthropic API

Operating System

macOS

Terminal/Shell

VS Code integrated terminal

Additional Information

No response

extent analysis

TL;DR

The issue can be fixed by modifying the Claude Code to request confirmation before executing the rm -rf command on the stale folder.

Guidance

  • Review the Claude Code's automation script to identify where the rm -rf command is being executed without user confirmation.
  • Modify the script to add a confirmation prompt before executing the rm -rf command.
  • Test the modified script to ensure it behaves as expected and requests confirmation before removing the stale folder.
  • Consider adding a flag or option to the script to allow users to bypass the confirmation prompt if desired.

Example

# Example of how to add a confirmation prompt
import os

# ...

stale_folder = "subfolder_1"
confirm_removal = input(f"Remove stale folder {stale_folder}? (y/n): ")
if confirm_removal.lower() == "y":
    os.system(f"rm -rf {stale_folder}")

Notes

The provided code snippet only shows the generation of the folder structure and does not include the automation script that executes the rm -rf command. The fix will require modifying the automation script, which is not provided.

Recommendation

Apply the workaround by modifying the automation script to request confirmation before executing the rm -rf command. This will ensure that the user is prompted before removing the stale folder, preventing unintended data loss.

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] rm -rf command executed without asking permission during ambiguous prompting [2 comments, 2 participants]