| Age | Commit message (Collapse) | Author |
|
fix(hooks): fall back to zsh, or exit quietly, when bash is missing on Unix (#2503)
|
|
fix(hooks): start no child processes in the SessionStart hook (#2081)
|
|
(#2503)
On a Unix system without bash, the harness can't honour shell:"bash" and
runs run-hook.cmd with zsh or sh. $BASH is unset there, so the wrapper's
exec "${BASH:-bash}" fails with "command not found: bash" (zsh) or
"exec: bash: not found" (sh), the hook exits 127, and the bootstrap is
lost on every session start.
Keep $BASH first, so the empty-PATH case from #2310 still works, then look
for bash on PATH, then zsh, which runs session-start unchanged (its output
is byte-identical to bash's, including for a SKILL.md full of backslashes,
quotes, tabs and CRs). With neither shell, exit 0 quietly, as the Windows
half already does.
Reproduced with Claude Code 2.1.308 in an alpine container with zsh and no
bash: the hook exited 127 and no bootstrap reached the model before the
change; after it the hook exits 0 and the bootstrap arrives.
Tests run the wrapper under real zsh and under a non-bash sh with a PATH
that holds only zsh, and under that sh with neither shell. They skip where
zsh is absent or sh is bash (Git Bash, macOS).
Co-authored-by: Twot <twotnguyen@users.noreply.github.com>
Claude-Session: https://claude.ai/code/session_01SHANcr4A71nzuU9et4Fnba
|
|
On Windows, Git Bash emulates fork(), so every command substitution and
pipe costs tens of milliseconds. The SessionStart hook runs on every
startup, /clear and compaction, and on dev it forked six times: the
$(cd ... && pwd) in run-hook.cmd and twice in session-start,
$(escape_for_json ...), and printf | cat.
Resolve paths with parameter expansion, read the skill with the read
builtin, have escape_for_json assign a variable, and absorb EPIPE with
trap '' PIPE plus printf 2>/dev/null || true instead of piping through
cat. The cat pipe also turned an early-closed stdout into exit 141 under
pipefail; the new emit_json exits 0 there.
Measured on Windows 11 (VM, Git Bash 5.2), 21 interleaved runs of
run-hook.cmd session-start: median 116 ms before, 46 ms after, against a
25 ms floor for one bash start (the wrapper starts two). Claude Code
2.1.308 logged the hook at 181-421 ms before and 137-146 ms after. Output
is byte-identical to dev across all five output shapes, two working
directories, normal and empty PATH, direct and through the wrapper (40/40
on Linux), and its sha256 matches on Windows.
Tests: the cat-stub case, which asserted the pipe, is replaced by a
closed-stdout case, and a new case counts process creations with strace
on Linux (5 in session-start and 6 through the wrapper on dev, 0 after).
Co-authored-by: willow <willowite@users.noreply.github.com>
Claude-Session: https://claude.ai/code/session_01SHANcr4A71nzuU9et4Fnba
|
|
Windows (#2189)
GitHub Copilot on Windows (Copilot CLI and VS Code Copilot) runs a hook's
command through PowerShell and ignores shell:"bash". PowerShell parses
"<root>/hooks/run-hook.cmd" session-start as a string expression followed
by a bareword, fails with "Unexpected token 'session-start'", and the
using-superpowers bootstrap never reaches the session.
Copilot prefers a hook's powershell key over command when it is present, so
add one that runs the same wrapper with the & call operator. Claude Code
ignores the key and keeps dispatching command through Git Bash.
Verified on Windows 11 in a VM: Copilot CLI 1.0.103 logged the ParserError
and sent no bootstrap before the change, and ran the hook and sent the
bootstrap after it. Claude Code 2.1.308 ran the hook and sent the bootstrap
both before and after.
The new test in test-run-hook-cmd-windows.sh runs the hooks.json powershell
value through powershell.exe against a plugin root with a space in its path.
Co-authored-by: Tugrul Guner <tugrulguner@users.noreply.github.com>
Co-authored-by: Serge ARADJ <orty@users.noreply.github.com>
Claude-Session: https://claude.ai/code/session_01SHANcr4A71nzuU9et4Fnba
|
|
current directory, keeps exit codes (#2393)
Combines and supersedes #1864 and #2365. Fixes #1863.
Co-authored-by: citizen204 <161211652+citizen204@users.noreply.github.com>
Co-authored-by: KaiyiQuan <156817180+KaiyiQuan@users.noreply.github.com>
|
|
(#2349)
* fix(hooks): make SessionStart hooks resolve without external PATH lookups
SessionStart:startup hooks can run before Claude Code's PATH is repaired
(anthropics/claude-code#43127), or ahead of a sibling PATH-fixing hook in
the same startup batch. hooks/session-start and the Unix half of
hooks/run-hook.cmd both shelled out to dirname, cat, and a PATH lookup for
bash itself, so an empty PATH made every SessionStart hook fail outright:
hooks/session-start: line 7: dirname: command not found
hooks/session-start: line 44: cat: command not found
None of those external calls are necessary:
- ${0%/*} replaces $(dirname "$0") for both scripts.
- ${BASH:-bash} replaces a bare 'bash' in run-hook.cmd's exec — bash always
sets $BASH to its own absolute path once running, so no PATH lookup is
needed to re-invoke it.
- $(<file) (a bash builtin) replaces 'cat file' for reading the skill body.
- The trailing '| cat' after each printf branch was a no-op pass-through
through another external binary; removed.
Adds a regression test in tests/hooks/test-session-start.sh that invokes
both hooks under an empty PATH.
Fixes #2310.
* Split $0 on / or \ so cmd-dispatched hooks find the plugin root
run-hook.cmd's Windows half starts bash with a backslash path
(C:\...\hooks\session-start). ${0%/*} found no slash there, so
session-start resolved the wrong plugin root and injected 'Error
reading using-superpowers skill' instead of the skill. MSYS dirname
handled backslashes, so dev was fine. Seen on Windows 11 + Git Bash
5.2.37 via cmd /c run-hook.cmd session-start.
---------
Co-authored-by: Jesse Vincent <jesse@primeradiant.com>
|
|
The SessionStart command string starts with a quoted path, which breaks
both Windows shells Claude Code may hand it to: PowerShell parses the
leading quoted string as an expression and dies on the next bareword
('Unexpected token session-start', #1751), and cmd.exe's /c quote rule
drops the outer quotes when the path contains a metacharacter, so a
profile dir like C:\Users\Name(External) truncates the command at the
'(' (#1918). Either way the bootstrap silently never loads.
Declare shell: "bash" on the hook. Claude Code >= 2.1.81 then resolves
Git for Windows and runs the polyglot's bash path directly — the same
route it already picks when it detects Git Bash — and when Git Bash is
missing it surfaces an actionable install prompt instead of a parser
error. Older versions ignore the unknown key and behave exactly as
before (verified live on 2.0.77 and 2.1.80).
Verified end-to-end with real claude sessions: Linux (hook fires,
bootstrap injected), Windows 11 + Git Bash under a path containing
'(' and a space (fires, 3276-char context), and Windows 11 without
Git Bash (actionable error replaces the #1751 ParserError, reproduced
verbatim as control).
Fixes #1751
Fixes #1918
|
|
hooks/session-start-codex has had no caller since "Remove Codex hooks"
(#1845) deleted hooks-codex.json and its manifest registration; the
Codex manifest now declares an empty hooks object so Codex registers no
session-start hook at all. The script is Codex-specific dead code —
nothing executes it on Codex or any other harness.
- Delete hooks/session-start-codex.
- tests/hooks/test-session-start.sh: drop the two Codex cases that are
redundant with the generic session-start tests (nested-format and the
legacy-warning omission are already covered by the Claude Code cases).
Re-point the "wrapper dispatches" case to the live `session-start`
script so run-hook.cmd dispatch coverage — used by Claude Code and
Cursor in production — is preserved rather than lost.
- docs/porting-to-a-new-harness.md: Codex is no longer a Shape A
(shell-hook) harness, so re-anchor that worked example to Cursor (a
live shell-hook harness that demonstrates the same per-harness field,
schema, and matcher variance) and mark Codex as native skill discovery
with no session-start hook. Clears the references to the deleted
hooks-codex.json.
- docs/windows/polyglot-hooks.md: the "check hooks-codex.json" pointer
referenced a file deleted in #1845; re-point to hooks-cursor.json.
RELEASE-NOTES.md keeps its historical mention of hooks-codex.json (it
accurately records what that release did). The tests/codex-plugin-sync
fixtures build their own synthetic session-start-codex and test the sync
mechanism generically, so they are intentionally left as-is.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
|
* docs: specify Codex native hooks parity
* docs: refine Codex hooks spec after review
* docs: record Codex hook contract spike
* docs: plan Codex native hooks implementation
* feat: support Codex native plugin hooks
* test: add Codex native hook drill coverage
* Simplify Codex hook entrypoint
|