Skip to content

Commit 261c28f

Browse files
tmchowclaude
andcommitted
feat(git-commit): pre-resolve context to reduce bash calls
Same pattern as git-commit-push-pr: on Claude Code, use !backtick pre-resolution for git status, diff, branch, log, and default branch. Non-CC platforms get a single fallback command. Also chains stage+commit into one call per commit group. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent b744f39 commit 261c28f

1 file changed

Lines changed: 39 additions & 16 deletions

File tree

  • plugins/compound-engineering/skills/git-commit

plugins/compound-engineering/skills/git-commit/SKILL.md

Lines changed: 39 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,31 +7,56 @@ description: Create a git commit with a clear, value-communicating message. Use
77

88
Create a single, well-crafted git commit from the current working tree changes.
99

10-
## Workflow
10+
## Context
1111

12-
### Step 1: Gather context
12+
**If you are not Claude Code**, skip to the "Context fallback" section below and run the command there to gather context.
13+
14+
**If you are Claude Code**, the five labeled sections below (Git status, Working tree diff, Current branch, Recent commits, Remote default branch) contain pre-populated data. Use them directly throughout this skill -- do not re-run these commands.
15+
16+
**Git status:**
17+
!`git status`
18+
19+
**Working tree diff:**
20+
!`git diff HEAD`
21+
22+
**Current branch:**
23+
!`git branch --show-current`
24+
25+
**Recent commits:**
26+
!`git log --oneline -10`
27+
28+
**Remote default branch:**
29+
!`git rev-parse --abbrev-ref origin/HEAD 2>/dev/null || echo '__DEFAULT_BRANCH_UNRESOLVED__'`
30+
31+
### Context fallback
1332

14-
Run these commands to understand the current state.
33+
**If you are Claude Code, skip this section — the data above is already available.**
34+
35+
Run this single command to gather all context:
1536

1637
```bash
17-
git status
18-
git diff HEAD
19-
git branch --show-current
20-
git log --oneline -10
21-
git rev-parse --abbrev-ref origin/HEAD
38+
printf '=== STATUS ===\n' && git status && printf '\n=== DIFF ===\n' && git diff HEAD && printf '\n=== BRANCH ===\n' && git branch --show-current && printf '\n=== LOG ===\n' && git log --oneline -10; printf '\n=== DEFAULT_BRANCH ===\n'; git rev-parse --abbrev-ref origin/HEAD 2>/dev/null || echo '__DEFAULT_BRANCH_UNRESOLVED__'
2239
```
2340

24-
The last command returns the remote default branch (e.g., `origin/main`). Strip the `origin/` prefix to get the branch name. If the command fails or returns a bare `HEAD`, try:
41+
---
42+
43+
## Workflow
44+
45+
### Step 1: Gather context
46+
47+
Use the context above (git status, working tree diff, current branch, recent commits, remote default branch). All data needed for this step is already available -- do not re-run those commands.
48+
49+
The remote default branch value returns something like `origin/main`. Strip the `origin/` prefix to get the branch name. If it returned `__DEFAULT_BRANCH_UNRESOLVED__` or a bare `HEAD`, try:
2550

2651
```bash
2752
gh repo view --json defaultBranchRef --jq '.defaultBranchRef.name'
2853
```
2954

3055
If both fail, fall back to `main`.
3156

32-
If the `git status` result from this step shows a clean working tree (no staged, modified, or untracked files), report that there is nothing to commit and stop.
57+
If the git status from the context above shows a clean working tree (no staged, modified, or untracked files), report that there is nothing to commit and stop.
3358

34-
Run `git branch --show-current`. If it returns an empty result, the repository is in detached HEAD state. Explain that a branch is required before committing if the user wants this work attached to a branch. Ask whether to create a feature branch now. Use the platform's blocking question tool (`AskUserQuestion` in Claude Code, `request_user_input` in Codex, `ask_user` in Gemini). If no question tool is available, present the options and wait for the user's reply before proceeding.
59+
If the current branch from the context above is empty, the repository is in detached HEAD state. Explain that a branch is required before committing if the user wants this work attached to a branch. Ask whether to create a feature branch now. Use the platform's blocking question tool (`AskUserQuestion` in Claude Code, `request_user_input` in Codex, `ask_user` in Gemini). If no question tool is available, present the options and wait for the user's reply before proceeding.
3560

3661
- If the user chooses to create a branch, derive the name from the change content, create it with `git checkout -b <branch-name>`, then run `git branch --show-current` again and use that result as the current branch name for the rest of the workflow.
3762
- If the user declines, continue with the detached HEAD commit.
@@ -55,18 +80,16 @@ Keep this lightweight:
5580

5681
### Step 4: Stage and commit
5782

58-
Run `git branch --show-current`. If it returns `main`, `master`, or the resolved default branch from Step 1, warn the user and ask whether to continue committing here or create a feature branch first. Use the platform's blocking question tool (`AskUserQuestion` in Claude Code, `request_user_input` in Codex, `ask_user` in Gemini). If no question tool is available, present the options and wait for the user's reply before proceeding. If the user chooses to create a branch, derive the name from the change content, create it with `git checkout -b <branch-name>`, then run `git branch --show-current` again and use that result as the current branch name for the rest of the workflow.
59-
60-
Stage the relevant files. Prefer staging specific files by name over `git add -A` or `git add .` to avoid accidentally including sensitive files (.env, credentials) or unrelated changes.
83+
If the current branch from the context above is `main`, `master`, or the resolved default branch from Step 1, warn the user and ask whether to continue committing here or create a feature branch first. Use the platform's blocking question tool (`AskUserQuestion` in Claude Code, `request_user_input` in Codex, `ask_user` in Gemini). If no question tool is available, present the options and wait for the user's reply before proceeding. If the user chooses to create a branch, derive the name from the change content, create it with `git checkout -b <branch-name>`, then continue.
6184

6285
Write the commit message:
6386
- **Subject line**: Concise, imperative mood, focused on *why* not *what*. Follow the convention determined in Step 2.
6487
- **Body** (when needed): Add a body separated by a blank line for non-trivial changes. Explain motivation, trade-offs, or anything a future reader would need. Omit the body for obvious single-purpose changes.
6588

66-
Use a heredoc to preserve formatting:
89+
For each commit group, stage and commit in a single call. Prefer staging specific files by name over `git add -A` or `git add .` to avoid accidentally including sensitive files (.env, credentials) or unrelated changes. Use a heredoc to preserve formatting:
6790

6891
```bash
69-
git commit -m "$(cat <<'EOF'
92+
git add file1 file2 file3 && git commit -m "$(cat <<'EOF'
7093
type(scope): subject line here
7194
7295
Optional body explaining why this change was made,

0 commit comments

Comments
 (0)