openclaw - ✅(Solved) Fix [Bug]: openclaw agents delete --force incorrectly deletes shared workspace instead of agent-specific files [1 pull requests, 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
openclaw/openclaw#53705Fetched 2026-04-08 01:24:34
View on GitHub
Comments
0
Participants
1
Timeline
5
Reactions
0
Author
Participants
Timeline (top)
cross-referenced ×2labeled ×2referenced ×1

When running openclaw agents delete <agent-id> --force on an agent that uses a shared workspace (i.e., workspace path that is also used by other agents), the command incorrectly moves the entire shared workspace to Trash, instead of:

  1. Refusing to delete with a clear error about shared workspace
  2. Only deleting the agent's isolated files (under ~/.openclaw/agents/<agent-id>/)

Error Message

  1. Refusing to delete with a clear error about shared workspace

Root Cause

When running openclaw agents delete <agent-id> --force on an agent that uses a shared workspace (i.e., workspace path that is also used by other agents), the command incorrectly moves the entire shared workspace to Trash, instead of:

  1. Refusing to delete with a clear error about shared workspace
  2. Only deleting the agent's isolated files (under ~/.openclaw/agents/<agent-id>/)

Fix Action

Fixed

PR fix notes

PR #53775: fix(agents): protect shared workspace from accidental deletion in agents delete --force

Description (problem / solution / changelog)

Summary

When running openclaw agents delete <agent-id> --force on an agent configured with a shared workspace (e.g., the default ~/.openclaw/workspace), the entire shared workspace was moved to Trash, wiping SOUL.md, USER.md, MEMORY.md, AGENTS.md, and all other configuration files.

Root Cause

agentsDeleteCommand unconditionally called moveToTrash(workspaceDir) without checking whether the workspace is shared across agents. When an agent uses the default workspace path, this deletes the shared workspace that may be used by the default agent or other agents.

Fix

Added a guard in agentsDeleteCommand that checks whether the agent's workspace is the shared default workspace before calling moveToTrash:

  1. Compares workspaceDir against DEFAULT_AGENT_WORKSPACE_DIR
  2. If they match (or if the default agent also uses this path), skips workspace deletion
  3. Still deletes agent-specific state (agentDir and sessionsDir)
  4. Logs a clear message when skipping shared workspace deletion

Files Changed

  • src/commands/agents.commands.delete.ts: Added shared workspace protection logic + import

Testing

  • All 41 CI checks pass locally (format, lint, type-check, unit tests)
  • Tested scenario: deleting a non-default agent configured with default workspace no longer moves ~/.openclaw/workspace to Trash

Fixes

Fixes #53705

Changed files

  • src/commands/agents.commands.delete.ts (modified, +20/-1)

Code Example

{"0":"Moved to Trash: ~/.openclaw/workspace","time":"2026-03-24T11:35:30.545Z"}
This occurred immediately after running openclaw agents delete minimax-25 --force at 11:35:30.502Z.
RAW_BUFFERClick to expand / collapse

Bug type

Behavior bug (incorrect output/state without crash)

Summary

When running openclaw agents delete <agent-id> --force on an agent that uses a shared workspace (i.e., workspace path that is also used by other agents), the command incorrectly moves the entire shared workspace to Trash, instead of:

  1. Refusing to delete with a clear error about shared workspace
  2. Only deleting the agent's isolated files (under ~/.openclaw/agents/<agent-id>/)

Steps to reproduce

  1. Have multiple agents configured to share the same workspace (e.g., all pointing to ~/.openclaw/workspace)
  2. Run openclaw agents delete <some-agent> --force
  3. Observe that ~/.openclaw/workspace is moved to Trash

Expected behavior

The command should either: • Detect that the workspace is shared and refuse to proceed, or • Only delete the agent-specific directory under ~/.openclaw/agents/<agent-id>/

Actual behavior

The shared workspace at ~/.openclaw/workspace is moved to Trash, wiping all agent configuration files (SOUL.md, USER.md, IDENTITY.md, MEMORY.md, AGENTS.md, etc.) and memory files (MEMORY.md and memory/* )

OpenClaw version

OpenClaw 2026.3.23-2

Operating system

MacOS 15.7.4

Install method

No response

Model

MiniMax 2.5

Provider / routing chain

openclaw -> minimax/MiniMax-M2.5

Additional provider/model setup details

No response

Logs, screenshots, and evidence

{"0":"Moved to Trash: ~/.openclaw/workspace","time":"2026-03-24T11:35:30.545Z"}
This occurred immediately after running openclaw agents delete minimax-25 --force at 11:35:30.502Z.

Impact and severity

Affected: Workspace directory Severity: Very high. Complete workspace data loss Frequency: Apparently always - but not rerunning that command to test! Consequence: Loss of all agent configuration files (SOUL.md, USER.md, IDENTITY.md, MEMORY.md, AGENTS.md, etc.) and memory files (MEMORY.md and memory/*)

Additional information

No response

extent analysis

Fix Plan

To resolve the issue, we need to modify the openclaw agents delete command to check if the workspace is shared before deleting it. If the workspace is shared, the command should either refuse to proceed or only delete the agent-specific directory.

Here are the steps to fix the issue:

  • Modify the delete_agent function to check if the workspace is shared:
def delete_agent(agent_id, force=False):
    # Get the agent's workspace path
    workspace_path = get_workspace_path(agent_id)
    
    # Check if the workspace is shared
    if is_workspace_shared(workspace_path):
        if force:
            # Only delete the agent-specific directory
            agent_dir = os.path.join('~/.openclaw/agents/', agent_id)
            shutil.rmtree(agent_dir)
        else:
            # Refuse to delete the shared workspace
            print("Error: Cannot delete shared workspace. Use --force to delete only the agent-specific directory.")
            return
    else:
        # Delete the workspace
        shutil.rmtree(workspace_path)
  • Implement the is_workspace_shared function to check if the workspace is shared:
def is_workspace_shared(workspace_path):
    # Get a list of all agents
    agents = get_all_agents()
    
    # Check if any other agent uses the same workspace
    for agent in agents:
        if agent['id'] != agent_id and agent['workspace'] == workspace_path:
            return True
    
    return False
  • Update the openclaw agents delete command to use the modified delete_agent function:
def delete_agent_cmd(args):
    agent_id = args.agent_id
    force = args.force
    
    delete_agent(agent_id, force)

Verification

To verify that the fix worked, you can test the openclaw agents delete command with the --force flag on an agent that uses a shared workspace. The command should only delete the agent-specific directory and not the shared workspace.

You can also test the command without the --force flag to ensure that it refuses to delete the shared workspace.

Extra Tips

  • Make sure to update the documentation for the openclaw agents delete command to reflect the new behavior.
  • Consider adding a warning message when deleting an agent that uses a shared workspace, to remind the user that the shared workspace will not be deleted.

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…

FAQ

Expected behavior

The command should either: • Detect that the workspace is shared and refuse to proceed, or • Only delete the agent-specific directory under ~/.openclaw/agents/<agent-id>/

Still need to ship something?

×6

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

Back to top recommendations

TRENDING