Initial commit

This commit is contained in:
Zhongwei Li
2025-11-29 18:19:59 +08:00
commit 9f60012661
14 changed files with 824 additions and 0 deletions

View File

@@ -0,0 +1,167 @@
# Hooks Reference
Quick reference for creating event hooks. For complete documentation, see @docs-claude/hooks-reference.md
## Structure
Add to settings.json:
```json
{
"hooks": {
"EventName": [
{
"matcher": "ToolPattern",
"hooks": [
{
"type": "command",
"command": "your-command"
}
]
}
]
}
}
```
## Location
- Project: `.claude/settings.json`
- Personal: `~/.claude/settings.json`
- Local: `.claude/settings.local.json` (gitignored)
## Hook Types
- `"type": "command"` - Execute bash command
- `"type": "prompt"` - LLM-based evaluation
## Common Events
- `PreToolUse` - Before tool runs (can block)
- `PostToolUse` - After tool completes
- `UserPromptSubmit` - Before processing user prompt
- `Stop` - When Claude finishes
- `SubagentStop` - When subagent finishes
- `Notification` - On notifications
- `SessionStart` - Session begins
- `SessionEnd` - Session ends
## Matchers
**For PreToolUse/PostToolUse:**
- `"Write"` - Exact match
- `"Write|Edit"` - Multiple tools
- `"Notebook.*"` - Regex pattern
- `"*"` - All tools
**For other events:** Omit matcher
## Exit Codes (Command Type)
- `0` - Success
- `2` - Block action, show stderr to Claude
- Other - Error, execution continues
## Simple Examples
**Format on write:**
```json
{
"hooks": {
"PostToolUse": [
{
"matcher": "Write|Edit",
"hooks": [
{
"type": "command",
"command": "prettier --write $file"
}
]
}
]
}
}
```
**Prevent stopping:**
```json
{
"hooks": {
"Stop": [
{
"hooks": [
{
"type": "command",
"command": "$CLAUDE_PROJECT_DIR/.claude/hooks/check-todos.sh"
}
]
}
]
}
}
```
**Validate bash commands:**
```json
{
"hooks": {
"PreToolUse": [
{
"matcher": "Bash",
"hooks": [
{
"type": "command",
"command": "python $CLAUDE_PROJECT_DIR/.claude/hooks/validate-bash.py"
}
]
}
]
}
}
```
## Hook Input
Hooks receive JSON via stdin:
```json
{
"session_id": "abc123",
"hook_event_name": "PreToolUse",
"tool_name": "Write",
"tool_input": { "file_path": "/path/to/file" }
}
```
## Environment Variables
- `$CLAUDE_PROJECT_DIR` - Project root path
- `$CLAUDE_ENV_FILE` - SessionStart only, for env vars
## Tips
- Use `$CLAUDE_PROJECT_DIR` for project scripts
- Test hooks with `claude --debug`
- Exit code 2 blocks and sends stderr to Claude
- Keep hooks fast (60s timeout default)
- For complete API, see @docs-claude/hooks-reference.md
## Prompt-Based Hooks
Use LLM for intelligent decisions:
```json
{
"hooks": {
"Stop": [
{
"hooks": [
{
"type": "prompt",
"prompt": "Check if all tasks complete: $ARGUMENTS"
}
]
}
]
}
}
```
LLM responds with: `{"decision": "approve"|"block", "reason": "..."}`

View File

