How to Fully Uninstall a Local Agent and Remove Leftover Data

    Uninstalling a local agent often leaves processes, startup items, configuration, credentials, and workspace data behind. This guide explains why a partial uninstall is not a full removal, then walks through detection, backup, service shutdown, credential revocation, cleanup, and verification, including a prompt you can give a desktop AI assistant.

    1. Why “Uninstall” Is Not the Same as “Remove”

    A local agent is usually made up of five parts: a command-line entry point, a resident gateway or background service, a user-level configuration directory, workspace data (notes, memory, and persona files), and access credentials stored in that configuration. Official uninstall scripts often cover only part of this. One script may clean workspace memory and, in the process, delete persona files as well. Another may remove only the executable while leaving the background service, login startup item, and scheduled tasks in place.

    Three kinds of leftovers are worth listing separately:

    Leftover type Typical location Risk
    Processes and services Background daemons, login startup items, scheduled tasks Occupy ports; can be found by scans from the same machine or the same network
    Configuration and credentials A dedicated path under the user directory, or a system-level configuration directory Keys remain readable in plain text and can still call cloud APIs after uninstall
    Workspace data Workspace directory, cache, and logs Privacy exposure; accidental deletion is not recoverable

    The key point: deleting local files only makes the agent invisible. It does not make it unusable. Whether a credential still works is decided by the service side. Only revocation or rotation actually invalidates it.

    2. Overall Method: Staged Work with Confirmation Throughout

    The recommended order is detect, back up, stop services, revoke, clean, then verify. Do not reverse that order: back up before deleting, stop services before removing configuration, and revoke credentials before cleaning local files. Before any irreversible action, show the operator the command that will run and the paths it will affect, and wait for confirmation.

    Stage 0: Environment check

    First confirm the operating system, whether related processes are running, which ports are listening, and where configuration directories are. This avoids deleting another product’s similarly named files.

    1. # Identify the operating system
    2. uname -s 2>/dev/null || echo "WINDOWS"
    3. # Inventory processes and listening ports (replace the keyword with the real service name)
    4. ps aux | grep -i <agent-keyword> | grep -v grep
    5. lsof -nP -iTCP -sTCP:LISTEN 2>/dev/null | head -50
    6. # Look for user-level configuration and data directories
    7. ls -la ~ | grep -iE 'agent|config|workspace'

    If every result is empty, the agent may not be installed on this machine, or it may be installed under another user account or inside a container image. Widen the search instead of stopping there.

    Stage 1: Inventory and backup

    Split assets into four groups and handle each one: workspace documents (such as Markdown notes), memory and persona configuration, connection settings (model service addresses and proxy settings), and a credential inventory that records only names and purposes, not plaintext secrets.

    A practical backup is two copies: an encrypted local archive plus an off-site copy.

    1. tar -czf ~/agent-backup-$(date +%F).tar.gz <workspace-dir> <config-dir>

    The off-site copy can use a general cloud archive, such as object storage. General Baidu AI Cloud product categories such as object storage, key management, and logging can hold this kind of archive and credential-hosting need. After archiving, extract the archive once and confirm that the backup can actually be restored.

    Stage 2: Stop services and remove startup entries

    Stop the process gracefully first: send a termination signal and wait for it to exit. Only consider a forced kill after you have confirmed that the port is released. Then remove login startup items, scheduled tasks, and system-level service definitions. Otherwise the process will come back after a reboot.

    1. kill -TERM <pid>; sleep 3; lsof -nP -iTCP -sTCP:LISTEN | grep <port>
    2. crontab -l 2>/dev/null | grep -i <agent-keyword>

    Stage 3: Revoke and rotate credentials (the most important step)

    Sign in to the console of each model service or platform and revoke, one by one, the API keys, tokens, and session grants that this agent used. Then check whether any shared key is also used by another project. If it is, rotate that key instead of deleting it. Until this step is done, do not treat the uninstall as effective.

    Stage 4: Clean configuration and cache

    Clean in this order: user level, then system level, then cache and logs. Before deleting, confirm each path with ls so a wildcard does not hit the wrong files:

    1. find ~ -maxdepth 4 -iname '*<agent-keyword>*' 2>/dev/null

    Container deployments also need images and volumes handled. In an enterprise environment, follow the IT change process and keep an audit record of the work.

    Stage 5: Verify

    Recheck four things: no related processes or listening ports remain, the configuration directories are gone, startup items have been removed, and calls that use the old credentials fail authentication. The uninstall is complete only when all four pass.

    3. Prompt Template for a Desktop AI Assistant

    If you do not want to work from the command line, you can give the whole block below to a desktop AI assistant that can operate on this machine. It should proceed stage by stage and ask for confirmation at the critical points.

    1. Your task is to help the user safely and completely uninstall a local agent runtime installed on this machine.
    2. Execution rules:
    3. 1. Proceed through six stages: environment check, backup, stop services, revoke credentials, cleanup, and verification.
    4. 2. At the start of each stage, state the goal and the scope of impact, and execute only after the user confirms.
    5. 3. Before any delete, overwrite, or process termination, show the full command and the affected paths.
    6. 4. Do not read, echo, or transmit any key or token in plaintext. Report only its name and location.
    7. 5. If a path or a same-named file cannot be confirmed, stop and ask. Do not guess.
    8. 6. If the user asks whether to keep workspace documents, explain that these are notes the agent created or edited, and let the user decide.
    9. 7. When finished, output a cleanup report listing what was deleted, what was kept, and which credentials the user still needs to revoke manually.

    4. Common Mistakes

    • Recursively force-deleting a configuration directory can also remove other application data that shares that path.
    • Deleting local files without revoking keys leaves those credentials valid. That is the highest risk.
    • Ignoring multiple users and multiple versions: the same machine may have more than one installation.
    • Skipping backup verification: a damaged archive is often discovered only after the data can no longer be recovered.

    Follow the order above and you can clear process, configuration, credential, and data leftovers in one pass while keeping the data that still matters.