refactor: update sessionStart hook to inject all best-practice guides and enhance documentation

This commit is contained in:
asepharyana
2026-07-26 17:55:20 +07:00
parent 95c77c694f
commit ffcd3ba8e3
5 changed files with 52 additions and 35 deletions
+1 -2
View File
@@ -6,6 +6,5 @@
"name": "Asep Haryana Saputra", "name": "Asep Haryana Saputra",
"email": "asepharyana@users.noreply.github.com" "email": "asepharyana@users.noreply.github.com"
}, },
"keywords": ["best-practice", "clean-code", "engineering-guide", "programming-standards", "architecture"], "keywords": ["best-practice", "clean-code", "engineering-guide", "programming-standards", "architecture"]
"skills": "./skills/"
} }
+22 -21
View File
@@ -2,23 +2,23 @@
A Claude Code plugin serving as a complete engineering guide for **all programming situations** — monorepo, standalone, any language, any framework. A Claude Code plugin serving as a complete engineering guide for **all programming situations** — monorepo, standalone, any language, any framework.
All best-practice guides are **injected directly into the system prompt** at every session start via a `SessionStart` hook (same pattern as the `explanatory-output-style` plugin). No manual skill invocation needed — all guides are always active.
## Features ## Features
### 24 Best-Practice Skills ### 25 Best-Practice Guides (Always Active)
| Category | Skills | | Category | Guides |
|----------|--------| |----------|--------|
| **Core Engineering** | clean-code, clean-architecture, design-patterns, testing, error-handling, security, api-design, git-workflow, documentation, logging-observability, performance | | **Core Engineering** | engineering-principles, clean-code, clean-architecture, design-patterns, testing, error-handling, security, api-design, git-workflow, documentation, logging-observability, performance |
| **Languages** | typescript, python, rust, go | | **Languages** | typescript, python, rust, go |
| **Frameworks** | react-frontend, elysiajs, hono-backend, drizzle-database, nextjs | | **Frameworks** | react-frontend, elysiajs, hono-backend, drizzle-database, nextjs |
| **Infrastructure** | docker, ci-cd, monitoring | | **Infrastructure** | docker, ci-cd, monitoring |
| **Monorepo** | monorepo (patterns + submodules + workspace tooling) | | **Monorepo** | monorepo (patterns + submodules + workspace tooling) |
Skills activate automatically when Claude detects relevant context. ### SessionStart Hook (All Skills Injected)
### SessionStart Hook A SessionStart command hook reads **every** `skills/*/SKILL.md` file and injects all content into the conversation context at session start — wrapped in `<CODE_GUIDE_SKILLS>` tags (same pattern as `explanatory-output-style`'s `additionalContext` injection). All 25 guides are active from turn 1, no separate invocation needed.
A SessionStart command hook (identical to Superpowers' pattern) injects the full `engineering-principles` skill content into context at every session start — all 29 principles covering correctness, YAGNI, KISS, DRY, never assume (show evidence), never suppress lints, root-cause fixes, and more. These rules are active from turn 1.
## Installation ## Installation
@@ -34,27 +34,27 @@ A SessionStart command hook (identical to Superpowers' pattern) injects the full
## Usage ## Usage
Skills are **auto-triggered** — Claude loads them when you mention relevant topics or work with matching file types. All guides are **always present in context** — Claude automatically applies the relevant guidance based on the current task, file types, and project structure.
Example triggers: Skills activate automatically when the task matches their domain:
- *"Refactor this function"* → `clean-code` activates - *"Refactor this function"* → `clean-code` guides apply
- *"Write a test for this"* → `testing` activates - *"Write a test for this"* → `testing` guides apply
- *"Design an API endpoint"* → `api-design` activates - *"Design an API endpoint"* → `api-design` guides apply
- Working with `.ts` files → `typescript` activates - Working with `.ts` files → `typescript` guides apply
- Project with `Cargo.toml``rust` activates - Project with `Cargo.toml``rust` guides apply
## Structure ## Structure
``` ```
code-guide/ code-guide/
├── .claude-plugin/ ├── .claude-plugin/
│ └── plugin.json # Plugin manifest │ └── plugin.json # Plugin manifest (no skills auto-discovery)
├── hooks/ ├── hooks/
│ ├── hooks.json # SessionStart command hook config │ ├── hooks.json # SessionStart command hook config
│ ├── run-hook.cmd # Cross-platform polyglot wrapper │ ├── run-hook.cmd # Cross-platform polyglot wrapper
│ └── session-start # Injects engineering-principles into context │ └── session-start # Injects ALL skills/*/SKILL.md into context
├── skills/ ├── skills/ # Source files read by the SessionStart hook
│ ├── engineering-principles/ # Auto-injected at session start │ ├── engineering-principles/
│ ├── clean-code/ │ ├── clean-code/
│ ├── ... │ ├── ...
└── README.md └── README.md
@@ -62,6 +62,7 @@ code-guide/
## How It Works ## How It Works
- **SessionStart hook** runs `hooks/run-hook.cmd session-start` which reads `skills/engineering-principles/SKILL.md` and injects it into the conversation context wrapped in `<EXTREMELY_IMPORTANT>` tags (same pattern as Superpowers' `using-superpowers`). 1. **SessionStart hook** runs `hooks/run-hook.cmd session-start`.
- All 24 skills are auto-discovered from the `skills/` directory. 2. The hook script iterates over **all** `skills/*/SKILL.md` files.
- Skills activate when Claude detects relevant context — no manual commands needed. 3. Each skill's content is combined and injected as `additionalContext` wrapped in `<CODE_GUIDE_SKILLS>` tags — same `hookSpecificOutput.additionalContext` pattern as `explanatory-output-style`.
4. All 25 guides are **always present** in the system prompt — no separate skill invocation needed.
+24 -9
View File
@@ -1,18 +1,34 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# SessionStart hook for code-guide plugin. # SessionStart hook for code-guide plugin.
# Reads engineering-principles SKILL.md and injects it as context # Reads ALL skills/*/SKILL.md files and injects them as additionalContext
# so the 29 foundational principles are always active from turn 1. # so every best-practice guide is always active from turn 1.
# #
# Pattern: identical to Superpowers' session-start hook # Pattern: identical to explanatory-output-style's session-start hook
# which injects skills/using-superpowers/SKILL.md content. # which injects educational-output instructions into context.
# Instead of one static message, we dynamically iterate over all skills.
set -euo pipefail set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
PLUGIN_ROOT="$(cd "${SCRIPT_DIR}/.." && pwd)" PLUGIN_ROOT="$(cd "${SCRIPT_DIR}/.." && pwd)"
skill_content=$(cat "${PLUGIN_ROOT}/skills/engineering-principles/SKILL.md" 2>&1 || echo "Error reading engineering-principles skill") # Build combined content from all SKILL.md files.
combined=""
while IFS= read -r -d '' skill_file; do
skill_name=$(basename "$(dirname "$skill_file")")
content=$(cat "$skill_file")
# Append skill with header separator — uses $'...' for real newlines
combined="${combined}"$'\n\n\n'"===== code-guide:${skill_name} ====="$'\n\n'"${content}"
done < <(find "${PLUGIN_ROOT}/skills" -name 'SKILL.md' -print0 | sort -z)
intro=$'You have the code-guide plugin loaded with all best-practice guides directly injected.\nThe following skills are ALWAYS active in context — no manual invocation needed.\nWhen the current task matches a skill\'s domain, apply its guidance automatically.\n'
full_context="<CODE_GUIDE_SKILLS>
${intro}
${combined}
</CODE_GUIDE_SKILLS>"
# JSON-escape the full context: \ → \\, " → \", newline → \n, etc.
escape_for_json() { escape_for_json() {
local s="$1" local s="$1"
s="${s//\\/\\\\}" s="${s//\\/\\\\}"
@@ -23,13 +39,12 @@ escape_for_json() {
printf '%s' "$s" printf '%s' "$s"
} }
escaped=$(escape_for_json "$skill_content") escaped=$(escape_for_json "$full_context")
context="<EXTREMELY_IMPORTANT>\nYou have the code-guide plugin loaded. Below is the full content of the 'code-guide:engineering-principles' skill — the 29 foundational rules that apply to every coding decision:\n\n${escaped}\n</EXTREMELY_IMPORTANT>"
if [ -n "${CLAUDE_PLUGIN_ROOT:-}" ]; then if [ -n "${CLAUDE_PLUGIN_ROOT:-}" ]; then
printf '{"hookSpecificOutput":{"hookEventName":"SessionStart","additionalContext":"%s"}}\n' "$context" printf '{"hookSpecificOutput":{"hookEventName":"SessionStart","additionalContext":"%s"}}\n' "$escaped"
else else
printf '{"additionalContext":"%s"}\n' "$context" printf '{"additionalContext":"%s"}\n' "$escaped"
fi fi
exit 0 exit 0
+3 -1
View File
@@ -1,5 +1,7 @@
# install.ps1 — code-guide plugin installer for Claude Code (Windows) # install.ps1 — code-guide plugin installer for Claude Code (Windows)
# #
# SessionStart hook injects ALL skills/*/SKILL.md into context at session start.
#
# Usage: # Usage:
# .\install.ps1 # Install to %USERPROFILE%\.claude\skills\ # .\install.ps1 # Install to %USERPROFILE%\.claude\skills\
# .\install.ps1 -Link # Symlink (PowerShell Admin/Dev mode) # .\install.ps1 -Link # Symlink (PowerShell Admin/Dev mode)
@@ -30,4 +32,4 @@ if ($Link) {
Write-Host "" Write-Host ""
Write-Host "Done. Restart Claude Code or run /reload." Write-Host "Done. Restart Claude Code or run /reload."
Write-Host "Skills auto-trigger. SessionStart hook injects engineering-principles into context." Write-Host "SessionStart hook injects all 25 best-practice guides into context."
+2 -2
View File
@@ -1,7 +1,7 @@
#!/bin/bash #!/bin/bash
# install.sh — code-guide installer for Claude Code # install.sh — code-guide installer for Claude Code
# Installs the entire code-guide directory as one unit into ~/.claude/skills/. # Installs the entire code-guide directory as one unit into ~/.claude/skills/.
# Skills auto-discover. SessionStart hook injects engineering-principles into context. # SessionStart hook injects ALL skills/*/SKILL.md into context at session start.
# Usage: # Usage:
# ./install.sh # Copy code-guide to ~/.claude/skills/ # ./install.sh # Copy code-guide to ~/.claude/skills/
# ./install.sh --link # Symlink (edits live) # ./install.sh --link # Symlink (edits live)
@@ -41,4 +41,4 @@ if [ "$LINK_MODE" = true ]; then
fi fi
echo "" echo ""
echo "Done. Restart Claude Code or run /reload." echo "Done. Restart Claude Code or run /reload."
echo "Skills auto-trigger. SessionStart hook injects engineering-principles into context." echo "SessionStart hook injects all 25 best-practice guides into context."