The WhatsApp CLI now supports persistent authentication sessions. Your login credentials are saved locally and automatically restored on restart, eliminating the need to scan the QR code every time.
1. Start the app → "ℹ No existing session found - will require QR code scan"
2. QR code displays → Scan with WhatsApp on phone
3. Session saved under `~/.whatsapp-cli/auth/`
4. CLI starts normally
1. Start the app → "✓ Found existing session - using saved authentication"
2. App authenticates instantly using saved token
3. No QR code needed unless session expires
4. CLI starts normally
- Location:
~/.whatsapp-cli/auth/directory (auto-created) - Contents: WhatsApp Web session data and authentication tokens
- Size: ~5-10MB
- Lifetime: Session persists until manually logged out
When you start the app, it will display:
✓ Found existing session - using saved authentication→ Using saved sessionℹ No existing session found - will require QR code scan→ New authentication needed
From the main menu, select Option 8: Logout & reset
⚠️ Clear authentication and logout? (yes/no): yes
✓ Logged out successfully
✓ Authentication session cleared
✅ Session cleared. Restart the app to re-authenticate.
This will:
- Disconnect from WhatsApp
- Delete the saved session
- Force QR code re-scan on next run
If the app won't start or session is corrupted:
# Windows
Remove-Item -Path "$HOME\.whatsapp-cli\auth" -Recurse -Force
# macOS/Linux
rm -rf ~/.whatsapp-cli/authThen restart the app to re-authenticate.
✅ Auto-reconnect on restart - Session automatically restored ✅ Network resilience - Automatic reconnection if disconnected ✅ Session validation - Checks if session still valid before using ✅ Manual control - Option to logout and reset anytime ✅ Graceful fallback - If session invalid, prompts for QR scan
Problem: App asks for QR code every restart
Solutions:
- Check if
~/.whatsapp-cli/auth/exists - Ensure app has write permissions in the directory
- Check disk space availability (~10MB required)
- Try manual logout (Option 8) then restart
Problem: Session exists but is no longer valid
Solutions:
- Use Option 8 to logout and clear
- Restart app and scan QR code again
- This happens after ~30 days of inactivity
Warning: Running the app simultaneously in multiple terminals can corrupt the session.
Solution: Run only one instance at a time.
- Session Token: The saved token can be used to access your WhatsApp
- File Permissions: Protect the
~/.whatsapp-cli/auth/directory - Sharing: Don't share or commit this folder to version control
- Cleanup: Delete the folder if you stop using the app
The runtime session data is stored outside the repo by default, under ~/.whatsapp-cli/auth/.
If you override WHATSAPP_CLI_DIR into the repo, make sure the auth directory stays ignored.
// Check if session already exists - if so, reuse it
const authPath = PATHS.auth;
const sessionExists = await fs
.access(authPath)
.then(() => true)
.catch(() => false);
if (sessionExists) {
console.log("✓ Found existing session - using saved authentication");
}export async function clearAuthSession(): Promise<void> {
if (clientInstance) {
await clientInstance.logout();
}
await fs.rm(PATHS.auth, { recursive: true, force: true });
clientInstance = null;
initPromise = null;
}async function handleLogout(): Promise<void> {
const confirmation = await promptUser(
process.stdin as any,
"⚠️ Clear authentication and logout? (yes/no): ",
);
if (confirmation.toLowerCase() === "yes") {
await clearAuthSession();
console.log("✅ Session cleared. Restart the app to re-authenticate.");
state.isExiting = true;
}
}- Save your session - Your token is only valid for ~30 days
- Logout on shared computers - Always use Option 8 before leaving
- Regular restarts - Restart app monthly to refresh token
- Monitor disk space - Session folder uses minimal space (~10MB)
- Keep app updated - Update regularly for security patches
Session Persistence enables seamless workflow - authenticate once, use multiple times!