Skip to content

feat(git-master): add GIT_MASTER=1 env prefix for all git commands#2332

Open
devxoul wants to merge 2 commits intocode-yeongyu:devfrom
devxoul:feat/git-master-env-prefix
Open

feat(git-master): add GIT_MASTER=1 env prefix for all git commands#2332
devxoul wants to merge 2 commits intocode-yeongyu:devfrom
devxoul:feat/git-master-env-prefix

Conversation

@devxoul
Copy link
Contributor

@devxoul devxoul commented Mar 6, 2026

Summary

  • Add git_env_prefix config to git_master config section (default: "GIT_MASTER=1", set to "" to disable).
  • When enabled, inject a mandatory instruction into the git-master skill template requiring all git commands to be prefixed with the configured env variable (e.g., GIT_MASTER=1 git commit ...).
  • Commit footer examples in the skill also respect the prefix.

Why This Matters

The git-master skill enforces atomic commits, conventional commit style, history analysis, and careful git discipline — but there is no way to guarantee the agent always loads it. This feature bridges that gap by giving hooks a reliable signal to detect (or enforce) git-master usage.

The primary motivation: a hook (OpenCode, Claude Code, or even git) can inspect git commands and reject them unless GIT_MASTER=1 is in the command, effectively forcing the agent to always load the git-master skill for any git operation. This ensures atomic commits, style detection, and all git-master discipline is always applied — no more silent fallback to unstructured commits.

Use Cases

1. Enforce git-master skill loading via hooks

The killer use case. A tool.execute.before hook (works in both OpenCode and Claude Code) detects git commands in Bash tool calls and rejects them if GIT_MASTER=1 prefix is missing — forcing the agent to load the git-master skill before touching git:

// OpenCode / Claude Code hook: tool.execute.before
if (toolName === "Bash" && command.includes("git ") && !command.includes("GIT_MASTER=1")) {
  return { error: "Load git-master skill before running git commands." }
}

This guarantees every agent git operation goes through git-master's atomic commit analysis, conventional commit enforcement, and history-aware style detection.

2. Git hooks also work

Since the env var is set at the shell level, traditional git hooks can see it too. A pre-commit hook can enforce stricter rules only for agent commits:

#!/bin/bash
# .git/hooks/commit-msg — stricter rules for agent commits
if [ "$GIT_MASTER" = "1" ]; then
  if ! grep -qE "^(feat|fix|refactor|test|docs|chore)(\(.+\))?: .+" "$1"; then
    echo "ERROR: git-master commits must use conventional commit format."
    exit 1
  fi
fi

3. Audit trail / observability

Scripts or CI pipelines can distinguish agent-made commits from human commits. Since the env var is present during the git operation, hooks can tag commits with metadata:

#!/bin/bash
# .git/hooks/prepare-commit-msg
if [ "$GIT_MASTER" = "1" ]; then
  git interpret-trailers --in-place --trailer "Agent: git-master" "$1"
fi

4. Customizable prefix for team integration

Teams can set their own prefix to integrate with existing tooling:

{
  "git_master": {
    "git_env_prefix": "AGENT_COMMIT=1"     // match your team's conventions
    // "git_env_prefix": "AI_AUTHORED=true" // or integrate with AI detection tools
    // "git_env_prefix": ""                 // disable entirely
  }
}

Roadmap

A follow-up PR can address the "enforce git-master loading" option directly — e.g., a built-in hook that rejects git operations without the skill loaded. But it's better to land this bridge first; it lays the groundwork that the enforce feature will build on.

Configuration

// .opencode/oh-my-opencode.jsonc
{
  "git_master": {
    "git_env_prefix": "GIT_MASTER=1"  // default, set to "" to disable
  }
}

Changes

  • src/config/schema/git-master.ts — Add git_env_prefix field to schema with "GIT_MASTER=1" default.
  • src/features/opencode-skill-loader/git-master-template-injection.ts — Inject env prefix section into skill template when enabled. Refactor injection logic into helper functions.
  • src/features/opencode-skill-loader/git-master-template-injection.test.ts — New: unit tests for env prefix injection (default value, disabled via empty string, custom value).
  • src/features/opencode-skill-loader/skill-content.test.ts — Update existing tests to include git_env_prefix field.

Testing

bun run typecheck
bun test src/features/opencode-skill-loader/git-master-template-injection.test.ts
bun test src/features/opencode-skill-loader/skill-content.test.ts

devxoul added 2 commits March 6, 2026 11:35
When git-master skill is loaded, all git commands are prefixed with the configured env variable (default: GIT_MASTER=1). This enables custom git hooks to detect git-master skill usage. Set to empty string to disable.
Add unit tests for env prefix injection (default, disabled, custom value) and update existing skill-content tests to include git_env_prefix field.
Copy link

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 4 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Auto-approved: The PR safely introduces a new configuration option with comprehensive tests. The logic for template injection is robust and handles default, custom, and disabled states correctly.

@devxoul devxoul changed the title feat(git-master): add git_env_prefix config for git command prefixing feat(git-master): add GIT_MASTER=1 env prefix for all git commands Mar 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant