Skip to content

feat(sente): shell-command hooks from the config (Claude Code format) - #72

Open
yukihamada wants to merge 2 commits into
headless-model-fallbackfrom
sente-hooks
Open

yukihamada wants to merge 2 commits into
headless-model-fallbackfrom
sente-hooks

Conversation

@yukihamada

Copy link
Copy Markdown
Owner

What

A hooks key in sente.json / sente.jsonc that runs shell commands on events, in the Claude Code hooks format:

{"hooks":{"PreToolUse":[{"matcher":"bash|edit","hooks":[{"type":"command","command":"./check.sh","timeout":60}]}]}}
Event Built on Effect
PreToolUse tool.execute.before exit 2 / decision:"block" / permissionDecision:"deny" stops the tool; reason goes to the model. updatedInput rewrites args
PostToolUse tool.execute.after reason / additionalContext appended to the tool output
UserPromptSubmit chat.message block drops the prompt before it is saved (server answers 400 HookBlockedError with the reason); stdout / additionalContext added as context
SessionStart chat.message (first prompt of a session in this process) stdout added as context; source startup/resume
Stop session.idle event notification only (cannot continue the turn yet)
Notification permission.asked / question.asked events notification only

Implemented 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.

  • stdin JSON: session_id, cwd, hook_event_name, tool_name, tool_input (+ snake_case copies such as file_path), tool_use_id, tool_response, prompt, … Env: SENTE_PROJECT_DIR, CLAUDE_PROJECT_DIR, SENTE_SESSION_ID.
  • Matchers: plain a|b exact, otherwise regex; Claude Code tool names (Bash, Edit, …) also match.
  • All matching hooks run in parallel. Timeout per hook (default 60s) kills the process group. Non-0/2 exits, timeouts and spawn failures are logged and ignored; Sente never fails because of a hook.
  • Reasons and context sent to the model go through SecretRedact.
  • Background hooks (Stop/Notification) are awaited on plugin dispose, so they also finish under sente run.

Trust model

  • Trusted (run immediately): ~/.config/sente/, ~/.sente/, SENTE_CONFIG, SENTE_CONFIG_DIR, SENTE_CONFIG_CONTENT, managed config / MDM, remote well-known and org config.
  • Untrusted: the opened project's own sente.json(c) and .sente/sente.json(c). Not run; a warning is published. sente hooks trust stores {file: sha256 of its hooks} in ~/.local/state/sente/hooks-trust.json; any change to those hooks (e.g. after git pull) disables them again. sente hooks list / untrust included. SENTE_TRUST_PROJECT_HOOKS=1 for CI. --pure disables 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"; permissionDecision only honours deny; transcript_path is empty; PostToolUse does not run for failed tools; project hooks need trust.

Tests

  • bun run typecheck in packages/sente and packages/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 through Plugin.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 base headless-model-fallback (session prompt/llm loop tests, httpapi-session v2 unavailable errors, run-process json error record, help snapshot stats --completion drift, openai-ws upgrade rejection, workflow-repeat-p01).
  • SDK types regenerated (packages/sdk/js/script/build.ts); the diff also picks up the previously ungenerated resources config field.

Manual check (bun src/index.ts run -m teai/cheap)

  • User-config PreToolUse hook (exit 2) blocked echo hello-from-shell; the model reported the hook reason; Stop hook received its JSON after the run.
  • Same hook in the project's sente.json: not run before trust (command executed), blocked after sente hooks trust, shown as OFF again after editing the matcher.
  • UserPromptSubmit exit 2 → HookBlockedError with the reason, no model call. SessionStart stdout reached the model as context.

🤖 Generated with Claude Code

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>
@github-actions

Copy link
Copy Markdown

This PR doesn't fully meet our contributing guidelines and PR template.

What needs to be fixed:

  • PR description is missing required template sections. Please use the PR template.

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

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant