Skip to content

Refactor git plugin with dynamic context and improved hooks - #4

Merged
cblecker merged 3 commits into
mainfrom
refactor-git-plugin-dynamic-context
Jan 27, 2026
Merged

Refactor git plugin with dynamic context and improved hooks#4
cblecker merged 3 commits into
mainfrom
refactor-git-plugin-dynamic-context

Conversation

@cblecker

@cblecker cblecker commented Jan 27, 2026

Copy link
Copy Markdown
Owner

Summary

Major refactoring of the git plugin to improve performance, maintainability, and reliability:

  • Dynamic context injection - Skills pre-fetch git state to reduce redundant command execution
  • New convention detection skill - Fast haiku-based subagent analyzes repository conventions
  • Shared mainline detection - Single source of truth with symlinked scripts
  • Command-based hooks - Replaced prompt hooks with faster jq-based command hooks
  • Improved documentation - Quick Reference sections, comprehensive hooks README, and CLAUDE.md

Changes

Dynamic Context Injection

  • Added dynamic context sections to commit, branch, and pr skills using !command`` syntax
  • Skills now receive pre-fetched git state (branch, status, remotes, commit history)
  • Eliminates redundant git command execution during skill invocation

New detect-conventions Skill

  • Haiku-based subagent for fast conventional commits detection
  • Analyzes git config, commit history, and CLAUDE.md
  • Replaces inline detection logic scattered across commit and branch skills

Shared Mainline Detection

  • Created git/scripts/detect-mainline.sh as single source of truth
  • Symlinked into each skill's scripts directory for portability
  • Priority: cached → upstream → origin → local branch fallback

Hook Refactoring

  • Replaced 3 prompt-based hooks with 9 command-based hooks
  • Faster execution with jq parsing instead of LLM processing
  • Added comprehensive hooks/README.md with test plan
  • Categories: force push protection, skill suggestions, safety warnings

Skill Improvements

  • Moved Quick Reference sections to top with navigation links
  • Pre-flight checks before convention detection in all skills
  • Integrated error handling into workflow steps
  • Safety sections moved before Core Workflow for visibility

Cleanup

  • Deleted git/reference/ directory (4 markdown files)
  • Removed broken symlinks to deleted reference files
  • All reference material now in skills or shared scripts
  • Removed redundant markdownlint ignores

Testing

  • Verified all 9 hooks execute correctly with test scenarios from hooks/README.md
  • Tested mainline detection script with various repository configurations
  • Validated symlinks resolve correctly from skill directories
  • Confirmed markdownlint passes: npx markdownlint-cli2 --config ${CLAUDE_PROJECT_DIR}/.markdownlint-cli2.jsonc "**/*.md"
  • Verified dynamic context injection reduces redundant git commands

Documentation

  • Added comprehensive git/CLAUDE.md documenting all architectural decisions
  • Created git/hooks/README.md with hook descriptions and test plan
  • Updated skills with Quick Reference sections and navigation
  • Documented convention detection patterns and mainline detection priority

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Added conventional commits detection capability to identify repository commit standards automatically.
    • Introduced specialized git workflow safety controls with targeted protections for common operations like push, reset, and rebase.
  • Improvements

    • Enhanced branch creation workflow with dynamic context integration and improved naming guidance.
    • Refined commit workflow with streamlined pre-flight checks.
    • Updated PR creation workflow with clearer guidance.
  • Version Updates

    • Plugin version bumped to 0.2.0.

✏️ Tip: You can customize this high-level summary in your review settings.

cblecker and others added 3 commits January 26, 2026 16:25
Major improvements to the git plugin:

**Dynamic Context Injection:**
- Added dynamic context sections to commit, branch, and pr skills
- Skills now pre-fetch git state using \!`command` syntax
- Reduces redundant git command execution during skill invocation

**New detect-conventions Skill:**
- Haiku-based subagent for fast conventional commits detection
- Analyzes config files, commit history, and CLAUDE.md
- Replaces inline detection logic in commit and branch skills

**Shared Mainline Detection Script:**
- Single source of truth: git/scripts/detect-mainline.sh
- Symlinked into each skill's scripts directory
- Priority: cached → upstream → origin → local fallback

**Refactored Hooks:**
- Replaced prompt-based hooks with jq-based command hooks
- Faster execution and more reliable parsing
- Added comprehensive hooks/README.md with test plan
- 9 hooks: force push protection, skill suggestions, safety warnings

**Skill Improvements:**
- Quick Reference sections moved to top with navigation links
- Pre-flight checks before convention detection in all skills
- Integrated error handling into workflow steps
- Safety sections moved before Core Workflow

