Try free

Last updated 13 October 2026

Clear the Claude Code command history

History builds up in your development environment

Claude Code keeps track of what you say and do to maintain context. This is helpful for long coding tasks but creates a trail of prompts and responses on your disk. If you accidentally paste a secret or a sensitive API key into the terminal, that data stays in the session logs. You need a way to scrub this information before it becomes a liability or simply clutters your workspace. Every developer has experienced the moment where they realize a private configuration string was included in a large copy and paste operation.

Clutter also slows you down mentally. When you use the command to resume a session, seeing a long list of old experiments makes it harder to find the work that actually matters. Removing old history is not just about privacy; it is about keeping your focus on the current task. You should treat your command history like a temporary scratchpad that needs regular cleaning to stay effective. A clean environment ensures that the agent does not pull in irrelevant information from an old conversation that no longer applies to your current architecture.

Clear the current session context

Inside an active Claude Code session, you can use the /clear command to wipe the current conversation history. This command resets the internal state of the agent for that specific session. It does not delete the files on your disk, but it ensures that the agent no longer remembers the previous prompts or the specific file edits from that session. This is the fastest way to start fresh if the conversation has become too long or if the agent has lost the thread of your instructions.

You might also use the /compact command if you want to keep the important parts of the history while removing the bulk. This command summarizes the session so far and frees up space in the context window. It is useful when the session is still active but you want to reduce the amount of data the agent has to process. While this does not delete the history from your storage, it changes what the agent sees in the current working memory and helps prevent the context window from becoming overloaded with redundant information.

Remove project specific settings and local logs

Claude Code stores data in a directory named .claude within your project root. This folder contains settings.json and settings.local.json which might hold specific configurations for your project. If you want to wipe the history for a specific repository, you can delete this folder entirely. Deleting the .claude directory removes any locally tracked information that the agent uses to remember your preferences or session state for that specific path. This is a common step when preparing a repository for a new contributor or moving a project to a new environment.

Be careful when deleting these files if you have custom slash commands or subagents. Custom commands are stored as markdown files in .claude/commands and subagents are in .claude/agents. If you only want to clear the history, focus on the settings files and any log files generated by the tool. If you have configured MCP servers in .mcp.json, that file is also in your project root and should be checked if it contains any sensitive connection strings you want to remove. Always check your .gitignore file to ensure these local configuration directories are not being tracked by your version control system.

Manage the global user history and settings

Your primary identity and global settings for Claude Code live in your home directory under the ~/.claude folder. This is where the global CLAUDE.md and settings.json files are stored. These files apply to every project where you run the agent. If you find that the agent is remembering things across different projects that you want it to forget, you must look in this global directory. This directory is the central hub for your user profile and is used to store persistent state that follows you across your file system.

The global directory often stores authentication tokens and persistent session data. Running the /logout command is a good first step to clear your session on the server side. To completely reset the local installation, you can remove the contents of ~/.claude. This will force you to run the /login command again and will reset any global permissions you have granted to the agent in the past. This level of cleanup is usually reserved for when you are handing over a machine or troubleshooting a deep configuration issue that is affecting all your projects.

Clean the terminal shell history

The command line interface itself remembers the commands you type. Even if you clear the Claude Code internal history, your terminal shell like zsh or bash likely recorded the initial claude commands and any prompts you passed with the -p flag. You can use the Ctrl+R key combination to search your shell history and see what has been recorded. To truly remove the record of your work, you must clear your shell history file, which is usually found in your home directory as .bash_history or .zsh_history.

If you frequently pass sensitive data as arguments to the claude command, consider using the interactive interface instead. Commands typed inside the agent session are handled differently than those typed directly into your shell. Clearing the shell history is a separate step from clearing the agent history. You should check your shell configuration to see if it is saving every line you type to a permanent file on your disk. Many developers use a space before a command in their terminal to prevent it from being recorded in the history, which is a helpful habit when dealing with tokens.

