Claude Code & Codex

Before Claude Code Edits Anything: A Two-Minute Session Checklist

Coding agents work fast, which makes a wrong branch or a dirty working tree expensive within minutes. This is the preflight I run at the start of every session, the five-line report it produces, and the safe way back when work ends up in the wrong place.

A terminal showing a five-line preflight report before a coding session: repository, branch, clean tree, commits since the last handover and constraints

A whole session of work once landed on the wrong branch: the agent created a new branch instead of using the agreed one, and everything it built went there. It was recoverable only because every change had been committed cleanly.

That's the case for a Claude Code session checklist: a two-minute preflight before the agent edits anything. It confirms the repository, the branch, the state of the working tree and the latest handover, and it costs less than reading one wrong diff.

At a glance

  • Run the preflight before any edit: repository, branch and worktree, uncommitted changes, sync with the remote, recent commits, the agent guide and the newest handover entry.
  • If there are changes you didn't make, stop and ask. Don't stash, reset or commit someone else's work.
  • Report in five lines or fewer, then restate the task with its non-goals and the checks you'll run at the end.
  • If work landed on the wrong branch: don't delete anything, cherry-pick the commits onto the intended branch, re-run the checks, and keep the wrong branch until the owner confirms.
  • The free starter kit's coding-agent-session-start skill runs this whenever you say "start", "continue" or "where were we".

Why do coding sessions go wrong in the first five minutes?

Because a coding agent acts on whatever it finds, and it finds things quickly. In the first minutes of a session, it decides which repository it's in, which branch to work on and what state the code is in. A human would notice that the branch name looks odd or that there are uncommitted files from yesterday. An agent will often just start.

The common failures are all cheap to prevent and expensive to undo:

  • Wrong branch. Work happens on main, on a stale branch, or on a new branch the agent invented.
  • Someone else's changes. Uncommitted files from another session or another agent get stashed, overwritten or committed under the wrong message.
  • Out of sync. The local branch is behind the remote, so the agent rebuilds something that already exists.
  • Busy ports and running jobs. Another agent's dev server already holds port 3000, and a second one starts on 3001 without anyone noticing which is which.
  • A push that deploys. On Vercel, every push to a non-production branch builds a preview deployment, and whether that preview is public depends on your Deployment Protection settings.1

The preflight, step by step

These are the eight steps of the free coding-agent-session-start skill. Steps 1 to 5 are git commands any agent can run; steps 6 to 8 are reading and thinking.

  1. Repository. git rev-parse --show-toplevel. If several repositories are involved, confirm which one may be edited, and treat the others as read-only context.
  2. Branch and worktree. git branch --show-current and git worktree list. Compare them with what the agent guide or the newest handover says.
  3. Uncommitted work. git status --short. If there are changes you didn't make, stop and ask.
  4. Sync. git fetch, then git status -sb. Pull only with --ff-only, and only if the guide allows it.
  5. History since the handover. git log --oneline -10. Note anything committed after the newest handover entry.
  6. Guide and handover. Read the whole agent guide (CLAUDE.md or AGENTS.md) and the newest handover entry. List the constraints: fenced files, push rules, ports in use, models or services that must not change.
  7. What's running. Before starting a dev server, check the port, for example with lsof -i :3000.
  8. Restate the task in one sentence, with what you're not doing and the checks you'll run at the end.

The report that comes out of it should fit in five lines:

Preflight: repo shop, branch feature/rate-limit (matches handover ✓), tree clean ✓, up to date ✓
Since last handover: 2 commits (a1b2c3 fix login copy, d4e5f6 add rate limit)
Constraints: no push without OK; don't touch src/data/; port 3000 belongs to the other agent
Task: raise the site-wide daily cap. Not doing: refactoring the counter. Checks: npm test, one manual sign-up

The point of the report isn't ceremony. It's that you, the owner, can read four lines and see a wrong branch or a surprise commit before the agent builds on it.

Practical takeaway

The preflight finds problems; it doesn't fix them. If the branch doesn't match or the tree is dirty, the right move is to report and ask, not to "clean up". Cleaning up someone else's work is how it gets lost.

What should the agent do if the tree is dirty?

Stop. Uncommitted changes the agent didn't make belong to someone: another session, another agent, or you. The tempting commands are the dangerous ones:

