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

# --resume Option

> Resume previous sessions to continue conversations

## Overview

The `--resume` (or `-r`) option allows you to resume a previous Qwen Code session, continuing where you left off with full conversation history intact. This is useful for long-running projects, multi-day tasks, or picking up interrupted work.

## Syntax

```bash theme={null}
qwen --resume <session-id>
qwen -r <session-id>
qwen --resume  # Opens session picker
```

## Basic Usage

### Resume Specific Session

```bash theme={null}
qwen --resume a1b2c3d4-e5f6-7890-abcd-ef1234567890
```

This restores:

* Full conversation history
* Context and token usage
* Session statistics
* Model selection
* Configuration settings

### Interactive Session Picker

Without a session ID, open the picker:

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

Displays:

```
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Select Session to Resume
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

  2h ago  › Building REST API with authentication
          a1b2c3d4-e5f6... | 45 messages | 12.5K tokens
          
  1d ago  › Refactoring database layer
          f1e2d3c4-b5a6... | 23 messages | 8.2K tokens
          
  3d ago  › Adding unit tests
          c1d2e3f4-a5b6... | 31 messages | 15.1K tokens

Use ↑↓ to navigate, Enter to select, Esc to cancel
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
```

### Continue Most Recent Session

Use `--continue` for the latest session:

```bash theme={null}
qwen --continue
qwen -c  # Short form
```

## Session Storage

### Where Sessions Are Saved

Sessions are stored in:

```
~/.qwen/sessions/
  ├── <project-hash>/
      ├── session-id-1.json
      ├── session-id-2.json
      └── ...
```

Each project (by directory path) has its own session storage.

### Session Data

Each session stores:

* Conversation history (messages)
* Model configuration
* Token usage statistics
* Tool call history
* Session metadata (start time, duration)
* Project context

### Session File Format

```json theme={null}
{
  "sessionId": "a1b2c3d4-e5f6-7890",
  "projectRoot": "/home/user/project",
  "startTime": "2024-03-10T14:30:00Z",
  "model": "qwen-coder-plus",
  "messages": [
    {
      "role": "user",
      "content": "Help me build a REST API",
      "timestamp": "2024-03-10T14:30:15Z"
    },
    {
      "role": "assistant",
      "content": "I'll help you build a REST API...",
      "timestamp": "2024-03-10T14:30:20Z"
    }
  ],
  "usage": {
    "inputTokens": 1234,
    "outputTokens": 567,
    "totalTokens": 1801
  }
}
```

## Use Cases

### Multi-Day Projects

```bash theme={null}
# Day 1
qwen --prompt "Start building the user management system"
# Session ID: abc123

# Day 2
qwen --resume abc123 --prompt "Continue with the authentication"

# Day 3  
qwen --resume abc123 --prompt "Now add authorization"
```

### Interrupted Work

```bash theme={null}
# Working on a task
qwen
> Implementing payment processing
# Interrupted by meeting

# Later, resume
qwen --continue
> Continue implementing payment processing
```

### Context Preservation

```bash theme={null}
# Build context over multiple sessions
qwen --session-id feature-auth
> Setup authentication

# Later, with full context
qwen --resume feature-auth
> Add OAuth support
# AI remembers previous authentication work
```

### Project Continuity

```bash theme={null}
# Project A
cd ~/projects/webapp
qwen
# Work on webapp

# Project B
cd ~/projects/api
qwen  
# Work on API

# Return to Project A with context
cd ~/projects/webapp
qwen --continue
# Resumes webapp session automatically
```

## Finding Session IDs

### View in Current Session

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

Session ID: a1b2c3d4-e5f6-7890-abcd-ef1234567890
```

### List All Sessions

```bash theme={null}
# List session files
ls -lh ~/.qwen/sessions/<project-hash>/

# View session metadata
cat ~/.qwen/sessions/<project-hash>/session-id.json | jq '.sessionId'
```

### Session Naming

Use custom session IDs:

```bash theme={null}
qwen --session-id feature-auth
# Later resume by name
qwen --resume feature-auth
```

## Resume with Options

### Resume with Different Model

```bash theme={null}
# Session was using qwen-turbo
qwen --resume abc123 --model qwen-coder-plus
# Continues with new model
```

### Resume in YOLO Mode

```bash theme={null}
qwen --resume abc123 --yolo
# Continue with auto-approval
```

### Resume with Prompt

```bash theme={null}
qwen --resume abc123 --prompt "Now implement feature X"
# Resumes and immediately executes prompt
```

### Resume in Headless Mode

```bash theme={null}
qwen --resume abc123 --prompt "Status update" --output-format json
# Non-interactive resume
```

## Session Management

### Delete Old Sessions

```bash theme={null}
# Delete sessions older than 30 days
find ~/.qwen/sessions -name '*.json' -mtime +30 -delete
```

### Export Session

```bash theme={null}
# Export session for backup or sharing
cp ~/.qwen/sessions/<project-hash>/session-id.json \
   ./my-session-backup.json
