TechBuzzPro

Opencode Sessions: How to Delete Them All Safely

· 6 min read · Apps & Browsers

In this article
  1. What Are OpenCode Sessions?
  2. Why Delete Sessions at All?
  3. How to List and Inspect Sessions First
  4. Deleting Individual Sessions
  5. Deleting All Sessions at Once
  6. Common Problems and Solutions
  7. Manual Deletion via File System
  8. Frequently Asked Questions

To delete all OpenCode sessions safely, use the built-in command opencode session delete --all in your terminal, which removes all session data. If you want to keep some sessions, use opencode session list to view them and opencode session delete <session-id> to remove individual ones.

What Are OpenCode Sessions?

OpenCode is a terminal-based AI coding assistant that runs in your command line. It stores a history of your conversations with the AI, including the prompts you typed, the responses you received, and the context of your code files. These are called sessions. Each session is like a saved chat log that lets you resume a previous conversation or review what you asked the AI to do. Sessions are stored locally on your machine, typically in a hidden directory like ~/.opencode or ~/.config/opencode, depending on your operating system and version.

Sessions are useful for continuity—you can start a task, close the terminal, and come back later to continue where you left off. But they also accumulate over time, taking up disk space and cluttering your workflow. Deleting them is a common housekeeping task, but you want to do it without accidentally losing important context or breaking your setup.

Why Delete Sessions at All?

There are several reasons you might want to clear out old sessions:

  • Disk space: Each session can contain large code snippets and long AI responses. Over months, this can add up to hundreds of megabytes.
  • Privacy: Sessions may contain proprietary code, personal notes, or sensitive information. If you share your computer or are preparing to sell it, deleting sessions is a good idea.
  • Performance: While OpenCode is generally fast, having thousands of sessions can slow down the session list and autocomplete features.
  • Fresh start: You might want to remove old experiments or failed attempts to keep your workspace clean.

Deleting sessions does not affect your actual code files—it only removes the conversation history. Your project files remain untouched.

How to List and Inspect Sessions First

Before deleting anything, you should see what sessions exist. Open your terminal and run:

opencode session list

This will show a table of sessions with their IDs, creation dates, and possibly a short title or the first few characters of the prompt. If you want more detail about a specific session, use:

opencode session show <session-id>

This prints the full conversation, so you can decide whether to keep it. You can also filter by project or date if your version supports flags like --project or --before. Check opencode session --help for the exact options your version offers.

Deleting Individual Sessions

If you only want to remove a few sessions, delete them one by one. First, get the session ID from the list command. Then run:

opencode session delete <session-id>

For example, if your session ID is abc123, you would run:

opencode session delete abc123

You can delete multiple sessions by passing multiple IDs:

opencode session delete abc123 def456 ghi789

This is the safest method because you explicitly choose what to remove. There is no undo, so double-check the IDs before confirming.

Deleting All Sessions at Once

To delete every session, run:

opencode session delete --all

This command will remove all session data from your machine. Some versions may ask for confirmation before proceeding. If your version does not, consider that the action is immediate and permanent. After deletion, you can verify with opencode session list—it should show an empty list or a message saying no sessions exist.

If you want to be extra safe, you can back up the session directory first. The default location is usually ~/.local/share/opencode on Linux, ~/Library/Application Support/opencode on macOS, and %APPDATA%\opencode on Windows. Copy that folder to a safe place (like a USB drive or cloud storage) before running the delete command. That way, if you later realize you needed a session, you can restore it by moving the backup back.

Common Problems and Solutions

Here are a few issues you might run into when deleting sessions, and how to handle them:

  • Command not found: If opencode is not recognized, make sure it is installed and in your PATH. You may need to install it via npm (npm install -g opencode) or your package manager.
  • Permission denied: If you get a permission error, the session files might be owned by another user or have restrictive permissions. Run the command with sudo (on Linux/macOS) or as administrator (on Windows), but be aware that this could affect other users' sessions.
  • Deletion does not free disk space: If you delete sessions but disk usage does not drop, there may be other cached data (like logs or temporary files) in the same directory. Check for a logs or cache subfolder and delete those too if needed.
  • Accidental deletion: If you delete a session by mistake, there is no built-in undo. However, if you backed up the session folder, you can restore the specific session's JSON file. Without a backup, the data is gone.

Manual Deletion via File System

If the command-line method fails or you prefer a more direct approach, you can delete sessions manually by removing the session files. Sessions are stored as JSON files in the data directory. Each session has a unique filename (usually the session ID). To delete all sessions:

  1. Close OpenCode completely.
  2. Navigate to the session directory. On Linux: ~/.local/share/opencode/sessions; macOS: ~/Library/Application Support/opencode/sessions; Windows: %APPDATA%\opencode\sessions.
  3. Delete the contents of that folder (or the entire folder).

This method is more error-prone because you might delete the wrong files, so only use it if you are comfortable with the file system. Always back up first.

Frequently Asked Questions

Will deleting sessions affect my code or settings?

No. Sessions are only conversation logs. Your code files, configuration files (like opencode.json), and any custom prompts are stored separately and will not be touched.

Can I recover a deleted session?

Only if you have a backup of the session directory. There is no recycle bin or trash for sessions. If you did not back up, the session is permanently gone.

Does deleting sessions log me out or reset my API key?

No. Your authentication tokens and API keys are stored in a separate auth file, not in sessions. Deleting sessions will not affect your login status.

How often should I delete sessions?

It depends on your usage. If you work on many projects, you might want to delete sessions monthly. If you rarely use OpenCode, you can leave them. There is no performance penalty unless you have thousands of sessions.

Is there a way to auto-delete old sessions?

OpenCode does not have a built-in auto-delete feature. You could write a cron job (on Linux/macOS) or a scheduled task (on Windows) that runs opencode session delete --all periodically, but be careful—that will delete all sessions, not just old ones.

What is the difference between a session and a conversation?

In OpenCode, they are the same thing. A session is a record of a conversation with the AI. The terms are used interchangeably.