Claude Code v2.1.251: PreModelSwitch/PostModelSwitch hooks, subagent tool-call streaming, background session CLI
cliClaude Code 2.1.251 adds PreModelSwitch/PostModelSwitch hook events for blocking or annotating model switches, live streaming of foreground subagent tool calls to Remote Control clients, and new background-session CLI subcommands (attach/logs/stop/respawn/rm). SessionStart resume hooks now receive staleness and re-cache cost. Also includes /cost prompt-cache stats, spend-limit status fields, and many symlink/path-traversal security fixes.
an agent can now intercept model switches via PreModelSwitch/PostModelSwitch hooks, stream foreground subagent tool calls to Remote Control clients, and read prompt-cache stats plus spend limits from status line fields.
Notable additions: PreModelSwitch/PostModelSwitch hook events, live subagent tool call streaming to Remote Control, and new background session CLI subcommands (attach/logs/stop/respawn/rm). Also includes many security fixes around symlink handling and path traversal in plugin commands.
npm i -g @anthropic-ai/claude-code@2.1.251# Update Claude Code
npm i -g @anthropic-ai/claude-code@2.1.251
# List and attach to background sessions using the new subcommands
claude --help | grep -E 'attach|logs|stop|respawn|rm'
claude attach <session-id>
claude logs <session-id>
# Register a PreModelSwitch hook in settings.json to block/confirm model switches
# Example hook config:
# {
# "hooks": {
# "PreModelSwitch": [{ "command": "./guard-model-switch.sh" }],
# "PostModelSwitch": [{ "command": "./log-model-switch.sh" }]
# }
# }