```

### Import Session

```bash theme={null}
# Import session from backup
cp ./my-session-backup.json \
   ~/.qwen/sessions/<project-hash>/session-id.json

qwen --resume session-id
```

### Clear Session History

```bash theme={null}
# Remove all sessions for current project
rm -rf ~/.qwen/sessions/<project-hash>/

# Remove all sessions
rm -rf ~/.qwen/sessions/
```

## Best Practices

<AccordionGroup>
  <Accordion title="Use Named Sessions">
    Create meaningful session IDs:

    ```bash theme={null}
    # Instead of:
    qwen
    # Random session ID

    # Use:
    qwen --session-id feature-user-auth
    # Easy to identify and resume
    ```
  </Accordion>

  <Accordion title="Resume Recent Sessions">
    For continuity, resume recent work:

    ```bash theme={null}
    # At start of day
    qwen --continue
    ```
  </Accordion>

  <Accordion title="Session Per Feature">
    Organize by feature or task:

    ```bash theme={null}
    qwen --session-id fix-bug-123
    qwen --session-id feature-notifications
    qwen --session-id refactor-auth
    ```
  </Accordion>

  <Accordion title="Clean Up Periodically">
    Remove old sessions:

    ```bash theme={null}
    # Monthly cleanup
    find ~/.qwen/sessions -name '*.json' -mtime +30 -delete
    ```
  </Accordion>
</AccordionGroup>

## Session Limitations

### Context Window

Resumed sessions still have token limits:

```bash theme={null}
qwen --resume abc123
> /stats
Context: 180,000 / 262,144 (68.7%)

# Compress if needed
> /compress
```

### File Changes

Sessions don't track external file changes:

```bash theme={null}
# Day 1: AI edits file.ts
qwen --session-id task

# Day 2: Someone else edits file.ts

# Resume: AI doesn't know about external changes
qwen --resume task
> Continue editing file.ts
# AI works from its last known state
```

### Model Availability

Resumed sessions might use different model if original unavailable:

```bash theme={null}
# Session used gpt-4
qwen --resume abc123
# Falls back to qwen-coder-plus if GPT-4 not configured
```

## Troubleshooting

### Session Not Found

```
Error: Session 'abc123' not found
```

**Solutions:**

1. Check session ID:
   ```bash theme={null}
   ls ~/.qwen/sessions/<project-hash>/
   ```

2. Use session picker:
   ```bash theme={null}
   qwen --resume  # Opens picker
   ```

3. Verify project directory:
   ```bash theme={null}
   # Sessions are project-specific
   cd correct-project-directory
   qwen --resume abc123
   ```

### No Sessions Available

```
No previous sessions found
```

**Causes:**

* No sessions created yet
* Chat recording disabled
* Sessions deleted or expired

**Solution:**

```bash theme={null}
# Enable chat recording
qwen --chat-recording=true

# Or in settings.json
{
  "session": {
    "chatRecording": true
  }
}
```

### Corrupted Session

```
Error: Failed to load session
```

**Solution:**

```bash theme={null}
# Validate session file
cat ~/.qwen/sessions/<project-hash>/session-id.json | jq .

# If corrupted, delete and start fresh
rm ~/.qwen/sessions/<project-hash>/session-id.json
qwen
```

## Advanced Usage

### Session Migration

```bash theme={null}
#!/bin/bash
# Migrate sessions to new machine

# On old machine
tar -czf qwen-sessions.tar.gz ~/.qwen/sessions/

# Transfer to new machine
scp qwen-sessions.tar.gz newmachine:

# On new machine
tar -xzf qwen-sessions.tar.gz -C ~/
qwen --resume
```

### Session Analytics

```bash theme={null}
#!/bin/bash
# Analyze session usage

find ~/.qwen/sessions -name '*.json' -exec jq -r '
  "\(.sessionId) | \(.messages | length) messages | \(.usage.totalTokens) tokens"
' {} \;
```

### Automated Resume

```bash theme={null}
#!/bin/bash
# Auto-resume last session on project entry

cd ~/my-project

if qwen --continue &> /dev/null; then
  echo "Resumed previous session"
else
  qwen
fi
```

## See Also

<CardGroup cols={2}>
  <Card title="--continue Option" icon="play" href="/cli/options/continue">
    Quick resume of most recent session
  </Card>

  <Card title="--session-id Option" icon="fingerprint" href="/cli/options/session-id">
    Create custom session identifiers
  </Card>

  <Card title="Session Management" icon="clock" href="/features/sessions">
    Complete guide to sessions
  </Card>

  <Card title="Context Management" icon="brain" href="/features/context-management">
    Managing conversation context
  </Card>
</CardGroup>
