refactor: update sessionStart hook to inject all best-practice guides and enhance documentation
This commit is contained in:
@@ -6,6 +6,5 @@
|
||||
"name": "Asep Haryana Saputra",
|
||||
"email": "asepharyana@users.noreply.github.com"
|
||||
},
|
||||
"keywords": ["best-practice", "clean-code", "engineering-guide", "programming-standards", "architecture"],
|
||||
"skills": "./skills/"
|
||||
"keywords": ["best-practice", "clean-code", "engineering-guide", "programming-standards", "architecture"]
|
||||
}
|
||||
|
||||
@@ -2,23 +2,23 @@
|
||||
|
||||
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
|
||||
|
||||
### 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 |
|
||||
| **Frameworks** | react-frontend, elysiajs, hono-backend, drizzle-database, nextjs |
|
||||
| **Infrastructure** | docker, ci-cd, monitoring |
|
||||
| **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 (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.
|
||||
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.
|
||||
|
||||
## Installation
|
||||
|
||||
@@ -34,27 +34,27 @@ A SessionStart command hook (identical to Superpowers' pattern) injects the full
|
||||
|
||||
## 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:
|
||||
- *"Refactor this function"* → `clean-code` activates
|
||||
- *"Write a test for this"* → `testing` activates
|
||||
- *"Design an API endpoint"* → `api-design` activates
|
||||
- Working with `.ts` files → `typescript` activates
|
||||
- Project with `Cargo.toml` → `rust` activates
|
||||
Skills activate automatically when the task matches their domain:
|
||||
- *"Refactor this function"* → `clean-code` guides apply
|
||||
- *"Write a test for this"* → `testing` guides apply
|
||||
- *"Design an API endpoint"* → `api-design` guides apply
|
||||
- Working with `.ts` files → `typescript` guides apply
|
||||
- Project with `Cargo.toml` → `rust` guides apply
|
||||
|
||||
## Structure
|
||||
|
||||
```
|
||||
code-guide/
|
||||
├── .claude-plugin/
|
||||
│ └── plugin.json # Plugin manifest
|
||||
│ └── plugin.json # Plugin manifest (no skills auto-discovery)
|
||||
├── hooks/
|
||||
│ ├── hooks.json # SessionStart command hook config
|
||||
│ ├── run-hook.cmd # Cross-platform polyglot wrapper
|
||||
│ └── session-start # Injects engineering-principles into context
|
||||
├── skills/
|
||||
│ ├── engineering-principles/ # Auto-injected at session start
|
||||
│ └── session-start # Injects ALL skills/*/SKILL.md into context
|
||||
├── skills/ # Source files read by the SessionStart hook
|
||||
│ ├── engineering-principles/
|
||||
│ ├── clean-code/
|
||||
│ ├── ...
|
||||
└── README.md
|
||||
@@ -62,6 +62,7 @@ code-guide/
|
||||
|
||||
## 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`).
|
||||
- All 24 skills are auto-discovered from the `skills/` directory.
|
||||
- Skills activate when Claude detects relevant context — no manual commands needed.
|
||||
1. **SessionStart hook** runs `hooks/run-hook.cmd session-start`.
|
||||
2. The hook script iterates over **all** `skills/*/SKILL.md` files.
|
||||
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
@@ -1,18 +1,34 @@
|
||||
#!/usr/bin/env bash
|
||||
# SessionStart hook for code-guide plugin.
|
||||
# Reads engineering-principles SKILL.md and injects it as context
|
||||
# so the 29 foundational principles are always active from turn 1.
|
||||
# Reads ALL skills/*/SKILL.md files and injects them as additionalContext
|
||||
# so every best-practice guide is always active from turn 1.
|
||||
#
|
||||
# Pattern: identical to Superpowers' session-start hook
|
||||
# which injects skills/using-superpowers/SKILL.md content.
|
||||
# Pattern: identical to explanatory-output-style's session-start hook
|
||||
# which injects educational-output instructions into context.
|
||||
# Instead of one static message, we dynamically iterate over all skills.
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "$0")" && 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() {
|
||||
local s="$1"
|
||||
s="${s//\\/\\\\}"
|
||||
@@ -23,13 +39,12 @@ escape_for_json() {
|
||||
printf '%s' "$s"
|
||||
}
|
||||
|
||||
escaped=$(escape_for_json "$skill_content")
|
||||
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>"
|
||||
escaped=$(escape_for_json "$full_context")
|
||||
|
||||
if [ -n "${CLAUDE_PLUGIN_ROOT:-}" ]; then
|
||||
printf '{"hookSpecificOutput":{"hookEventName":"SessionStart","additionalContext":"%s"}}\n' "$context"
|
||||
printf '{"hookSpecificOutput":{"hookEventName":"SessionStart","additionalContext":"%s"}}\n' "$escaped"
|
||||
else
|
||||
printf '{"additionalContext":"%s"}\n' "$context"
|
||||
printf '{"additionalContext":"%s"}\n' "$escaped"
|
||||
fi
|
||||
|
||||
exit 0
|
||||
|
||||
+3
-1
@@ -1,5 +1,7 @@
|
||||
# install.ps1 — code-guide plugin installer for Claude Code (Windows)
|
||||
#
|
||||
# SessionStart hook injects ALL skills/*/SKILL.md into context at session start.
|
||||
#
|
||||
# Usage:
|
||||
# .\install.ps1 # Install to %USERPROFILE%\.claude\skills\
|
||||
# .\install.ps1 -Link # Symlink (PowerShell Admin/Dev mode)
|
||||
@@ -30,4 +32,4 @@ if ($Link) {
|
||||
|
||||
Write-Host ""
|
||||
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
@@ -1,7 +1,7 @@
|
||||
#!/bin/bash
|
||||
# install.sh — code-guide installer for Claude Code
|
||||
# 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:
|
||||
# ./install.sh # Copy code-guide to ~/.claude/skills/
|
||||
# ./install.sh --link # Symlink (edits live)
|
||||
@@ -41,4 +41,4 @@ if [ "$LINK_MODE" = true ]; then
|
||||
fi
|
||||
echo ""
|
||||
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."
|
||||
|
||||
Reference in New Issue
Block a user