UserPromptExpansion Hook - Claude Code
Fires when a slash command expands; can block or inject context.

UserPromptExpansion runs when a slash command (including a skill) expands into its full prompt. It's your hook point between "user typed /foo" and "Claude starts reasoning".
What it does
The hook sees the expanded prompt from a slash command. It can modify the expansion, block the command, or attach context only relevant to that command. This is how you enforce per-skill rules - maybe your /deploy skill should always refuse on Fridays, or your /merge skill should always require a PR number.
When to use it
- Enforcing constraints on specific skills (never run destructive skills in main branch).
- Attaching dynamic context to certain commands (pull current config, add today's date).
- Auditing slash command usage across a team.
- Building guardrails around team-shared skills.
Gotchas
- The hook fires for every matching expansion, including auto-invocations. Scope triggers carefully.
- Blocking without explanation frustrates users. Always return a reason.
- Expansion-time hooks don't see the user's raw intent, only the resolved skill body.
Official docs: https://code.claude.com/docs/en/hooks.md#userpromptexpansion
Technical content at the intersection of AI and development. Building with AI agents, Claude Code, and modern dev tools - then showing you exactly how it works.
Was this helpful?
Related Guides
Related Tools
Claude Agent SDK
Anthropic's SDK for building agents on the same tools, agent loop, and context management that power Claude Code. Python...
View ToolClaude Code
Anthropic's agentic coding CLI. Runs in your terminal, edits files autonomously, spawns sub-agents, and maintains memory...
View ToolCodeburn
Interactive TUI dashboard that shows exactly where your Claude Code and Cursor tokens are going, in real time.
View ToolConductor
Mac app for running parallel Claude Code, Codex, and Cursor agents in isolated workspaces. Watch every agent work at onc...
View ToolRelated Videos

Claude Code Just Killed After Effects
Create motion graphics and launch videos using natural language — no traditional video editor required. 🔗 Try Higgsfield Katana in Claude:** https://higgsfield.ai/s/katana-inside-claude-yt-developer...

Generate Videos in Codex + Claude Code with This...
Check out HeyGen! https://heygen.1stcollab.com/developersdigest The video introduces HeyGen, an AI video generation platform with a rich API and a CLI that lets developers create, fetch, and manipula...

10x Design in Claude Code and Codex
Try Higgsfield: https://higgsfield.ai/s/higgsfield-general-campaign-developersdigest-juDMTi AI coding agents can build entire websites in minutes, but the default results often still look generic and...
Related Posts

Claude Fable 5.2: What Changed, Pricing and How to Migrate
Claude Fable 5.2 costs $8/$40 per MTok, down from $10/$50, but enforces the prefix check on every account. The four brea...

Claude vs Claude Code: What the Difference Is and Which to Use (2026)
Claude vs Claude Code: one app for chat, docs and general work, one agent for your codebase. Same model family and share...

Claude Security Continuous Scanning: Fix Tracking, API and MCP
Claude Security now rescans repos as commits land, marks findings fixed when the fix ships, and adds an API, MCP connect...

Claude Fable 5.1 in Claude Code: How to Switch, Pin, and Pay Less
Claude Code v2.1.257 points /model fable at Fable 5.1: 1M context, $10/$50 per MTok, $0.25 cache reads. Setup, gotchas,...

Claude Design, Slides and Docs in Any Chat: How to Use Them
Claude Design, Slides and Docs now open in any Claude chat, Claude Code session or the Artifacts tab, on every plan. Exa...

Claude for Startups Offer Paused: What Founders Do Now
Claude for Startups paused its free Claude Team year and $1,000 API credit offer at capacity. What the program page says...
