AI Prompt for Claude Code Customization
Configure a SessionStart context loader (read open PRs + recent diff) in .claude/settings.json for a VS Code extension, with matcher, command, and rollback plan.
You are an expert staff engineer with deep expertise in Claude Code customization.
Configure a Claude Code hook that fires on **UserPromptSubmit** to implement: SessionStart context loader (read open PRs + recent diff).
**Project:** VS Code extension
**Team:** open-source maintainers
**Convention to enforce:** handle errors explicitly (Result<T,E> or tagged unions, no bare try/except)
## Hook events recap (use exactly these names)
- `PreToolUse` -- fires before a tool call; exit code 2 blocks the call and feeds stderr back to Claude
- `PostToolUse` -- fires after a tool call succeeds
- `UserPromptSubmit` -- fires when the user submits a prompt; can modify or block
- `Notification` -- fires on Claude Code notifications (permission requests, idle)
- `Stop` -- fires when the main agent finishes responding
- `SubagentStop` -- fires when a Task subagent finishes
- `PreCompact` -- fires before context compaction
- `SessionStart` -- fires when a session begins or resumes
- `SessionEnd` -- fires when a session ends
## Where to put the config
Three files, precedence low -> high:
1. `~/.claude/settings.json` -- user-level, all projects
2. `<repo>/.claude/settings.json` -- project-level, committed
3. `<repo>/.claude/settings.local.json` -- project-level, gitignored (per-dev overrides)
For this VS Code extension the right file is **.claude/settings.local.json (project, gitignored)**.
## Output you must produce
### 1. The settings.json block
Produce the full `hooks` entry in the correct shape:
```json
{
"hooks": {
"UserPromptSubmit": [
{
"matcher": "<regex over tool name, or empty for all>",
"hooks": [
{
"type": "command",
"command": "<shell command>",
"timeout": 60
}
]
}
]
}
}
```
Pick a precise `matcher`. For tool-scoped events: `Bash`, `Write`, `Edit`, `Read`, `Task`, or a regex like `Edit|Write`. For `UserPromptSubmit`/`Stop`/`SessionStart`, omit or leave empty.
### 2. The command script
Produce a standalone shell script (bash) that the hook will invoke. Rules for the script:
- Read JSON from stdin (Claude Code pipes the event payload in)
- Use `jq` to extract fields (e.g. `.tool_input.command`, `.tool_input.file_path`)
- Exit 0 for success / no opinion
- Exit 2 to block (PreToolUse / UserPromptSubmit) and print the reason to stderr
- Any other non-zero exit is a non-blocking error shown to the user
- Keep total runtime under 2s for PreToolUse hooks or you will jam the session
- NEVER modify files from inside a PreToolUse hook -- only observe/decide
Example skeleton:
```bash
#!/usr/bin/env bash
set -euo pipefail
payload="$(cat)"
# ... jq extraction ...
# ... decision ...
```
### 3. Testing the hook
- One command to simulate the event locally (`echo '{...}' | ./my-hook.sh`)
- How to verify it fires inside Claude Code (check the transcript / `/hooks` menu)
- Rollback: exact diff to remove this hook
### 4. Guardrails
- Do not make PostToolUse hooks that rewrite files Claude just wrote without logging the change
- Do not silently consume Claude's tool output -- hooks do not receive tool result unless on PostToolUse
- handle errors explicitly (Result<T,E> or tagged unions, no bare try/except) must not be bypassed by this hook
## Hard constraints
- Use only the documented hook event names above -- any other name is invalid
- JSON must parse; keys are case-sensitive
- Commands run in the session's cwd, so prefer absolute paths or `$CLAUDE_PROJECT_DIR`
Present your output in a clear, organized structure with headers (##), subheaders (###), and bullet points. Use bold for key terms.More prompts for Claude Code Customization.
Configure a SessionEnd summary writer (commit a session digest) in .claude/settings.json for a FastAPI microservice, with matcher, command, and rollback plan.
Define a specialized Claude Code subagent at .claude/agents/diff-explainer.md with its own tool allowlist and system prompt.
Define a specialized Claude Code subagent at .claude/agents/diff-explainer.md with its own tool allowlist and system prompt.
Configure a UserPromptSubmit linter (strip secrets, expand aliases) in .claude/settings.json for a NestJS API, with matcher, command, and rollback plan.
Define a specialized Claude Code subagent at .claude/agents/changelog-curator.md with its own tool allowlist and system prompt.
Build a project-level slash command at .claude/commands/docstrings.md that review my current diff and comment inline in a Node.js backend.