Skip to main content

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

qwen --resume <session-id>
qwen -r <session-id>
qwen --resume  # Opens session picker

Basic Usage

Resume Specific Session

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

{
  "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

# 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

# Working on a task
qwen
> Implementing payment processing
# Interrupted by meeting

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

Context Preservation

# 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

# 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

qwen
> /stats

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

List All Sessions

# 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:
qwen --session-id feature-auth
# Later resume by name
qwen --resume feature-auth

Resume with Options

Resume with Different Model

# Session was using qwen-turbo
qwen --resume abc123 --model qwen-coder-plus
# Continues with new model

Resume in YOLO Mode

qwen --resume abc123 --yolo
# Continue with auto-approval

Resume with Prompt

qwen --resume abc123 --prompt "Now implement feature X"
# Resumes and immediately executes prompt

Resume in Headless Mode

qwen --resume abc123 --prompt "Status update" --output-format json
# Non-interactive resume

Session Management

Delete Old Sessions

# Delete sessions older than 30 days
find ~/.qwen/sessions -name '*.json' -mtime +30 -delete

Export Session

# Export session for backup or sharing
cp ~/.qwen/sessions/<project-hash>/session-id.json \
   ./my-session-backup.json

Import Session

# Import session from backup
cp ./my-session-backup.json \
   ~/.qwen/sessions/<project-hash>/session-id.json

qwen --resume session-id

Clear Session History

# Remove all sessions for current project
rm -rf ~/.qwen/sessions/<project-hash>/

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

Best Practices

Create meaningful session IDs:
# Instead of:
qwen
# Random session ID

# Use:
qwen --session-id feature-user-auth
# Easy to identify and resume
For continuity, resume recent work:
# At start of day
qwen --continue
Organize by feature or task:
qwen --session-id fix-bug-123
qwen --session-id feature-notifications
qwen --session-id refactor-auth
Remove old sessions:
# Monthly cleanup
find ~/.qwen/sessions -name '*.json' -mtime +30 -delete

Session Limitations

Context Window

Resumed sessions still have token limits:
qwen --resume abc123
> /stats
Context: 180,000 / 262,144 (68.7%)

# Compress if needed
> /compress

File Changes

Sessions don’t track external file changes:
# 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:
# 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:
    ls ~/.qwen/sessions/<project-hash>/
    
  2. Use session picker:
    qwen --resume  # Opens picker
    
  3. Verify project directory:
    # 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:
# Enable chat recording
qwen --chat-recording=true

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

Corrupted Session

Error: Failed to load session
Solution:
# 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

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

#!/bin/bash
# Analyze session usage

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

Automated Resume

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

--continue Option

Quick resume of most recent session

--session-id Option

Create custom session identifiers

Session Management

Complete guide to sessions

Context Management

Managing conversation context