Skip to main content
hook official · GitHub

session-auto-commit — GitHub Copilot hook: what it does

At the end of a GitHub Copilot session, this hook commits changed files and tries to push them to the remote repository. Use it to save session work automatically.

Install into Claude Code · Manually: put the files in place All methods and platforms ↓
.claude/settings.json
Open on GitHub

What session-auto-commit does

The hook runs on the sessionEnd event. It checks that the working directory is a Git repository and looks for uncommitted changes. When it finds any, it stages them with git add -A, creates a commit with a timestamp, then attempts to push. It uses --no-verify, so pre-commit hooks are bypassed.

To install it, copy the hook folder into .github/hooks/, make auto-commit.sh executable, and commit the hook configuration to the repository’s default branch. Git credentials must be set up for pushes. A failed push does not prevent the session from ending, but the changes will not reach the remote. Set SKIP_AUTO_COMMIT=true or remove the sessionEnd entry from hooks.json to pause automatic commits.

What it helps with

  • commit Git changes when a Copilot session ends
  • add a timestamp to automatic commits
  • push session changes to a remote repository
  • avoid creating a commit when there are no changes

Example prompts for the agent

  • When this session ends, save the project changes in Git.
  • Commit and push my changes automatically when I finish.
  • End the session and save the current changes to the repository.

How to install session-auto-commit

Manually: put the files in place

.claude/settings.json

The hooks block: event (PreToolUse, PostToolUse, Stop…) → command. Personal ones go to ~/.claude/settings.json

Step by step, with commands for each platform: Claude Code hooks: what they are, where to configure them, how to block a risky command

Questions about session-auto-commit

How do I install session-auto-commit for GitHub Copilot?

Copy the hook folder with cp -r hooks/session-auto-commit .github/hooks/, then run chmod +x .github/hooks/session-auto-commit/auto-commit.sh. Commit the hook configuration to the repository’s default branch.

What does session-auto-commit do?

When a Copilot session ends, it checks for uncommitted changes, stages them, creates a timestamped commit, and attempts to push it to the remote repository.

Does session-auto-commit need Git credentials?

Yes. Git credentials must be configured for the hook to push commits to the remote repository.

Source text

session-auto-commit · MIT
---
name: 'Session Auto-Commit'
description: 'Automatically commits and pushes changes when a Copilot coding agent session ends'
tags: ['automation', 'git', 'productivity']
---

# Session Auto-Commit Hook

Automatically commits and pushes changes when a GitHub Copilot coding agent session ends, ensuring your work is always saved and backed up.

## Overview

This hook runs at the end of each Copilot coding agent session and automatically:
- Detects if there are uncommitted changes
- Stages all changes
- Creates a timestamped commit
- Pushes to the remote repository

## Features

- **Automatic Backup**: Never lose work from a Copilot session
- **Timestamped Commits**: Each auto-commit includes the session end time
- **Safe Execution**: Only commits when there are actual changes
- **Error Handling**: Gracefully handles push failures

## Installation

1. Copy this hook folder to your repository's `.github/hooks/` directory:
   ```bash
   cp -r hooks/session-auto-commit .github/hooks/
   ```

2. Ensure the script is executable:
   ```bash
   chmod +x .github/hooks/session-auto-commit/auto-commit.sh
   ```

3. Commit the hook configuration to your repository's default branch

## Configuration

The hook is configured in `hooks.json` to run on the `sessionEnd` event:

```json
{
  "version": 1,
  "hooks": {
    "sessionEnd": [
      {
        "type": "command",
        "bash": ".github/hooks/session-auto-commit/auto-commit.sh",
        "timeoutSec": 30
      }
    ]
  }
}
```

## How It Works

1. When a Copilot coding agent session ends, the hook executes
2. Checks if inside a Git repository
3. Detects uncommitted changes using `git status`
4. Stages all changes with `git add -A`
5. Creates a commit with format: `auto-commit: YYYY-MM-DD HH:MM:SS`
6. Attempts to push to remote
7. Reports success or failure

## Customization

You can customize the hook by modifying `auto-commit.sh`:

- **Commit Message Format**: Change the timestamp format or message prefix
- **Selective Staging**: Use specific git add patterns instead of `-A`
- **Branch Selection**: Push to specific branches only
- **Notifications**: Add desktop notifications or Slack messages

## Disabling

To temporarily disable auto-commits:

1. Remove or comment out the `sessionEnd` hook in `hooks.json`
2. Or set an environment variable: `export SKIP_AUTO_COMMIT=true`

## Notes

- The hook uses `--no-verify` to avoid triggering pre-commit hooks
- Failed pushes won't block session termination
- Requires appropriate git credentials configured
- Works with both Copilot coding agent and GitHub Copilot CLI


```json
{
  "version": 1,
  "hooks": {
    "sessionEnd": [
      {
        "type": "command",
        "bash": ".github/hooks/session-auto-commit/auto-commit.sh",
        "timeoutSec": 30
      }
    ]
  }
}

```

© github · MIT · github/awesome-copilot

Similar hooks

All hooks for Git and GitHub →

From the same set952

The whole set →
ai-prompt-engineering-safety-best-practices This rule guides prompt writing with clear context, constraints, and output formats. It also asks developers to consider safety and bias when creating or reviewing prompts. ★ 40,451repo stars agents A rule file that sets the format for GitHub Copilot custom agent files: which frontmatter fields are required, how tools and handoffs work. ★ 40,451repo stars agent-skills Provides guidelines for creating portable Agent Skills for GitHub Copilot. It ensures SKILL.md files follow proper frontmatter formats, directory structures, and workflow layouts. ★ 40,451repo stars agent-safety This rule sets access controls, policy checks, and audit guidance for code built with AI agents. Use it when implementing tool-calling or multi-agent systems. ★ 40,451repo stars secrets-scanner Scans the files a Copilot coding agent touched during a session for leaked keys and credentials before they get committed. Useful when the agent edits code fast. ★ 40,451repo stars governance-audit Scans GitHub Copilot prompts for threat patterns before execution. It records events to a local JSON log and stops destructive actions based on governance settings. ★ 40,451repo stars fix-broken-links This hook checks links in recently edited web files after GitHub Copilot uses a tool. It helps catch dead URLs and vague link labels before they linger in the project. ★ 40,451repo stars dependency-license-checker A GitHub Copilot hook that scans newly added dependencies at session end and flags copyleft licenses before they get committed. ★ 40,451repo stars

Project sponsors

Companies that keep this analytics open
Gold sponsor

Impressions, clicks and code copies — open statistics. We keep the numbers public for the same reason NeBlask itself is public. Become a sponsor