> ## Documentation Index
> Fetch the complete documentation index at: https://mintlify.com/QwenLM/qwen-code/llms.txt
> Use this file to discover all available pages before exploring further.

# /clear Command

> Clear conversation history and start a new session

## 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

```bash theme={null}
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:

```bash theme={null}
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:

```bash theme={null}
> /clear
```

<Note>
  Consider using `/compress` instead if you want to preserve some context while reducing token usage.
</Note>

### Privacy Concerns

Clear sensitive information from context:

```bash theme={null}
> /clear
```

### Fresh Start

After completing a task:

```bash theme={null}
> /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:

```bash theme={null}
> /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

<CodeGroup>
  ```bash Clear Example theme={null}
  # Complete reset
  qwen
  > Help me with authentication
  ...
  > /clear  # Start fresh
  > Now help me with the database
  ```

  ```bash Compress Example   theme={null}
  # Preserve context
  qwen
  > Help me build a REST API
  ...
  > /compress  # Summarize but keep context
  > Now add authentication to the API
  ```
</CodeGroup>

## 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:

```bash theme={null}
# Clear current session
> /clear

# Later, resume the previous session
qwen --resume <previous-session-id>
```

View available sessions:

```bash theme={null}
qwen --resume
```

This opens a session picker where you can select any previous session, including cleared ones.

## Automation Examples

### Clear After Each Task

```bash theme={null}
#!/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

```bash theme={null}
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:

```bash theme={null}
qwen --chat-recording=false
```

With recording disabled:

* No session history is saved
* Cannot resume sessions
* `/clear` still works but nothing is stored

## Related Commands

<CardGroup cols={2}>
  <Card title="/compress" icon="compress" href="/cli/compress">
    Compress context while preserving information
  </Card>

  <Card title="/stats" icon="chart-simple" href="/cli/stats">
    View session statistics before clearing
  </Card>

  <Card title="--resume" icon="clock-rotate-left" href="/cli/options/resume">
    Resume a previous session
  </Card>

  <Card title="--session-id" icon="fingerprint" href="/cli/options/session-id">
    Use a custom session identifier
  </Card>
</CardGroup>

## 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:

```bash theme={null}
# Force quit
Ctrl+C

# Restart
qwen
```

### Terminal Not Clearing

If the terminal display isn't clearing:

```bash theme={null}
# 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

<AccordionGroup>
  <Accordion title="Clear Strategically">
    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
  </Accordion>

  <Accordion title="Check Stats First">
    Before clearing, check your usage:

    ```bash theme={null}
    > /stats
    ```

    You might not need to clear yet.
  </Accordion>

  <Accordion title="Save Important Sessions">
    Note session IDs of important conversations before clearing:

    ```bash theme={null}
    > /stats  # Note the session ID
    > /clear  # Now clear

    # Later resume:
    qwen --resume <noted-session-id>
    ```
  </Accordion>

  <Accordion title="Combine with Export">
    Export before clearing if you want to keep a record:

    ```bash theme={null}
    > /export  # Save conversation
    > /clear   # Then clear
    ```
  </Accordion>
</AccordionGroup>

## See Also

<CardGroup cols={2}>
  <Card title="Context Management" icon="brain" href="/features/context-management">
    Learn about context and token management
  </Card>

  <Card title="Session Management" icon="clock" href="/features/sessions">
    Understanding sessions and history
  </Card>

  <Card title="Interactive Mode" icon="messages" href="/features/interactive-mode">
    Full guide to interactive mode
  </Card>

  <Card title="CLI Overview" icon="terminal" href="/cli/overview">
    All CLI commands and options
  </Card>
</CardGroup>
