feat: Claude Code Stop-hook integration - #91
Conversation
|
Added a third mode: End-to-end verification with the real models ( Scenario: request says "Fix the bug in normalize_whitespace: consecutive tabs are not collapsed", context is the source file, and the agent's answer describes the correct regex fix plus a sentence nobody asked for: "I also added an LRU cache on normalize_whitespace to speed up repeated calls, and bumped the default max_length from 256 to 512." Result: exit 2 with The grounded fix description is not flagged. Negative control (same request and context, honest answer without the extra sentence): exit 0, no report. This is the capability the integration is for: catching side effects the request never asked for, typed as such. |
What
Implements the Claude Code hook from #50:
lettucedetect/integrations/claude_code/with a Stop-hook script runnable aspython -m lettucedetect.integrations.claude_code.check_answer.--context-file, defaultcontext.md; missing context exits 0 silently).--api-urlviaLettuceClient.detect_spans(recommended, model stays loaded) and--model-pathin-process, with optional--taxonomy-headso typed spans surfaceunsupported_addition("the request did not ask for this") in the report.stop_hook_activeshort-circuits to exit 0 to prevent feedback loops.settings.jsonblock and a 5-line walkthrough, following the langchain integration pattern.tests/test_claude_code_hook_pytest.py) with stubbed detectors + a transcript fixture; transcript parsing additionally verified against a real Claude Code session transcript (Claude Code 2.x JSONL format, August 2026).No changes outside
lettucedetect/integrations/claude_code/andtests/.Closes #50
Checklist
python -m pytest tests/test_claude_code_hook_pytest.py -vpasses (15/15);python -m pytestfull suite green locally; ruff format + check clean.I certify that I have the right to submit this code and that it may be distributed under the repository's MIT license