The JWT chain scanner only accepted a header at the start of a segment or
after `-`, so `session_<JWT>` reached the audit and cost logs unredacted.
Treat `_` as a prefix boundary too and cover it in the tests.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
CLASSIFIER_NOTICE matched by prefix, so a pasted notice followed by a
user question was dropped from both summary paths. Anchor it to the
whole message so trailing user text is kept, and add a regression test.
Also pass ECC_SKIP_LLM_SUMMARY=1 in the withTranscript fixture helper so
an inherited ECC_LLM_SUMMARY_INTERVAL=1 cannot trigger claude -p.
Refs #3867
Assisted-by: Claude <noreply@anthropic.com>
In double quotes Bash drops a backslash-newline before it expands
anything, so a tail of `$\<newline>HOME` after the substitution's `)` is
`$HOME` and expands. The expansion check read the tail with the
continuation still in it and saw an escaped newline, so the hook
validated `fix: a$HOME` with no warning. Continuations are now dropped
first, while other escapes stay for the check: `\$\<newline>HOME` is
still the literal `$HOME`.
In `-m "$(cat <<'EOF' … EOF\n)."` Bash drops the body's trailing newlines
and adds the period, so Git records `fix: update input.`, but the hook
checked only the here-document and missed the trailing-period warning.
Read the rest of the quoted value after the substitution's `)` and add
it to the message as double-quoted text. Commands or an expansion after
the here-document make the message unverifiable, as an expansion in an
unquoted body already does. The here-document reading moves into
readHeredocMessage, which also returns the Bash 3.2 note.
Since expanded here-document segments are queued too, a long substitution puts every segment in the queue, and shift() copied it each time: 130,000 segments took about 20 s, past the hook timeout. An index keeps the walk linear (under 0.3 s).
Bash ends a decoded $'...' string at its first NUL, so `cat <<$'EOF\0X'`
ends at the line EOF, but the splitter looked for EOF\0X and swallowed
the commands after the body. A carriage return or a no-break space is
not a blank to Bash, so `echo foo\r# && npm run dev` runs the dev
server, but the splitter read the # as a comment. And spreading a long
substitution's segments into push() threw RangeError, which the hook's
catch turned into an allow. Truncate the decoded part at the NUL, use
Bash's blanks for word starts, and append the segments one at a time.
The tracker serialized any structured result with JSON.stringify before
redaction, so an encoding nested in it, such as a double-escaped JSON
token, reached tool-usage.jsonl whole, and Claude Code's Bash stdout went
in as text. Keep text only from the adapter's tool_output, as main did,
and from Claude Code's tool_response only the sizes of stdout and stderr
and its interrupted and image flags. Any other structure is left out.
The safety-classifier notice filter only covered the mechanical summary.
When generateSessionSummary runs (low context or message interval),
extractConversationText read the raw transcript and passed the notice to
the LLM as a user turn, so it could still reach saved context.
Move the check into one shared isClassifierNotice() in
scripts/lib/llm-summary.js and use it in both userMessageText() and
extractConversationText(). Add LLM-path regression tests, and split the
session-end classifier-notice tests into small functions (<50 lines).
Refs #3867
Assisted-by: Claude <noreply@anthropic.com>
The dev-guard half of 7632669d from #3735: segments that the splitter
reads from an expanded here-document body are scanned again, so a dev
command in a substitution nested inside one is still found.
(split from commit 7632669d28)
In an unquoted here-document, Bash removes a backslash-newline before Git
receives the message, so `fix: \` followed by `Update input.` commits
`fix: Update input.`, and a delimiter line right after a continued line
does not end the body. Read the body that way, keep `<<-` from stripping
the tabs of a continued line, and drop the backslash before $, ` and \.
A quoted body stays literal, as Bash 4 and later and zsh read it. Inside
"$(...)", Bash 3.2 joins its lines too, so the hook now notes when that
would change the subject.
The commit-quality half of 7632669d from #3735: a single-quoted -m
message keeps its backslashes, and an unquoted here-document whose body
Bash would expand yields an advisory that the subject cannot be validated
from the literal command.
(split from commit 7632669d28)
In `echo $$'\'; npm run dev`, Bash reads `$$` as the process-ID parameter
and the quote after it as an ordinary single quote, so it runs
`npm run dev`. The splitter took the second `$` as the start of ANSI-C
quoting, which hid the semicolon, and a here-document delimiter such as
`$$'EOF'` was read as `$EOF`, so the body never ended. Consume the `$$`
pair first in both places.
The lookbehind added to keep the JWT scan linear also skipped tokens right
after a `-`, so `--cookie "session=jwt-<JWT>"` reached the logs unredacted.
Scan each `[A-Za-z0-9_.-]` run once instead, checking every dot segment for
a header at its start or after a `-`, decoding at most once per segment so
long `ey-ey-...` runs stay linear.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
When a response is stopped by the safety classifier, the harness records
a notice ("Your response above was stopped by a safety classifier ...")
as a user entry in the transcript. session-end.js kept it as a user
message, so it was written under "### Tasks" and re-injected by
session-start.js on the next session.
userMessageText() now drops entries that start with that notice, next
to the existing HARNESS_NOISE filter. User messages that only mention
the phrase are kept, since the match is anchored to the start.
Fixes#3867
Assisted-by: Claude <noreply@anthropic.com>
- Replace the secret=/api_key= value regex with a single-pass, quote-aware
scanner so the whole Bash word is redacted when quoted and unquoted
fragments are joined (e.g. --secret='prefix-'suffix), while a value inside
an enclosing quoted string stops at that string's closing quote.
- Searching for the keyword itself (grep -n "secret =" file,
rg 'api_key:' dir) no longer redacts the rest of the command.
- Use a lookbehind instead of \b before the JWT header so long dot-free
ey-ey-... runs are scanned in linear time instead of quadratic.
- Add regression tests for joined fragments, keyword searches, and the
ey- performance case.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Match JWT headers that start with ey or ew (whitespace after the opening
brace) and keep non-eyJ matches only when the header does not decode to
an object with an alg field. Parse secret= / api_key= values with escaped
double quotes, $'...' quoting and backslash escapes, and redact an
unterminated quoted value to the end of the command.
Refs #3846
sanitizeCommand only redacted keyword- or flag-shaped secrets, so a bare
Anthropic/OpenAI sk- key, a JWT, a PEM private key block, or a secret= /
api_key= / x-api-key: value was written verbatim to bash-commands.log and
cost-tracker.log. Add value-shape patterns for these and keep the key name
and separator for assignments so the log stays readable.
Refs #3846
Address bot review on the Stop delivery path: the stop:evaluate-session
registration no longer carries async (an async Stop registration cannot
block), so delivery is synchronous, and the metadata fingerprint for the
changed entry is regenerated with the repo's own function; the delivery
marker is now claimed atomically with exclusive create and any write
failure fails closed instead of delivering without once-per-session
protection; the skill doc now marks the shell entry as counting-only,
requires the JavaScript evaluator through the plugin hooks for delivery,
and clarifies that Stop fires whenever Claude finishes responding; test
spawn helpers no longer coerce a failed spawn to exit 0.
Test plan:
- tests/hooks/evaluate-session.test.js: 25 passed, 0 failed (2 new:
marker write failure skips delivery, registration is synchronous);
pristine comparison: 22 passed, 3 failed (delivery, marker, registration)
- tests/hooks/hooks.test.js: 260 passed
- tests/hooks/stop-hooks-stdout.test.js: 48 passed
- tests/hooks/cursor-hook-dispatchers.test.js: 27 passed
- tests/integration/hooks.test.js: 27 passed
- scripts/ci/check-unicode-safety.js: passed
The v1 evaluator computed the learning signal but wrote it to stderr, which Claude Code never forwards to the model, so the learned-skills folder was never populated through this path.
Delivery now follows the maintainer-endorsed shape: an explicit stop_nudge_opt_in flag (default off, so existing installs are unchanged), the native Stop block contract (decision block plus reason) instead of plain stdout text, at most one delivery per session via a temp-dir marker, Stop-loop protection via stop_hook_active, and delivery only for sessions with a registered lease from SessionStart.
Tests: 7 new evaluator tests (opt-in off, no lease, one valid block then silence on repeat, stop_hook_active, short session, non-Stop event, missing session id). Evaluator suite 23/23 with the fix, failing on pristine; hooks suite 260/260; Stop stdout contract suite 48/48.
Limits stated plainly: end-to-end delivery in a live Claude Code session is not certified from this host (unit-level spawn plus parse only), and the fix ships inert by default until a user opts in.
config-protection.js and post-edit-typecheck.js attached process.stdin
listeners at module scope. tests/hooks/hook-input.test.js requires
config-protection.js, so that test never exits while stdin stays open.
Attach the listeners only when the script runs directly
(require.main === module), as stop-format-typecheck.js and quality-gate.js
already do.
post-edit-typecheck.js picked tsc diagnostics with line.includes(candidate),
so editing a root index.ts reported the errors of src/index.ts, and a
Windows relative path (src\index.ts) never matched tsc's forward-slash
output. Compare the file at the start of each diagnostic instead, the same
check diagnosticMatchesFile() does in stop-format-typecheck.js.
Refs #3821
On Windows, Claude Code kills an overrunning hook by killing the bash.exe
wrapper; the node.exe runner underneath survives. If another process still
holds the write end of the runner's stdin (a handle inherited by a process
spawned at the same moment), the runner never sees EOF and waits forever.
Orphaned runners were observed living 3-18 hours.
Add scripts/hooks/hook-watchdog.js and start it from the four hook entry
points (plugin-hook-bootstrap, run-with-flags, posttooluse-dispatcher,
lifecycle-hook-bootstrap). It exits the process when the parent PID is gone
(Windows) or the process was re-parented (POSIX), polled every 2s, or when a
hard deadline passes (330s, above the longest hooks.json timeout, or an
earlier inherited ECC_HOOK_DEADLINE_MS). Timers are unref'd so a finished
hook is never kept alive.
The regression test reproduces the leak with a detached runner whose stdin
write end is held by an unrelated process; it fails without the watchdog
(runner still alive after 8s) and passes with it.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Reject numeric prefixes, fractions and unsafe window integers consistently with summary scheduling while preserving resolver precedence. Cap only the default context reminder at eighty percent of a valid earlier native compaction budget; explicit thresholds, including zero, retain their intentional policy. Document the independent capacity, summary and advisory contracts.
RED controls reproduce malformed-budget summary triggers and the known-1M/native-200k missed reminder. Resolver65, helper47, actualStop18 and actualPreToolUse54 pass on Node18 and24. Parent and independent reviewer approved the exact diff before commit. Registry rebinding remains the integration coordinator responsibility after combining documentation repairs.
Restore the shipped payload-first contract from #3464/#3495 and the explicit source #3755 scope clarification. Two provider conversations must retain distinct IDs despite an inherited registered ECC parent ID. Normal and ambient producer24 tests, canonical resolver10 and independent differential review pass. Keep native importer guards; explicit provider/native correlation is queued separately.
Verify review discussion4419348312 against actual native producer/importer behavior. Prefer the independently sanitized ECC_SESSION_ID for the ECC-owned metrics feed, retain payload then legacy fallback for standalone hooks, and leave sibling hooks unchanged.
Actual Node producer plus read-only cached native binary reproduces zero imported metrics before the fix and exactly one tool/file/log after repeated sessions/status commands. Four producer regression controls and normal/adversarial inherited-env suites pass22/22. Focused coverage96.47percent lines and91.47percent branches; parent independent source review passed.
Separate confirmed model capacity from Stop-summary scheduling. Use the smaller confirmed capacity/native budget, or native-only budget for inferred capacity. Three unit and one actual hook RED cases now pass; helper43, actualStop15 and ten independent controls pass without changing the capacity resolver.
AGENTS.md asks for new objects rather than mutation. toggleQuote now returns the updated quote state (or null when the character is not a quote it toggles), skipOuterSpan returns it alongside the skipped index, and each scanner reassigns its own local state.