**Cleanup:**
- Deleted git/reference/ directory (replaced by scripts and inline docs)
- Removed broken symlinks to deleted reference files
- All reference material now in skills or shared scripts

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Simplify markdownlint configuration by removing reference symlink ignores.
Update CLAUDE.md to include explicit config path for markdownlint command.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Documents architectural decisions and patterns from the refactoring:
- Dynamic context injection benefits and patterns
- Skill structure standardization (Quick Reference at top)
- Convention detection with haiku subagent
- Mainline detection with symlinked scripts
- Command-based hooks architecture and categories
- Workflow patterns (pre-flight checks first, integrated error handling)
- File organization decisions (deleted reference/, inline docs)
- Development learnings (performance improvements, best practices)
- Testing and maintenance procedures

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jan 27, 2026

Copy link
Copy Markdown

Walkthrough

This PR restructures the Git plugin from prompt-based to command-based hooks, consolidates documentation, and rewrites skill workflows. Changes include hook system refactoring in hooks.json, deletion of legacy reference documents, new script additions, comprehensive skill documentation updates, and plugin version bump to 0.2.0.

Changes

Cohort / File(s) Summary
Configuration & Plugin Metadata
.markdownlint-cli2.jsonc, .../plugin.json, CLAUDE.md
Removed markdown ignores block; bumped plugin version from 0.1.0 to 0.2.0; added explicit markdownlint config path reference and removed claudelint instruction.
Hook System Restructuring
git/hooks/hooks.json, git/hooks/README.md, git/CLAUDE.md
Migrated from generic prompt-based hooks to command-specific hooks (git push, commit, checkout, reset, clean, rebase, gh); replaced prompt outputs with structured JSON; updated description and added comprehensive safety/hook behavior documentation.
Legacy Reference Documentation Removed
git/reference/conventional-commits.md, git/reference/fork-detection.md, git/reference/git-safety.md, git/reference/mainline-detection.md
Deleted four comprehensive reference documents totaling 851 lines covering conventional commits, fork detection logic, git safety practices, and mainline detection strategies.
Shared Scripts
git/scripts/detect-mainline.sh
New script implementing prioritized mainline detection: cache → upstream → origin → local fallback (main/master). Includes environment caching support.
Skill Documentation Overhauls
git/skills/branch/SKILL.md, git/skills/commit/SKILL.md, git/skills/pr/SKILL.md
Restructured workflows into Quick Reference format; replaced detailed bash commands with high-level procedural guidance; added dynamic context sections (Current Git State, Core Workflow); refined conventional commits integration and removed legacy configuration examples.
Skill Reference File Updates
git/skills/branch/reference, git/skills/commit/reference, git/skills/pr/reference
Removed relative path references (../../reference) from each skill directory.
Skill Scripts Consolidation
git/skills/branch/scripts/detect-mainline.sh, git/skills/commit/scripts/detect-mainline.sh, git/skills/pr/scripts/detect-mainline.sh
Added delegation references to shared ../../../scripts/detect-mainline.sh across all skill script directories.
New Skill Addition
git/skills/detect-conventions/SKILL.md
New skill to detect conventional commits usage via config files, commit history, or CLAUDE.md overrides; includes detection confidence and types analysis.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~30 minutes

Possibly related PRs

Poem

🐰 Hooks now speak in JSON clear,
No prompts obscure the pathway here,
Skills refactored, docs set free,
Mainline detection, fresh and spry!
From push to commit, each command knows
The safety gates that guard our flows. ✨

🚥 Pre-merge checks | ✅ 2
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main changes: refactoring the git plugin with dynamic context injection and improved hook implementations, which are the primary objectives of this PR.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
git/skills/commit/SKILL.md (1)

237-243: Missing detect-conventions in the integration list.

The workflow invokes detect-conventions skill in step 2 (line 71), but this isn't listed under "This skill invokes". This inconsistency could confuse users about skill dependencies.

Suggested fix
 ## Integration with Other Skills
 
 **This skill invokes:**
 - **`/git:branch`** - When user tries to commit on mainline
+- **`/git:detect-conventions`** - To determine commit message style
 
 **This skill is invoked by:**
 - **`/git:pr`** - When creating PR with uncommitted changes