Tempting commandWhat it does to someone else's work
git stashHides it. Often forgotten, sometimes dropped later.
git reset --hardDeletes uncommitted changes to tracked files. Gone.
git clean -fdDeletes untracked files and folders. Gone.
git commit -am "wip"Commits it under a message that means nothing, mixed with new work.
git push --forceRewrites shared history on the remote.

The checklist's rule is simple: never run git reset --hard, git clean -fd or git push --force without explicit approval. You can also enforce this in Claude Code rather than relying on instructions. Hooks run as scripts at fixed points and are deterministic, unlike instructions in CLAUDE.md, which are advisory.2 A PreToolUse hook that blocks those commands makes the rule hold even in a long session.

How to recover when work landed on the wrong branch

If the commits exist, nothing is lost. The recovery is calm and mechanical:

  1. Don't delete anything. Committed work is safe as long as the branch exists.
  2. List the commits: git log --oneline <wrong-branch> -n 20.
  3. Switch and replay: git switch <intended-branch>, then git cherry-pick <sha> for each commit, oldest first.3
  4. Re-run every check on the intended branch. Tests that passed on the wrong base can fail on the right one.
  5. Push only the intended branch, and only if pushing is allowed.
  6. Keep the wrong branch until the owner confirms everything moved. Delete it only with their OK.
  7. Write it down. Add one line to the agent guide: "All work happens on <branch>."
Found
Work on the wrong branchCommits exist, nothing deleted
→
Replay
Cherry-pick, oldest firstOnto the branch you meant
→
Prove
Re-run every checkOn the new base, not the old one
→
Close
Owner confirmsThen, and only then, delete the old branch
Recovering work from the wrong branch without destructive commands.

Put the rules where every session reads them

A checklist that lives only in your head runs only when you remember it. Two places make it automatic:

  • The agent guide. Claude Code reads CLAUDE.md at the start of every session, and Codex reads AGENTS.md.4 5 A short section at the top ("Current work: branch feature/rate-limit. Read the newest entry in docs/handover.md first. Never push without approval.") gives every session the same starting point.
  • A skill. The coding-agent-session-start skill in the free starter kit runs the preflight and writes the report whenever you start, resume or switch tools. Its partner, coding-agent-handover, writes the entry the next preflight reads. The handover side is explained in the Claude Code handover guide.

If you run Claude Code and Codex on the same project, the two guides need to point at the same handover file, or each agent will follow a different truth. The setup is in how to use Claude Code and Codex together.

FAQ

Isn't this overkill for a solo project?

It takes two minutes, and the failure it prevents can cost a whole session. On a solo project the "other person" is usually you from yesterday, with uncommitted changes and a dev server still running.

Should the agent pull from the remote automatically?

Only with --ff-only, and only if the guide allows it. A fast-forward pull can't create merge conflicts or rewrite anything; if it fails, that's information the owner needs.

Can I run the preflight with a Claude Code hook instead?

Partly. A hook can run the git commands and print the result at the start of a session. Reading the guide, comparing it with the handover and restating the task still needs the model, so a skill or an instruction in CLAUDE.md covers that half.

Does this work in Codex and Cursor?

Yes. The commands are plain git, and the skill uses the open SKILL.md format, so it runs in Codex, Cursor and other agents that read skills.

Sources

  1. Environments: preview deployments, Vercel documentation.
  2. Best practices for Claude Code: set up hooks, Claude Code documentation.
  3. git-cherry-pick, Git documentation.
  4. How Claude remembers your project, Claude Code documentation.
  5. AGENTS.md, a format for guiding coding agents, stewarded by the Agentic AI Foundation.
Free starter kit

Get the free starter kit

Four complete skills for Claude, Claude Code and Codex: handover, session start, social captions and an honest exam-prep tutor. Free, so you can judge the standard.

Keep reading

Related articles

Claude Code & Codex The Claude Code Handover: End Every Session With a File the Next One Can Act On A Claude Code handover is the file a fresh session reads first. The template, the rules behind it, and a ready-to-paste prompt for the next chat. Claude Code & Codex How to Use Claude Code and Codex Together on One Repository Run Claude Code and Codex on one repo without collisions: one rulebook, CLAUDE.md vs AGENTS.md, one handover file, clear lanes and a reviewer. Claude Code & Codex Running Claude Code Overnight: Guardrails, Permissions and the Morning Report Let Claude Code work unattended without damage: the right permission mode, a no-touch list, self-checks, and a five-minute morning report.