Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion git/.claude-plugin/plugin.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "git",
"version": "1.4.0",
"version": "1.5.0",
"description": "Dynamic git instructions via SessionStart hook with mainline detection, conventional commits, fork handling, and safety guardrails",
"author": {
"name": "cblecker",
Expand Down
22 changes: 21 additions & 1 deletion git/CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ are needed.

```text
SessionStart → git-instructions.sh → stdout (instructions injected as context)
→ CLAUDE_ENV_FILE (git config overrides)
1. Detect mainline branch
2. Detect conventional commits
3. Detect fork setup
4. Output instructions with detected values
5. Write git config env overrides (if CLAUDE_ENV_FILE available)
```

### Prerequisite
Expand Down Expand Up @@ -62,6 +63,25 @@ instructions and warn the user if both built-in and plugin instructions are
present. This keeps detection logic out of the script and lets Claude handle it
contextually.

### Git config overrides via environment

Rather than modifying git config files (which the safety protocol forbids), the
script writes `GIT_CONFIG_COUNT`/`GIT_CONFIG_KEY_n`/`GIT_CONFIG_VALUE_n`
environment variables to `CLAUDE_ENV_FILE`. These override git settings for the
session without persisting to disk.

The entries use deferred expansion via a single-quoted heredoc: literal
`${GIT_CONFIG_COUNT:-0}` references are written to the file and expand at
source-time. This makes the approach additive — if another plugin or the parent
environment has already set entries, our entries append at the next available
index rather than overwriting.

Current overrides:

| Setting | Value | Reason |
|---------|-------|--------|
| `branch.autosetupmerge` | `false` | Prevents unintended tracking setup when creating branches |

### Differences from built-in instructions

- `main/master` replaced with detected mainline branch name
Expand Down
10 changes: 10 additions & 0 deletions git/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ At session start, the plugin runs a detection script that:
1. **Detects your mainline branch** (via `origin HEAD`, falls back to `main`/`master`)
2. **Detects conventional commits** (commitlint config or commit history analysis)
3. **Detects fork setup** (checks for `upstream` remote)
4. **Sets git config overrides** via `CLAUDE_ENV_FILE` environment variables

Then injects tailored git instructions covering:

Expand Down Expand Up @@ -53,6 +54,15 @@ The plugin auto-detects repository conventions at session start.
| Conventional commits | commitlint config files, commit history pattern matching |
| Fork setup | Presence of `upstream` remote |

### Git Config Overrides

When `CLAUDE_ENV_FILE` is available, the plugin writes environment variables to
override git settings for the session (without modifying git config files):

| Setting | Value | Reason |
|---------|-------|--------|
| `branch.autosetupmerge` | `false` | Prevents unintended tracking when creating branches |

## Testing

Validate the plugin:
Expand Down
11 changes: 11 additions & 0 deletions git/scripts/git-instructions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -274,3 +274,14 @@ ${BRANCH_NAMING}
- Check \`git branch\` before creating to avoid duplicates

EOF

###############################################################################
# Environment: Git config overrides via CLAUDE_ENV_FILE
###############################################################################
if [[ -n "${CLAUDE_ENV_FILE:-}" ]]; then
cat >> "${CLAUDE_ENV_FILE}" <<'ENVEOF'
export GIT_CONFIG_KEY_${GIT_CONFIG_COUNT:-0}=branch.autosetupmerge
export GIT_CONFIG_VALUE_${GIT_CONFIG_COUNT:-0}=false
export GIT_CONFIG_COUNT=$(( ${GIT_CONFIG_COUNT:-0} + 1 ))
ENVEOF
fi
Loading