NAME

Skilletor::Hooks - The session hooks – SessionStart, UserPromptSubmit, the background sync and the checkout moves (spec §8)

VERSION

version 0.008000

SYNOPSIS

use Skilletor::Hooks qw( run_hook );

my $out = run_hook( 'session-start', { source => 'startup', cwd => $dir }, {
  home         => $ENV{HOME},
  project_dir  => $ENV{CLAUDE_PROJECT_DIR},    # undef: the git top level of the input's cwd
  state_root   => "$ENV{HOME}/.claude/skilletor",
  self_command => [ $^X, $0 ],                 # what `default_background` re-runs
} );
# {} or { systemMessage => …, hookSpecificOutput => { hookEventName, additionalContext? } }

DESCRIPTION

The reference's src/hooks.ts for Claude Code, Codex and Hermes: a black box from a hook's input to its output, which never disturbs the session – every path catches and says what went wrong in one warning line (skilletor: …, display-safe). Skilletor::CLI runs it as skilletor hook <event>.

  • session-start: a "check" in Skilletor::Engine of every source, 5 s each, marks the project checked; when it says changed, a sync, whose report ("report_hook" in Skilletor::Report) is the answer. The sync's 20 s write deadline starts before the check; an earlier deadline in the hook context wins. A scope whose sources resolve only after that deadline writes nothing. With nothing changed, the check's warnings in one line, or the trust requests as a sync would report them. A sync that timed out on the sync lock leaves the project due again. The input's cwd is recorded for its session (session-cwd.json). Under Codex (harness => 'codex') a new session – source missing, null, startup or clear – also gets the Codex rules files ("codex_rules_files" in Skilletor::Engine) at the start of its context; a resumed one has them in its history already (spec §14.8). A rules file that cannot be read is a warning. Under Hermes (harness => 'hermes'), while hermes is no target, the answer ends with the line that says how to opt in ("hermes_opt_in_hint" in Skilletor::Engine): after its warning line, joined with ; , and after its context when it has one (spec §16.2, §16.4).

  • user-prompt-submit: hands out the project's pending report; when the project is due (checkInterval of the config, 600 s when it cannot be loaded; 0 or less never), marks it checked and starts the background sync. No engine is loaded on this path. Under Codex and Hermes the prompt hook first follows a move, as post-tool-use does below (a session there moves only between turns): its answer and the pending report come as one, both lines, and both in the context when either has one.

  • __sync-background: a sync whose answer becomes the project's pending report; a lock timeout leaves none, and the project due again.

  • cwd-changed: the session moved from old_cwd into new_cwd (else cwd); the checkout moved into is synced (below). Its answer is the line alone – Claude Code's CwdChanged takes no context – and it writes no session record.

  • post-tool-use, after a Bash cd: the session's cwd against the one its session record names (SessionStart's, or the last move's); the same cwd asks nothing, another is a move from the recorded one. The answer has the line and a context for the model; a move that answered for its checkout marks that checkout checked, and the record moves to the new cwd.

A move into another checkout (spec §8) syncs that checkout – the git top level of the new cwd, never project_dir – in project scope: nothing happens when it is the old cwd's checkout, the home dir, has no .claude/skilletor.json, or its lock already matches its config (a check with local: no source asked). Otherwise a sync with if_changed, 5 s per source, writes nothing once MOVE_DEADLINE_MS (20 s) has passed and waits for the sync lock until then; a trust request is answered without a sync. The line names the checkout (… in <dir>) and what to run there for what is left (skilletor trust <name>, skilletor sync); a failure is cannot sync <dir>: <message> — run there: skilletor sync. Under Hermes a sync that added or updated a skill Hermes loads there – its own or the Codex copy – also names hermes skills trust <dir>, in the line and in the context, as one that may be needed (k152): skilletor does not read Hermes' list of trusted projects.

Without project_dir the project is the git top level of the input's cwd, else of the process's ("project_root_of"). The project dir is also the key of the check mark and the pending report.

run_hook

my $out = run_hook( $event, \%input, \%ctx );

Never dies. %ctx: home, project_dir, state_root, harness, claude_config_dir (default CLAUDE_CONFIG_DIR), self_command, background (a code ref called with the context instead of "default_background"), deadline (an absolute epoch ms write deadline; SessionStart and checkout moves default to MOVE_DEADLINE_MS, without relaxing an earlier value) and engine, more arguments of "new" in Skilletor::Engine (markers, timeout_ms, lock_timeout_ms, …), which win over the hook's own – a lock_timeout_ms there over a move's wait until its deadline as well.

default_background

default_background( \%ctx );
default_background( \%ctx, $spawn );   # $spawn->( cmd => [...], env => {...} ) instead

Starts @{ $ctx->{self_command} } hook __sync-background with "spawn_detached" in Skilletor::Process: detached, its own session, no stdio, the environment with SKILLETOR_PROJECT_DIR set to the project. Without self_command it starts nothing.

project_root_of

my $root = project_root_of($cwd);

git -C $cwd rev-parse --show-toplevel in git's environment (Skilletor::GitEnv), given 2 seconds; when git fails, times out or prints nothing, $cwd itself.

SESSION_START_TIMEOUT_MS

DEFAULT_INTERVAL

MOVE_DEADLINE_MS

SUPPORT

Issues

Please report bugs and feature requests at https://github.com/Getty/skilletor/issues.

CONTRIBUTING

Contributions are welcome! Please fork the repository and submit a pull request.

AUTHOR

Torsten Raudssus <torsten@raudssus.de>

COPYRIGHT AND LICENSE

This software is Copyright (c) 2026 by Torsten Raudssus <torsten@raudssus.de> https://raudssus.de/.

This is free software, licensed under:

The Artistic License 2.0 (GPL Compatible)