Automating cleanup with hook events

You can use hook events to manage how history is handled automatically. The SessionEnd hook is a good place to trigger a script that clears out temporary files or logs. By defining actions that happen during SessionEnd or Stop, you can ensure that your environment stays clean without manual intervention. This is done by writing logic that responds to these specific events within your configuration files. This ensures that you do not leave a digital trail behind every time you close a session.

Another useful hook is PreCompact. Since the /compact command is used to manage context, you can use this hook to inspect what is being summarized or to perform a cleanup before the agent shrinks the history. Using hooks requires a bit of setup in your settings.json file under the hooks section, but it provides a way to make privacy and cleanliness a default part of your workflow rather than a chore you have to remember. Automation is the best defense against accidental data leaks in a busy development cycle.

Organizing sessions to prevent history sprawl

One way to avoid the need for massive history deletions is to keep your sessions small and focused. Instead of having one massive session that lasts for days and touches every part of your project, create small sessions for specific tasks. This makes it easier to use the claude --resume command to find a specific piece of work later. It also means that when you are done with a task, you can simply stop using that session and the history remains isolated in its own context.

Using adhdTerminal can help with this organization. It runs many Claude Code sessions side by side as tiles on a wall. Each tile has a name and a color, which helps you keep different tasks separate. Because each tile is its own session, you do not end up with a single, giant history file that is hard to manage. When you finish a task in one tile, you can clear it or close it without affecting the context or history of your other active tasks. This visual separation makes it much easier to keep track of what needs to be deleted.

Control data flow with permissions and settings

You can prevent unwanted data from entering your history by using permission modes. By pressing Shift+Tab, you can cycle through modes like plan or bypassPermissions. If you are in plan mode, the agent will not execute tools that might change your files or create long logs until you approve the plan. You can also explicitly allow or deny specific tools in your settings.json file under the permissions key. This gives you granular control over what the agent is allowed to record and do.

Restricting the agent to only use specific tools like Read or Glob prevents it from creating a lot of TodoWrite or NotebookEdit entries that you might later want to delete. If you know you are working on a sensitive part of a project, you can use these settings to limit what the agent can see and record. This proactive approach to history management ensures that you only ever have to clear the data that you actually intended to generate. Setting permissions is a fundamental part of maintaining a secure and clean development environment.

Final steps for a complete wipe

If you want to be absolutely sure that everything is gone, you can run the claude doctor command. This command checks the health of your installation and can identify where files are stored. After running it, you can manually navigate to those directories and delete them. Follow this by a claude update to ensure your environment is restored to a clean, default state with the latest version of the tool. This process removes all cached data and resets the installation to its original state.

For developers who need to move between machines, remember that your history is local to the computer where you ran the session. If you use adhdTerminal, you can mirror your wall to an iPhone app over an end to end encrypted link. This allows you to see the status of your tasks without moving the actual history files off your primary machine. Keeping your history restricted to one physical device and one set of local files is the best way to maintain control over your data while still enjoying the mobility of a modern development workflow.

Questions people ask

Does /clear delete the conversation from the Anthropic servers?

The /clear command resets the local context window and the session state on your machine. It tells the agent to forget the current thread of conversation so you can start fresh. However, it does not directly manage data retention policies on the server side, which are governed by the terms of service of the provider.

Where is the list of previous sessions stored?

The list you see when you run claude --resume is generated from the session metadata stored in your project and user directories. These are typically kept in the .claude folders in your home directory or your project root. Deleting these folders will remove the entries from the resume list.

Can I recover a session after using /clear?

Once you use /clear, the current interactive context is wiped and cannot be recovered within that same session. If you need to go back to an earlier message, you can try pressing Escape twice before you clear the session to see the message history. If you have already cleared it, you would need to start a new session or use the resume command to find a previous state if it was saved.

Read next

More on when it goes wrong·All posts