Skip to content

Instantly share code, notes, and snippets.

@sohei1l
Last active July 15, 2025 08:19
Show Gist options
  • Select an option

  • Save sohei1l/f19cc1d91320db9db3a6cb7c63b312e6 to your computer and use it in GitHub Desktop.

Select an option

Save sohei1l/f19cc1d91320db9db3a6cb7c63b312e6 to your computer and use it in GitHub Desktop.
CLAUDE.md rule for Git based Undo/Checkpoint in Claude Code

⚠️ MANDATORY SESSION RULES - MUST FOLLOW IMMEDIATELY

IMPORTANT: At the VERY START of any coding task, you MUST:

  1. Create a new branch using the format: claude-session-YYYYMMDD-[topic]
  2. Push the branch to origin
  3. Start committing changes immediately

Session Workflow

Starting a Session

When user requests any code changes:

# Create feature branch
git checkout -b claude-session-YYYYMMDD-[topic]
git push -u origin claude-session-YYYYMMDD-[topic]

# Create draft PR (if using GitHub)
gh pr create --draft --title "WIP: [topic]" --body "Session started: [topic]"

During Session

  1. Commit after EVERY change without asking permission:

    git add -A && git commit -m "[action]: [description]"
  2. Push regularly (every 3-5 commits):

    git push origin HEAD
  3. Update PR with progress (if applicable):

    gh pr comment --body "✅ Completed: [what was done]"

Commit Message Format

Use these prefixes:

  • feat: New feature
  • fix: Bug fix
  • refactor: Code refactoring
  • style: Formatting/styling changes
  • docs: Documentation updates
  • chore: Maintenance tasks
  • test: Test-related changes

Example: git commit -m "feat: add user authentication"

Working Process

1. Understand First

  • Read existing code and documentation
  • Understand project structure before making changes
  • Ask clarifying questions if needed

2. Make Changes Incrementally

  • Write code in logical chunks
  • Commit after each meaningful change
  • Keep commits atomic and focused

3. Communication

  • Explain what you're doing and why
  • Point out potential issues or considerations
  • Suggest next steps after each change

Example Session Flow

# User: "Add error handling to the API"

# 1. IMMEDIATELY create branch
git checkout -b claude-session-20250116-error-handling
git push -u origin claude-session-20250116-error-handling

# 2. Make first change
# ... write error handling code ...
git add -A && git commit -m "feat: add try-catch to user controller"

# 3. Continue with more changes
# ... add validation ...
git add -A && git commit -m "feat: add input validation middleware"

# 4. Push commits
git push origin HEAD

# 5. Update documentation
# ... update README ...
git add -A && git commit -m "docs: update API error handling section"

# 6. Final push
git push origin HEAD

Session Completion

When task is complete:

# Mark PR as ready (if using PRs)
gh pr ready
gh pr edit --title "feat: [description of changes]"

# Or simply ensure all commits are pushed
git push origin HEAD

Key Reminders

  • User handles ALL testing and execution
  • You only write code and explain changes
  • Commit frequently without asking permission
  • Keep documentation updated
  • Professional commit messages only

Emergency Rollback

If user requests reverting changes:

# Rollback to specific commit
git reset --hard [commit-hash]
git push --force-with-lease origin HEAD
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment