@veda-hq/sarathi
सारथि, charioteer. Runs a project's Claude Code hooks from one settings entry
per event, with kavach's guards built in, publishes claude.ai
pages for sessions without the Artifact tools, and carries the sarathi
plugin's agents. Part of Veda.
Why a package and not only a plugin
A Claude Code plugin cannot carry permissions or environment (a plugin's
settings apply only agent and subagentStatusLine), and a cloud session
does not install the plugins a repository lists, because that needs the
folder-trust dialog a cloud session never shows. A pinned package installs
wherever the repository's dependencies do: a laptop, a cloud session, a second
repository. So the hooks run from the package, and the plugin carries what
only a plugin can: the agents.
The hooks
The project's settings keep one entry per event that runs sarathi:
{
"hooks": {
"PreToolUse": [
{ "matcher": "Bash|Edit|Write|NotebookEdit",
"hooks": [{ "type": "command", "command": "npx --no-install sarathi hook PreToolUse", "timeout": 70 }] }
],
"Stop": [
{ "hooks": [{ "type": "command", "command": "npx --no-install sarathi hook Stop", "timeout": 130 }] }
]
}
}
and the handlers live in .claude/sarathi.json, in the shape of the
settings' own hooks block, one entry per handler:
{
"kavach": { "config": ".claude/kavach.json", "python": "python3" },
"hooks": {
"PreToolUse": [
{ "matcher": "Bash|Edit|Write|NotebookEdit", "guard": "worktree" },
{ "matcher": "Bash", "guard": "command" },
{ "matcher": "Write|Edit|MultiEdit|RemoteTrigger|mcp__ccd_host__sync_with_base_branch|Workflow", "guard": "tool" },
{ "matcher": "Edit|Write", "command": "./scripts/check-edit.sh", "timeout": 10 }
],
"Stop": [{ "command": "./scripts/keep-going.sh", "timeout": 120 }]
}
}
| Key |
Meaning |
matcher |
Claude Code's: absent or * for all, A\|B for exact names, else a regular expression |
command |
Run through sh -c with the event on stdin, as Claude Code runs a hook |
guard |
worktree, command or tool: kavach's guard, run by kavach.python with KAVACH_CONFIG set to kavach.config (tool reads the tools kavach's rules name besides Bash; its README gives the matcher) |
timeout |
Seconds before the handler and its children are stopped (60) |
failClosed |
Any end but exit 0 refuses the call; always true for guards |
sarathi hook <Event> runs the matching handlers side by side and answers
Claude Code once, as Claude Code combines several hooks' answers: any exit 2
blocks with every blocker's reason; a fail-closed handler that crashes or
runs out of time blocks too. sarathi blocks with exit 2 either way, which
drops every JSON answer, so on Stop and SubagentStop the other handlers'
decision: "block" reasons, then their additionalContext, follow the
blockers' reasons on stderr, each after a blank line. JSON answers merge with the strictest decision
winning (deny over ask over allow, block over none, continue: false over
true) and every handler's context kept; a handler that failed without
blocking is named in systemMessage, or on stderr with exit 1. A hook list
that cannot be read refuses PreToolUse and only warns on other events.
sarathi check --settings .claude/settings.json proves the settings run
sarathi for every event the list names, with a matcher that lets every
handler fire and a timeout at least the longest handler's. Run it in the
project's tests. An event may have more than one settings entry that runs
sarathi, each held to that timeout, but no tool two of them cover: sarathi
would run twice. A handler's regular expression is covered only by an entry
with that same matcher, or one with none, since whether one pattern covers
another cannot be proved. So a handler matched by suffix gets an entry of its
own beside the plain names:
{ "matcher": "^mcp__.+__(publish_version|publish_files|edit_version)$",
"hooks": [{ "type": "command", "command": "npx --no-install sarathi hook PreToolUse", "timeout": 70 }] }
Handlers it carries
Every command runs with SARATHI_HOOKS set to the package's hooks/
folder, which holds handlers any TypeScript repository can list:
{ "matcher": "Edit|Write", "command": "bash \"$SARATHI_HOOKS\"/code-quality-guard.sh" }
| Handler |
Event |
What it does |
format-before-write.sh |
PreToolUse, Edit\|Write |
Hands the tool prettier-formatted input, so the file is written formatted and Claude Code has no "hook modified your file" notice to keep in context. Never blocks. |
format-on-edit.sh |
PostToolUse, Edit\|Write |
Formats the written file with prettier: the net for what the first one skips. Never blocks. |
code-quality-guard.sh |
PostToolUse, Edit\|Write |
Refuses @ts-ignore, @ts-nocheck, eslint-disable, any and skipped tests in a .ts/.tsx edit. .claude/, .agent/ and docs/ are exempt. |
arch-guard.sh |
PostToolUse, Edit\|Write |
Runs the repository's .dependency-cruiser.js on a .ts/.tsx edit that touches imports; refuses what it refuses, and refuses when it cannot run. scripts/ is exempt too. |
session-dedupe-guard.sh |
PreToolUse, session starts |
Refuses starting a session unless the conversation called list_sessions successfully in the last 15 minutes. |
ask-gate.sh |
PreToolUse AskUserQuestion\|mcp__ccd_turn__wrap_up; Stop; PostToolUse AskUserQuestion (the log) |
Holds, once per turn, a question to the owner when the session has done no research since the owner's last message: refuses the ask, or on Stop keeps the turn going when the closing message asks the owner to choose ("Research before you ask"). Logs each gated ask and each answer ("The ask log"). |
researcher-report.sh |
PreToolUse SubagentHandback; SubagentStop ^sarathi:researcher$ |
Sends the plugin's sarathi:researcher report back when it has no Verdict line, a Settled or Conflicting verdict with no claims, or a claim without its source and read date ("The researcher's report"). |
lessons.sh |
PreToolUse Bash\|Edit\|Write\|Agent\|Task\|mcp__ccd_session__start_session; PostToolUseFailure |
Shows a lesson whose when line matches the call ("Lessons at their moment"). Never blocks. |
autofix-watch.sh |
PostToolUse Bash\|mcp__ccd_pr__set_monitor\|mcp__ccd_pr__get_status\|mcp__ccd_turn__wrap_up; PostToolUseFailure mcp__ccd_pr__set_monitor |
Lists every pull request the session opens and tells the model, in its context, about each open one that Auto-fix is not on for ("Auto-fix for every pull request"). Never blocks. |
action-box.sh |
PreToolUse ^mcp__.+__(publish_version\|publish_files\|edit_version)$ |
Refuses a session's direct claude.ai publish whose page has no whole action box ("Pages"). List it with "failClosed": true. |
worktree-archive.sh |
PreToolUse ExitWorktree (and Codex's set_thread_archived) |
Denies removing or archiving the session's worktree while sarathi worktree archive-check finds work that would be lost ("Worktrees"). List it with "failClosed": true. |
services-reap.sh |
SessionStart |
Starts sarathi services reap detached, output discarded, when docker is on PATH: deleted worktrees' services go ("Services"). Never blocks; always exits 0. |
worktree-hooks-path.sh |
SessionStart |
Clears a worktree-scoped core.hooksPath in the session's checkout, which tools that create worktrees write as an absolute path to another checkout's hooks, so the repository's shared value applies again ("Worktrees"). Acts only when extensions.worktreeConfig is on, since without it there is no scoped value. Clears an empty value too: under hooksPath = git runs no hooks at all. Says what it cleared, or, when the key is still there after the clear, warns with its value and the config.worktree path; always exits 0. |
They act on the session's checkout, the git toplevel of the event's cwd:
the desktop app runs a worktree session's hooks with $CLAUDE_PROJECT_DIR
set to the main checkout. They use that checkout's prettier and
dependency-cruiser, and the project checkout's prettier when a fresh worktree
has none installed. They need bash, jq and git;
session-dedupe-guard.sh, ask-gate.sh and researcher-report.sh run
HOOK_PYTHON, or python3.