Files
claude-skills/skills/session-handoff/hooks/README.md
vitya 790f1f41b8 docs(session-handoff): pwsh/powershell choice + restart-after-edit caveat [v0.3.2]
Two findings from live-hook e2e smoke 2026-05-25 on this Windows machine:

(1) README snippet was pwsh-only — PS 7 Core isn't on stock Windows. PS 5.1
(`powershell`) is always present and the hook script runs cleanly under both.
README now leads with `powershell` and notes the `pwsh` swap for PS 7+ users.

(2) Missing caveat that hooks load at Claude Code session start — mid-session
edits to ~/.claude/settings.json don't activate the hook until CC restart.
Without this note user would think the hook is broken after applying the
snippet (standalone smoke would pass but live in-session wouldn't fire).
Added explicit restart instruction + verification recipe.

Also: dist/session-handoff.skill now tracked (was missing since promotion —
inconsistent with other dist/*.skill artifacts that ship in repo).

PATCH bump 0.3.1 → 0.3.2 (docs-only, no behavioral change in hook or skill).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-25 00:24:23 +03:00

4.2 KiB

session-handoff hooks

Opt-in PostToolUse hook that detects substantive git commit invocations and signals the agent ("consider running session-handoff write-mode") via a system reminder. Replaces the agent-side commit-detection heuristic in the SKILL.md When to use section with a deterministic harness-side trigger.

Why opt-in (not auto-installed)

install.sh deliberately does not mutate ~/.claude/settings.json. Auto-rewriting the user's hook config on every skill install is the wrong shape — user expects install.sh to copy files, nothing more. The hook is shipped as scripts; user enables it once per machine.

Enable on Windows (PowerShell)

Add to ~/.claude/settings.json. Use powershell for stock Windows (PS 5.1, always present); use pwsh if you have PowerShell 7+ installed. The hook script runs cleanly under both.

{
  "hooks": {
    "PostToolUse": [
      {
        "matcher": "Bash",
        "hooks": [
          {
            "type": "command",
            "command": "powershell -NoProfile -ExecutionPolicy Bypass -File \"$env:USERPROFILE\\.claude\\skills\\session-handoff\\hooks\\commit-detector.ps1\""
          }
        ]
      }
    ]
  }
}

Swap powershell for pwsh if you prefer PS 7+. To check which you have: Get-Command pwsh -ErrorAction SilentlyContinue (empty → PS 7 not installed → use powershell).

If hooks.PostToolUse already exists — append the matcher block to the array. Don't overwrite existing entries.

Restart Claude Code after editing settings.json — hooks are loaded at session start. A running session won't pick up the new hook until it's restarted (close + reopen the CC instance). Verify the hook is active by making a substantive commit and checking for a Substantive commit detected on ... system reminder in the next turn.

Enable on Linux / macOS (bash)

{
  "hooks": {
    "PostToolUse": [
      {
        "matcher": "Bash",
        "hooks": [
          {
            "type": "command",
            "command": "bash ~/.claude/skills/session-handoff/hooks/commit-detector.sh"
          }
        ]
      }
    ]
  }
}

The bash variant needs python3 on PATH (used to parse the PostToolUse JSON stdin).

What gets signalled

On a successful git commit whose subject prefix is not in {meta, docs, style, chore} or fix typo, and whose body exceeds 200 characters or which touches more than 3 files — the hook emits a hookSpecificOutput.additionalContext system reminder of shape:

Substantive commit detected on <cwd>: <subject> (N files changed, body M chars). Consider invoking session-handoff write-mode to update .tasks/NEXT_SESSION.md.

On any of these → silent skip (exit 0, no JSON):

  • malformed PostToolUse stdin
  • Bash command isn't git commit
  • command is git commit --amend
  • commit returned non-zero exit
  • cwd isn't a git work-tree
  • subject prefix is in trivial set
  • body ≤ 200 chars AND files ≤ 3

Smoke test (without enabling the hook)

Pipe a synthetic PostToolUse JSON to the script. On Windows:

$payload = @{
  tool_input    = @{ command = 'git commit -m "subject"' }
  tool_response = @{ exit_code = 0 }
  cwd           = (Get-Location).Path
} | ConvertTo-Json -Compress

$payload | pwsh -NoProfile -File .\skills\session-handoff\hooks\commit-detector.ps1

If your HEAD is a non-trivial commit (e.g. recent feat: with > 200-char body or > 3 files), output is JSON containing additionalContext. Otherwise — empty stdout (silent skip).

Caveats

  • Rebase / cherry-pick noise. Every commit in a rebase or cherry-pick batch will re-fire the hook. Deferred to a follow-up if it actually annoys in practice; the hook is opt-in so the cost is bounded.
  • First-non-trivial commit of session. The agent-side heuristic in SKILL.md treats the first non-trivial commit of a session as "always substantive" regardless of thresholds. The hook can't see session boundaries — uses only body/file thresholds. Slight under-detection on small first commits; acceptable trade-off for harness-side determinism.
  • No automatic write-mode invocation. Hook only signals. The agent still decides whether to run session-handoff write-mode in response — keeps the user-agency invariant from SKILL.md What NOT to do.