🤖 Fix all issues with AI agents
In `@git/hooks/hooks.json`:
- Around line 5-12: The force-push detection regex inside the jq test in the
"command" value (the expression that sets $is_force currently using
test("\\s--force|\\s-[a-zA-Z]*f")) is too narrow and misses variants like
--force-with-lease and --force-if-includes; update that test to match all force
variants (e.g., include --force(-with-lease|-if-includes)? or equivalent
word-boundary patterns while keeping the short-flag match \\s-[a-zA-Z]*f) so
$is_force becomes true for --force, --force-with-lease, --force-if-includes and
-f; modify the regex only in the jq test expression inside the command string
referenced in the hooks JSON.
🧹 Nitpick comments (5)
git/scripts/detect-mainline.sh (1)

34-37: Guard env-file caching to avoid errors/duplication.
Consider checking writability and skipping duplicate exports to prevent noisy stderr and growth over repeated runs.

♻️ Proposed refinement
-if [ -n "$CLAUDE_ENV_FILE" ] && [ -f "$CLAUDE_ENV_FILE" ]; then
-  echo "export CLAUDE_MAINLINE_BRANCH='$mainline'" >> "$CLAUDE_ENV_FILE"
-fi
+if [ -n "$CLAUDE_ENV_FILE" ] && [ -f "$CLAUDE_ENV_FILE" ] && [ -w "$CLAUDE_ENV_FILE" ]; then
+  if ! grep -q "^export CLAUDE_MAINLINE_BRANCH=" "$CLAUDE_ENV_FILE"; then
+    echo "export CLAUDE_MAINLINE_BRANCH='$mainline'" >> "$CLAUDE_ENV_FILE"
+  fi
+fi
git/CLAUDE.md (1)

5-7: Consider removing duplicated content.

Lines 5-7 (Key decisions) duplicate the content in lines 11-15 (Architecture > Dynamic Context Injection). Consider keeping just the Architecture section for a single source of truth.

♻️ Suggested fix
 Development learnings and architectural decisions for the git plugin.
 
-Key decisions:
-- Use [dynamic context injection](https://code.claude.com/docs/en/skills#inject-dynamic-context) to pre-fetch information where possible.
-- Place dynamic context section after Quick Reference, before Core Workflow.
-
 ## Architecture
git/skills/pr/SKILL.md (1)

22-28: Consider caching the mainline value in the dynamic context command.

Line 28 executes detect-mainline.sh in a subshell, but line 25 already captures the mainline branch. If the dynamic context system supports variable references, you could avoid the redundant script execution.

If variable references aren't supported and the script has caching (as mentioned in PR objectives), this is fine as-is.

git/skills/commit/SKILL.md (1)

69-71: Consider clarifying skill invocation syntax.

The instruction "Invoke the detect-conventions skill" is clear but doesn't specify whether to use the Skill tool or another mechanism. For consistency with line 58 which says "Invoke /git:branch skill using the Skill tool", consider adding similar specificity here.

Suggested clarification
 ### 2. Detect Commit Style
 
-Invoke the `detect-conventions` skill to determine commit style (conventional commits or standard).
+Invoke the `/git:detect-conventions` skill using the Skill tool to determine commit style (conventional commits or standard).
git/hooks/hooks.json (1)

53-60: Potential false positive in mainline detection regex.

The check test($mainline) performs substring matching, which could trigger on branch names containing the mainline name. For example, if mainline is main, it would match git rebase maintain-feature or domain-branch.

Consider using word boundaries for more precise matching:

Suggested fix with word boundaries
-        "command": "mainline=$(\"${CLAUDE_PLUGIN_ROOT}/scripts/detect-mainline.sh\"); cat | jq -r --arg mainline \"$mainline\" 'if .tool_input.command | test($mainline) then {\"hookSpecificOutput\":{\"hookEventName\":\"PreToolUse\",\"additionalContext\":\"WARNING: Rebasing onto mainline. Ensure this is intentional.\"}} else null end'",
+        "command": "mainline=$(\"${CLAUDE_PLUGIN_ROOT}/scripts/detect-mainline.sh\"); jq -r --arg mainline \"$mainline\" 'if .tool_input.command | test(\"(^|\\\\s)\" + $mainline + \"(\\\\s|$)\") then {\"hookSpecificOutput\":{\"hookEventName\":\"PreToolUse\",\"additionalContext\":\"WARNING: Rebasing onto mainline. Ensure this is intentional.\"}} else null end'",

Note: Also removed the unnecessary cat | since jq reads from stdin by default.

Comment thread git/hooks/hooks.json
@cblecker
cblecker merged commit e8ebe6c into main Jan 27, 2026
8 checks passed
@cblecker
cblecker deleted the refactor-git-plugin-dynamic-context branch January 27, 2026 00:47
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