Skip to main content

Overview

The /clear command clears the current conversation history, frees up context space, and starts a fresh session. This is useful when you want to begin a new topic or when your conversation history becomes too long.

Usage

In Interactive Mode

qwen
> /clear

Alternative Names

The following aliases are available:
  • /clear
  • /reset
  • /new

What It Does

When you run /clear, the command:
  1. Clears Terminal: Removes all messages from the display
  2. Resets Chat History: Clears the conversation context sent to the AI
  3. Starts New Session: Generates a new session ID
  4. Resets Metrics: Clears token usage and statistics
  5. Preserves Settings: Keeps your authentication and configuration

When to Use

Starting a New Topic

Clear when switching to an unrelated topic:
qwen
> Help me debug this authentication issue
...
> /clear
> Now let's work on the UI components

Context Window Full

If you’re approaching token limits:
> /clear
Consider using /compress instead if you want to preserve some context while reducing token usage.

Privacy Concerns

Clear sensitive information from context:
> /clear

Fresh Start

After completing a task:
> /clear

Behavior Details

What Gets Cleared

  • ✅ Conversation messages
  • ✅ Terminal display
  • ✅ Chat history context
  • ✅ Token usage metrics
  • ✅ Session statistics

What Gets Preserved

  • ✅ Authentication credentials
  • ✅ Model selection
  • ✅ Configuration settings
  • ✅ Custom themes
  • ✅ Extension settings

Session IDs

Each /clear generates a new session ID:
> /stats
Session ID: abc123-def456

> /clear
Starting a new session, resetting chat, and clearing terminal.

> /stats
Session ID: ghi789-jkl012

Clear vs Compress

Use /clear when:

  • Starting a completely new topic
  • Conversation is too long and unrelated
  • You want a fresh start
  • Clearing sensitive data

Use /compress when:

  • Continuing the same topic
  • Preserving important context
  • Optimizing token usage
  • Maintaining conversation flow
# Complete reset
qwen
> Help me with authentication
...
> /clear  # Start fresh
> Now help me with the database

Command Output

After running /clear:
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Starting a new session, resetting chat, and clearing terminal.
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Qwen Code - Type your message or /help for commands

Resuming Cleared Sessions

Cleared sessions are still saved and can be resumed:
# Clear current session
> /clear

# Later, resume the previous session
qwen --resume <previous-session-id>
View available sessions:
qwen --resume
This opens a session picker where you can select any previous session, including cleared ones.

Automation Examples

Clear After Each Task

#!/bin/bash
# Script to run multiple independent tasks

qwen --prompt "Task 1: Generate API docs"
qwen --prompt "Task 2: Write unit tests" # New session automatically
qwen --prompt "Task 3: Update README"     # Another new session
Each invocation starts a fresh session automatically in headless mode.

Conditional Clear

qwen
> Help me with this long task
...
# After 50 messages
> /compress  # Try compression first
...
# If still having issues
> /clear     # Start fresh if needed

Chat Recording

By default, cleared sessions are saved to disk. To disable recording:
qwen --chat-recording=false
With recording disabled:
  • No session history is saved
  • Cannot resume sessions
  • /clear still works but nothing is stored

/compress

Compress context while preserving information

/stats

View session statistics before clearing

--resume

Resume a previous session

--session-id

Use a custom session identifier

Troubleshooting

Clear Not Working

If /clear doesn’t seem to work:
  1. Verify you’re in interactive mode
  2. Check if there’s a pending operation
  3. Try force-quitting and restarting:
# Force quit
Ctrl+C

# Restart
qwen

Terminal Not Clearing

If the terminal display isn’t clearing:
# Manual terminal clear
qwen
> /clear
# Then press Ctrl+L or run:
> clear

Context Still Preserved

If the AI seems to remember cleared context:
  1. Wait a moment for the reset to complete
  2. Verify the new session ID changed: /stats
  3. Try restarting Qwen Code completely

Best Practices

Don’t clear too often - each clear loses valuable context:
  • Clear when switching major topics
  • Use /compress for minor topic shifts
  • Let conversations flow naturally
Before clearing, check your usage:
> /stats
You might not need to clear yet.
Note session IDs of important conversations before clearing:
> /stats  # Note the session ID
> /clear  # Now clear

# Later resume:
qwen --resume <noted-session-id>
Export before clearing if you want to keep a record:
> /export  # Save conversation
> /clear   # Then clear

See Also

Context Management

Learn about context and token management

Session Management

Understanding sessions and history

Interactive Mode

Full guide to interactive mode

CLI Overview

All CLI commands and options