For the complete documentation index, see llms.txt. This page is also available as Markdown.

Quản lý Session trong Claude Code

Quản lý cuộc hội thoại trong Claude Code: resume, rewind, checkpoints, branching, worktrees và cách quản lý context window hiệu quả.

Claude Code lưu mọi conversation locally. Bạn có thể resume, rewind, branch, và manage context xuyên suốt các session — giúp task phức tạp kéo dài nhiều ngày vẫn giữ được continuity.

Session là gì?

Mỗi lần bạn chạy claude là một session mới. Session chứa:

  • Toàn bộ conversation (messages, responses)

  • Files đã đọc

  • Command outputs

  • Tool calls

Session được save locally và có thể resume bất cứ lúc nào.

Resume session

Tiếp tục session gần nhất

Terminal
claude --continue

Hoặc từ trong session:

Claude Code prompt
/resume

Chọn session từ list

Hiển thị list các sessions trước đó để bạn chọn.

Đặt tên session

Đặt tên descriptive giúp tìm lại session sau này. Treat sessions như branches — mỗi workstream có persistent context riêng.

Checkpoints và Rewind

Mỗi prompt bạn gửi tạo một checkpoint. Claude tự snapshot files trước mỗi change, nên checkpoint có thể restore cả conversation, code, hoặc cả hai.

Rewind

Hoặc:

Rewind menu hiển thị list checkpoints. Bạn có thể:

  • Restore conversation only — quay lại context tại thời điểm đó

  • Restore code only — revert files về state tại checkpoint

  • Restore both — cả conversation và code

  • Summarize from here — tóm tắt từ thời điểm đó, giữ context gần

  • Summarize up to here — tóm tắt trước đó, giữ context gần

Thay vì plan carefully mọi move, hãy bảo Claude thử something risky. Nếu không work, rewind và thử approach khác. Checkpoints save với conversation — bạn có thể close terminal, resume sau, và vẫn rewind được.

Branching session

Tạo nhánh hội thoại mới để explore approach khác nhau mà không mất context hiện tại:

Branching hữu ích khi:

  • Muốn thử 2 approaches khác nhau

  • Đang làm task A nhưng cần research task B

  • Muốn experiment mà không sợ mất context sạch

/clear vs /compact

/clear

Xóa toàn bộ context. Context window trở về trạng thái sạch.

Dùng khi:

  • Chuyển task không liên quan

  • Session quá dài, performance giảm

  • Đã sửa hơn 2 lần cùng vấn đề — cần fresh start

/compact

Nén context hiện tại — giữ summary quan trọng, giải phóng space.

Dùng khi:

  • Context gần đầy

  • Muốn tiếp tục task hiện tại nhưng cần thêm space

  • Muốn giữ context nhưng giảm token usage

Có thể thêm hướng dẫn cho compact:

Customize compaction behavior trong CLAUDE.md: "When compacting, always preserve the full list of modified files and any test commands".

So sánh

Tính năng

/clear

/compact

Xóa context

Hoàn toàn

Nén, giữ summary

Session tiếp tục

Cần re-explain

Tiếp tục với summary

Khi nào dùng

Switch task

Giữ task, thêm space

CLAUDE.md survives

Yes (re-reads từ disk)

Yes (re-reads từ disk)

Worktrees — chạy song song

Làm feature trong một terminal trong khi Claude fix bug trong terminal khác, không conflict:

Mỗi worktree là git checkout riêng trên branch riêng. Chạy lệnh trên với tên khác trong terminal thứ 2 để start isolated parallel session.

Quản lý Context Window

Context window là resource quan trọng nhất cần manage. Nó chứa:

  • Prompts và responses

  • Files đã đọc

  • Command outputs

  • Tool calls

Theo dõi usage

Hiển thị breakdown context đang dùng.

Quản lý context hiệu quả

  • Dùng subagents để research trong context riêng

  • /clear giữa unrelated tasks

  • /compact khi context gần đầy

  • /btw cho quick questions không cần giữ trong context

Câu trả lời xuất hiện trong dismissible overlay, không enter conversation history.

Resume giữa các thiết bị

Remote Control

Tiếp tục session từ phone hoặc browser khác:

Teleport

Chuyển session từ web/mobile về terminal:

Teleport yêu cầu claude.ai subscription.

Tài liệu tham khảo

Cập nhật lần cuối