@@ -0,0 +1,119 @@
# Output Styles Reference
Quick reference for creating custom output styles.
## Structure
Markdown file with frontmatter:
```markdown
---
name: My Style
description: Brief description shown in UI
keep-coding-instructions: false
---
# Custom Style Instructions
Your custom system prompt additions here.
Define how Claude should behave in this style.
```
## Location
- Project: `.claude/output-styles/style-name.md`
- Personal: `~/.claude/output-styles/style-name.md`
## Key Fields
- `name` - Display name (optional, defaults to filename)
- `description` - Shown in `/output-style` menu
- `keep-coding-instructions` - Keep Claude's coding instructions (default: false)
## Activation
- `/output-style` - Open menu to select
- `/output-style style-name` - Switch directly
- Saved in `.claude/settings.local.json`
## How It Works
Output styles modify the system prompt:
- Removes efficiency instructions (concise output)
- Removes coding instructions (unless keep-coding-instructions: true)
- Adds your custom instructions
## Simple Examples
**Teacher mode:**
```markdown
---
name: Teacher
description: Educational mode with explanations
keep-coding-instructions: true
---
# Teacher Mode
You help users learn while coding.
Behavior:
- Explain your reasoning
- Share insights between tasks
- Ask questions to check understanding
- Encourage hands-on practice
```
**Formal mode:**
```markdown
---
name: Formal
description: Professional, detailed responses
---
# Formal Mode
You provide formal, professional assistance.
Style:
- Use formal language
- Provide detailed explanations
- Structure responses clearly
- Include relevant references
```
**Quick mode:**
```markdown
---
name: Quick
description: Minimal, direct responses
keep-coding-instructions: true
---
# Quick Mode
Provide minimal, direct responses.
- Short answers
- Code only when needed
- No extra explanations
```
## Tips
- Set `keep-coding-instructions: true` for coding tasks
- Clear behavior guidelines work best
- Test with different request types
- Use for non-coding tasks (research, writing, etc.)
## Built-in Styles
- **Default** - Standard software engineering
- **Explanatory** - Adds educational insights
- **Learning** - Collaborative learn-by-doing
## Comparison
- **Output Styles** - Change system prompt, affect all responses
- **CLAUDE.md** - Add context, doesn't change system prompt
- **Subagents** - Separate tasks, own context
- **Slash Commands** - Reusable prompts

View File

@@ -0,0 +1,109 @@
# Skills Reference
Quick reference for creating agent skills.
## Structure
```
my-skill/
├── SKILL.md (required)
├── reference.md (optional)
├── examples.md (optional)
├── scripts/
│ └── helper.py
└── templates/
└── template.txt
```
## Location
- Project: `.claude/skills/skill-name/`
- Personal: `~/.claude/skills/skill-name/`
## SKILL.md Format
```markdown
---
name: my-skill-name
description: What it does and when to use it. Include trigger keywords.
allowed-tools: Read, Write, Bash
---
# My Skill
## Instructions
1. Clear step-by-step guidance
2. What to do and how
## Examples
Simple, minimal examples
```
## Description Tips
Include WHEN to use:
- ✅ "Extract PDF text. Use when working with PDF files."
- ❌ "Extract PDF text."
## Tool Access
- Omit `allowed-tools` → inherit all tools
- Specify tools → restrict access (e.g., read-only: `Read, Grep, Glob`)
## Progressive Disclosure
Reference other files:
```markdown
For advanced usage, see [reference.md](reference.md)
Run helper: `python scripts/helper.py`
```
Claude loads files only when needed.
## Simple Examples
**Code reviewer:**
```markdown
---
name: code-reviewer
description: Review code quality. Use after writing or modifying code.
allowed-tools: Read, Grep, Glob
---
# Code Reviewer
## Checklist
- Readable code
- Error handling
- No duplicated code
- Security issues
Review and provide specific feedback.
```
**Commit helper:**
```markdown
---
name: commit-helper
description: Generate commit messages. Use when staging commits.
allowed-tools: Bash(git diff:*), Bash(git status:*)
---
# Commit Helper
## Instructions
1. Run `git diff --staged`
2. Generate clear commit message:
- Summary under 50 chars
- Present tense
- Explain what and why
```
## Tips
- One skill = one focused capability
- Clear, specific descriptions
- Simple instructions
- Test with relevant requests

View File

