Repository navigation
feat(sente): shell-command hooks from the config (Claude Code format) - #72
Open
yukihamada wants to merge 2 commits into
Open
yukihamada wants to merge 2 commits into
yukihamada wants to merge 2 commits into
Conversation
Adds a `hooks` config key running shell commands on PreToolUse, PostToolUse, UserPromptSubmit, SessionStart, Stop and Notification, implemented as a built-in plugin on top of the existing plugin hooks. Exit code 2 or a JSON decision blocks; failures and timeouts (default 60s) are logged and ignored. Hooks from the user's own config run immediately. Hooks declared by the opened project only run after `sente hooks trust`, bound to a fingerprint of their content so a changed hook asks again. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
This PR doesn't fully meet our contributing guidelines and PR template. What needs to be fixed:
Please edit this PR description to address the above within 2 hours, or it will be automatically closed. If you believe this was flagged incorrectly, please let a maintainer know. |
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
A
hookskey insente.json/sente.jsoncthat runs shell commands on events, in the Claude Code hooks format:{"hooks":{"PreToolUse":[{"matcher":"bash|edit","hooks":[{"type":"command","command":"./check.sh","timeout":60}]}]}}tool.execute.beforedecision:"block"/permissionDecision:"deny"stops the tool; reason goes to the model.updatedInputrewrites argstool.execute.afteradditionalContextappended to the tool outputchat.messageHookBlockedErrorwith the reason); stdout /additionalContextadded as contextchat.message(first prompt of a session in this process)startup/resumesession.idleeventpermission.asked/question.askedeventsImplemented as a built-in plugin (
packages/sente/src/plugin/config-hooks.ts) on top of the existing plugin hooks, so no session loop or TUI changes.session_id,cwd,hook_event_name,tool_name,tool_input(+ snake_case copies such asfile_path),tool_use_id,tool_response,prompt, … Env:SENTE_PROJECT_DIR,CLAUDE_PROJECT_DIR,SENTE_SESSION_ID.a|bexact, otherwise regex; Claude Code tool names (Bash,Edit, …) also match.SecretRedact.sente run.Trust model
~/.config/sente/,~/.sente/,SENTE_CONFIG,SENTE_CONFIG_DIR,SENTE_CONFIG_CONTENT, managed config / MDM, remote well-known and org config.sente.json(c)and.sente/sente.json(c). Not run; a warning is published.sente hooks truststores{file: sha256 of its hooks}in~/.local/state/sente/hooks-trust.json; any change to those hooks (e.g. aftergit pull) disables them again.sente hooks list/untrustincluded.SENTE_TRUST_PROJECT_HOOKS=1for CI.--puredisables config hooks.Differences from Claude Code
Documented in
packages/web/src/content/docs/hooks.mdx(+ja/hooks.mdx): Stop cannot continue the turn; no SubagentStop/PreCompact/SessionEnd/type:"prompt";permissionDecisiononly honoursdeny;transcript_pathis empty; PostToolUse does not run for failed tools; project hooks need trust.Tests
bun run typecheckinpackages/senteandpackages/core: pass.bun test test/plugin/config-hooks.test.ts test/plugin/config-hooks-trust.test.ts test/config/config.test.ts: 142 pass, 0 fail (25 new hook tests: every event, matchers, exit-code and JSON blocks, updatedInput, timeout, failure continues, secret masking, project trust end-to-end throughPlugin.Service, config origin tracking).bun test test/plugin test/config test/session test/server test/cli: 1783 pass / 15 fail after the fix; all 15 also fail on the baseheadless-model-fallback(session prompt/llm loop tests,httpapi-sessionv2 unavailable errors,run-processjson error record, help snapshotstats --completiondrift,openai-wsupgrade rejection,workflow-repeat-p01).packages/sdk/js/script/build.ts); the diff also picks up the previously ungeneratedresourcesconfig field.Manual check (
bun src/index.ts run -m teai/cheap)echo hello-from-shell; the model reported the hook reason; Stop hook received its JSON after the run.sente.json: not run before trust (command executed), blocked aftersente hooks trust, shown as OFF again after editing the matcher.HookBlockedErrorwith the reason, no model call. SessionStart stdout reached the model as context.🤖 Generated with Claude Code