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.
.claude/settings.jsonWhat 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.jsonThe 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