Git and sessions are Claude Code's memory, and you can work with them safely only by distinguishing the sources of changes. Before any agent action it helps to separate three states: changes that existed before the run, changes of the current session and changes of other processes or people. Mixing them means losing control over what exactly goes into the commit, and one day overwriting someone else's work, taking it for session junk.
Hence a firm rule: never let the agent "clean up everything extra" if the working tree was dirty to begin with. The right request is to show git status, separate the changes that existed before the task and explicitly not touch them: do not roll back, do not format, do not include in the commit. This is cheap insurance against the most painful loss - when an autonomous agent "tidies up" and carries off uncommitted work you thought was safe.
Sessions store the conversation history, and you manage them both from the shell and from within. claude -c continues the last session of the current directory, claude -r resumes by name or ID, and you can append a task to it right away. Inside the CLI there are /rename, /resume, /branch, /clear and /export. The subtleties: --continue takes the last session of the directory context, --resume searches by name or ID, --fork-session on resume creates a new ID, /branch opens an alternative line of conversation, and /fork sends a copy to a separate background session.
It helps to gather the session commands side by side once, so as not to confuse continue, resume and branch. Below is management from the shell and from within the CLI. You return to this map when work on a task stretches over several runs: clear session names and a conscious choice between continuing, resuming by name and branching turn the history from a dump into a set of named lines of work.
Checkpointing and rewind are a local rollback mechanism, not a replacement for git. Claude Code saves snapshots before edits, and a double Esc on empty input or /rewind opens the options: restore only the conversation, only the files, both, or make a summary of the selected range. But a checkpoint does not track every external change: if files were changed by a hook, a formatter or a third-party process, the rollback boundaries must be checked - the automation may not see them.
Resuming after a long break has its cost. A long old session may require an expensive cold cache replay; on a subscription Claude Code may offer resume from summary. In practice discipline helps: give sessions clear names, end a logical task with /clear rather than growing the history endlessly, do a /recap before a pause, call /compact at a natural boundary rather than in the middle of a debug trace, and export the important result to an issue, a PR or docs.
Exporting the result outward is not a formality but protection from a single point of failure. If the whole task context lives only in the session transcript, you are hostage to that transcript: it will expire, compact or be lost. A result moved into an issue, a PR or a document survives any session and is available to the team. The transcript is working memory, not an archive; long-term history and review live in git and the tracker, not in the conversation with the agent.
For clearing project state there is a separate command, and it is destructive. claude project purge removes transcripts, task lists, debug logs, edit and prompt history, the project entry - so always --dry-run with an absolute path first. It is not meant for the ordinary "fix a stuck session". The typical failure is letting the agent tidy a dirty tree or confusing a checkpoint with a commit; the right approach is to separate the sources of changes, guard git as the real history and move results outward.
# Don't let the agent remove others' work from a dirty tree
Show git status and separate the changes that existed before this task.
Do not roll back, format or include them in the commit.# Sessions from the shell
claude -c # continue the last one in this directory
claude -r auth-refactor # resume by name/ID
claude -r auth-refactor "run the remaining regression tests"
# Inside the CLI: /rename /resume /branch /clear /export
# --continue (last), --resume (by name/ID), --fork-session (new ID)