@@ -0,0 +1,85 @@
# Slash Commands Reference
Quick reference for creating custom slash commands.
## Structure
```markdown
---
description: Brief description
argument-hint: [arg1] [arg2]
allowed-tools: Tool1, Tool2
---
Your command prompt here with $ARGUMENTS or $1, $2, etc.
```
## Location
- Project: `.claude/commands/filename.md``/filename`
- Personal: `~/.claude/commands/filename.md``/filename`
- Subdirectories: `.claude/commands/subdir/filename.md``/filename` (subdir shown in description)
## Arguments
- `$ARGUMENTS` - All arguments as single string
- `$1, $2, $3` - Individual arguments
## File References
Use `@` prefix to reference files:
```
Review @src/app.js for bugs
Compare @old.js with @new.js
```
## Bash Execution
Prefix with `!` to execute bash:
```markdown
---
allowed-tools: Bash(git status:*), Bash(git diff:*)
---
Current status: !`git status`
Recent changes: !`git diff HEAD`
```
## Simple Examples
**Commit helper:**
```markdown
---
description: Create git commit
allowed-tools: Bash(git add:*), Bash(git commit:*)
---
Create a commit for these changes: !`git diff`
```
**Review PR:**
```markdown
---
description: Review pull request
argument-hint: [pr-number]
---
Review PR #$1 focusing on code quality and security.
```
**Fix issue:**
```markdown
---
description: Fix GitHub issue
argument-hint: [issue-number]
---
Fix issue #$ARGUMENTS following our coding standards.
```
## Tips
- Keep descriptions short and clear
- Use `allowed-tools` to pre-approve tools
- Simple prompts work best
- Test with different arguments

View File

@@ -0,0 +1,115 @@
# Subagents Reference
Quick reference for creating specialized subagents.
## Structure
Single Markdown file:
```markdown
---
name: my-agent
description: What it does. Use proactively when [condition].
tools: Read, Write, Bash
model: sonnet
---
System prompt for this subagent.
Detailed role and approach instructions.
```
## Location
- Project: `.claude/agents/agent-name.md`
- Personal: `~/.claude/agents/agent-name.md`
## Key Fields
- `name` - lowercase-with-hyphens
- `description` - Include "use proactively" for automatic invocation
- `tools` - Optional; omit to inherit all tools
- `model` - Optional: `sonnet`, `opus`, `haiku`, or `inherit`
## Model Selection
- `sonnet` (default) - Balanced capability
- `opus` - Maximum capability
- `haiku` - Fast, cost-effective
- `inherit` - Use main conversation's model
## Invocation
**Automatic:** Claude delegates based on description
**Explicit:** User mentions agent by name
## Simple Examples
**Code reviewer:**
```markdown
---
name: code-reviewer
description: Expert code reviewer. Use proactively after writing code.
tools: Read, Grep, Glob, Bash(git diff:*)
model: inherit
---
You are a senior code reviewer.
When invoked:
1. Run git diff to see changes
2. Review for quality and security
3. Provide specific, actionable feedback
Focus on:
- Readable code
- Error handling
- Security issues
- Performance
```
**Debugger:**
```markdown
---
name: debugger
description: Debug errors and test failures. Use proactively when issues occur.
tools: Read, Edit, Bash, Grep
---
You are an expert debugger.
Process:
1. Capture error message
2. Identify cause
3. Implement minimal fix
4. Verify solution
Provide root cause and fix.
```
**Test runner:**
```markdown
---
name: test-runner
description: Run tests and fix failures. Use proactively after code changes.
---
You run tests and fix failures.
Steps:
1. Run appropriate tests
2. Analyze failures
3. Fix issues
4. Re-run tests
```
## Tips
- Single, clear responsibility per agent
- Include "use proactively" for automatic use
- Limit tools to what's needed
- Test with relevant requests
- Use `/agents` command to manage
## When to Use
- **Subagents** - Separate context, specialized tasks
- **Skills** - Extend capabilities, loaded in main context