# How to Automate Git Workflow with the Commit Commands Plugin in Claude Code

> Automate your Git workflow in Claude Code with the Commit Commands plugin. Streamline staging, message generation, and pull request creation for efficient development.

- Repository: [Anthropic/claude-code](https://github.com/anthropics/claude-code)
- Tags: how-to-guide
- Published: 2026-04-02

---

**The Commit Commands plugin provides three slash commands (`/commit`, `/commit-push-pr`, and `/clean_gone`) that automate staging, conventional commit message generation, branch management, and pull request creation directly within Claude Code.**

The **Commit Commands plugin** in the `anthropics/claude-code` repository transforms how developers interact with version control by enabling AI-driven Git automation through simple slash commands. This native extension eliminates context switching between your terminal and chat interface, allowing you to automate Git workflow with commit commands plugin in Claude Code for routine operations from committing changes to cleaning up stale branches.

## What Is the Commit Commands Plugin?

The Commit Commands plugin is a **metadata-driven extension** that registers three slash commands with Claude Code. Unlike traditional CLI tools, this plugin consists of Markdown command files stored in `plugins/commit-commands/commands/` that Claude reads at runtime. The [`plugin.json`](https://github.com/anthropics/claude-code/blob/main/plugin.json) file in `plugins/commit-commands/.claude-plugin/` registers the plugin, making the commands instantly available when the repository loads.

Because the plugin is pure metadata with no custom code, you can add it to any Claude Code-enabled repository by placing the `commit-commands` directory under `plugins/`. No compilation or package installation is required beyond having Git installed on your system.

## The Three Core Slash Commands

The plugin exposes three distinct commands for different stages of the Git lifecycle.

### /commit

The `/commit` command analyzes your working directory, drafts a **conventional-style commit message**, stages relevant files, and creates a single atomic commit. This command is ideal for quick, routine commits while iterating on features.

According to the source code in [`plugins/commit-commands/commands/commit.md`](https://github.com/anthropics/claude-code/blob/main/plugins/commit-commands/commands/commit.md), the command begins with a YAML header that permits specific Bash tool calls (e.g., `Bash(git add:*)`). Claude Code then runs `git status`, `git diff HEAD`, and `git log` to understand the repository state before generating a message that matches your project's existing commit style.

### /commit-push-pr

The `/commit-push-pr` command automates the full **feature-branch-to-PR workflow**. When invoked from the `main` branch, Claude Code:
1. Creates a new feature branch with a descriptive name
2. Runs the same analysis and commit steps as `/commit`
3. Pushes the branch to the remote with `git push -u origin <branch>`
4. Opens a pull request using `gh pr create` with an auto-generated description including a summary, test plan, and Claude Code attribution

This command requires the **GitHub CLI (`gh`)** to be installed and authenticated, as defined in [`plugins/commit-commands/commands/commit-push-pr.md`](https://github.com/anthropics/claude-code/blob/main/plugins/commit-commands/commands/commit-push-pr.md).

### /clean_gone

The `/clean_gone` command handles **repository hygiene** by scanning local branches for the `[gone]` status (branches deleted on the remote but still present locally). As implemented in [`plugins/commit-commands/commands/clean_gone.md`](https://github.com/anthropics/claude-code/blob/main/plugins/commit-commands/commands/clean_gone.md), the command:
1. Identifies stale branches using `git branch -vv`
2. Removes any associated work-trees
3. Deletes the stale branches with `git branch -D`
4. Reports the cleanup results back to you

## How the Plugin Works Under the Hood

The Commit Commands plugin operates through a structured five-phase execution model defined in the Markdown command files.

**Context Gathering**
Each command file contains a YAML frontmatter header that lists explicitly allowed tools. Claude Code uses this whitelist to determine which Bash commands it may invoke, ensuring security boundaries are respected.

**Dynamic Analysis**
The commands execute a standard discovery sequence: `git status` reveals the working tree state, `git diff HEAD` shows pending changes, and `git log` provides recent commit history. This context allows Claude to understand the repository's conventions and current state.

**Message Drafting**
Claude examines the diffs and recent commit history to produce messages following **conventional commit** standards (e.g., `feat:`, `fix:`, `refactor:`). The plugin respects repository-specific styles by analyzing existing patterns rather than using rigid templates.

**Tool Execution**
Claude issues permitted Bash calls (`git add`, `git commit`, `git push`, `gh pr create`) in a single response, creating an **atomic operation**. The security-reminder hook prevents commits of sensitive files like `.env` or credentials.

**Feedback**
After execution, Claude relays the operation results, including the new commit SHA or the PR URL (e.g., `https://github.com/anthropics/claude-code/pull/123`).

## Installation and Setup Requirements

Since the plugin lives in the `anthropics/claude-code` repository, you can activate it by ensuring the `plugins/commit-commands/` directory exists in your Claude Code configuration. The plugin requires:

- **Git** installed and configured
- **GitHub CLI (`gh`)** installed and authenticated (only for `/commit-push-pr`)
- Repository access permissions for the target remote

No additional installation steps are required beyond these prerequisites.

## Practical Usage Examples

Execute a standard commit with automatic message generation:

```text
/commit

```

Claude Code executes the following workflow:
1. Runs `git status` and `git diff HEAD` to analyze changes
2. Drafts a message such as `feat: add user-profile component`
3. Stages files with `git add` using the minimal necessary set
4. Creates the commit with `git commit -m "feat: add user-profile component"`
5. Returns the new commit SHA

Create a feature branch and open a PR in one command:

```text
/commit-push-pr

```

This triggers:
1. Branch creation (e.g., `feature-xyz`) if on `main`
2. Commit workflow execution
3. Remote push via `git push -u origin feature-xyz`
4. PR creation with `gh pr create --title "feat: add user-profile component" --body "..."`
5. URL return for review access

Clean up merged branches:

```text
/clean_gone

```

The command scans for `[gone]` branches, removes associated work-trees, deletes the branches, and reports the cleanup.

## Summary

- The Commit Commands plugin provides **three slash commands** (`/commit`, `/commit-push-pr`, `/clean_gone`) that automate Git operations within Claude Code.
- Commands are defined as **Markdown files** in `plugins/commit-commands/commands/` with YAML headers specifying allowed tools.
- The plugin generates **conventional commit messages** by analyzing `git diff` and repository history.
- `/commit-push-pr` requires the **GitHub CLI (`gh`)** and handles the complete feature-branch-to-PR workflow.
- A **security-reminder hook** prevents accidental commits of sensitive files like `.env`.

## Frequently Asked Questions

### Is the Commit Commands plugin safe for production repositories?

Yes. The plugin includes a **security-reminder hook** that blocks commits containing potentially sensitive files such as `.env` files or credential stores. Additionally, the YAML header in each command file explicitly whitelists permitted Bash tools, preventing arbitrary command execution.

### Do I need GitHub CLI installed to use the plugin?

You only need the **GitHub CLI (`gh`)** for the `/commit-push-pr` command, which creates pull requests. The `/commit` and `/clean_gone` commands function with Git alone. Ensure `gh` is authenticated with `gh auth login` before attempting PR creation.

### Can I customize the commit message format?

The plugin automatically adopts your repository's existing style by analyzing `git log` history. While you cannot override the format through configuration files, you can edit the markdown command files in `plugins/commit-commands/commands/` to adjust the prompting instructions that guide Claude's message generation.

### Where are the command definitions stored?

The command definitions reside in the `anthropics/claude-code` repository under `plugins/commit-commands/commands/`:
- `/commit` logic is in [`commit.md`](https://github.com/anthropics/claude-code/blob/main/commit.md)
- `/commit-push-pr` logic is in [`commit-push-pr.md`](https://github.com/anthropics/claude-code/blob/main/commit-push-pr.md)
- `/clean_gone` logic is in [`clean_gone.md`](https://github.com/anthropics/claude-code/blob/main/clean_gone.md)

The plugin registration occurs in [`plugins/commit-commands/.claude-plugin/plugin.json`](https://github.com/anthropics/claude-code/blob/main/plugins/commit-commands/.claude-plugin/plugin.json).