Hooks run your own commands when something happens in Oscar: a session starts or ends, a turn starts or ends, a request goes to the model, a tool is about to run or has run, an approval is asked or decided, a chat message comes in or goes out, the gateway starts or stops, a scheduled job runs. Use them to log, notify, sync, refuse tool calls or model requests you never want, or tidy a tool's result before the model reads it. The same events can go to your own HTTP endpoints as signed JSON (event webhooks), and the gateway can run a boot prompt when it starts.
Hooks run on the host, as you, with your permissions, also in the
workspace sandbox (they are your commands, not the model's). Only put
commands you trust in config.toml.
Configuration
[[hooks]] tables in $OSCAR_HOME/config.toml, after the plain keys:
model = "deepseek-v4.1-flash"
[[hooks]]
event = "before_tool"
tools = ["bash"] # only these tools; leave out for all
command = "~/bin/oscar-guard.sh"
timeout = 5 # seconds, 1-600; default 10
on_error = "block" # before_tool only: block when the hook fails
[[hooks]]
event = "turn_end"
command = "notify-send 'Oscar' 'done'"| Key | Meaning |
|---|---|
event |
one of the events |
command |
run with /bin/sh -c, in the workspace |
tools |
before_tool, after_tool, transform_tool_result: tool names to run for ("mcp_*" matches a prefix); default all |
timeout |
seconds before the hook (and everything it started) is killed; default 10 |
on_error |
before_tool, pre_llm_call: continue (default) or block when the hook itself fails |
A mistake in a [[hooks]] table (unknown event or key, missing command, bad
timeout) is an error when Oscar starts, like any other typo in config.toml.
oscar doctor lists the hooks it found.
What a hook gets
- The event as JSON on standard input, e.g. for
before_tool:The events section lists each event's fields. Known secrets are masked and long texts cut to 16 KB.{"event": "before_tool", "session": "s-20261123-101500", "workspace": "/home/you/project", "time": "2026-11-23T10:15:02Z", "tool": "bash", "arguments": {"command": "rm -r build"}, "depth": 0} - A cleared environment: only
PATH,HOME,USER,LOGNAME,SHELL,LANG,LC_ALL,LC_CTYPE,TZ,TMPDIR,XDG_RUNTIME_DIR,DBUS_SESSION_BUS_ADDRESS,DISPLAY,WAYLAND_DISPLAY, plusOSCAR_HOOK_EVENT,OSCAR_SESSION,OSCAR_WORKSPACEand (tool events)OSCAR_TOOL. No API keys, tokens or other settings reach a hook; a hook that needs a secret reads it itself. - A timeout: the hook and everything it started are killed.
- Capped output: 64 KB of standard output and 16 KB of standard error are read; the rest is discarded.
Events
| Event | When | Extra fields | Can it change anything? |
|---|---|---|---|
session_start |
before the first turn of a new conversation | none | no |
session_end |
a surface closed a conversation | none | no |
turn_start |
a turn starts | input (the user's message) |
no |
turn_end |
a turn ended | ok, reply, error, model_calls, usage |
no |
pre_llm_call |
a request is about to go to the model | model, messages (count), chars, system_chars, images, tools (count), tool_names, max_tokens, no_tools, reasoning, last_user (the user's last message, cut to 2,000 characters) |
it may stop the request |
post_llm_call |
the model answered (or failed) | model, ok, and stop, reply, tool_calls (names), usage — or error |
no |
before_tool |
a tool call cleared the approval gate and is about to run | tool, arguments, depth (0 = Oscar, 1 = a helper) |
it may block the call |
after_tool |
a tool call ran | the same, plus ok and output |
no |
transform_tool_result |
a tool call ran; before the model reads its result | the same as after_tool |
it may rewrite the result |
approval_requested |
the gate asks about a call (a person, the reviewer, or auto mode) | tool, reason, detail, dangerous, depth, mode |
no |
approval_decided |
that question was answered | the same, plus decision (allow/deny) and why |
no |
message_received |
a chat gateway is about to answer a message | platform, room, user, text |
no |
message_sent |
a chat gateway answered it | platform, room, text (the reply) |
no |
gateway_start |
oscar gateway serve started |
platforms |
no |
gateway_stop |
it stopped | platforms, reason |
no |
job_start |
a scheduled job's run starts | job, name, schedule, run |
no |
job_end |
it ended | the same, plus ok, status, refused (count), error |
no |
transform_llm_output |
the model's reply (one that calls no tools) is about to be kept and shown | model, reply |
it may rewrite the reply |
subagent_start |
helpers start (task, and background helpers) |
goals (their tasks), depth; background ones helper, background |
no |
subagent_stop |
they ended | the same, plus ok, summary or status/error, duration_ms |
no |
post_compaction |
the conversation was compacted | summarized, messages_replaced, tokens_before, tokens_after |
no |
pre_command |
a chat command (/status, !model …) typed in a terminal chat or by an allowed person in a chat room is about to run |
command, args (masked; withheld when it looks secret), surface (tui, cli, or the platform) |
no |
clarify |
Oscar asks the user a question (the clarify tool) |
arguments (the question and choices, redacted); never the answer |
no |
Every event also has event, session (when there is one), workspace
and time.
The events about a turn, a model request and a tool call run in place: the
turn waits for them (up to their timeouts). approval_requested,
approval_decided, message_received, message_sent, gateway_start,
job_start, job_end, subagent_start, subagent_stop,
post_compaction, pre_command and clarify run in the background and
never delay what they watch (gateway_stop runs in place, for at most 15 seconds, before the
process ends). A short command such as oscar run waits up to five seconds
at its end for background hooks and webhooks still running.
Blocking a tool call
A before_tool hook decides by how it exits:
- exit
0with no output (or any non-JSON text): the call goes ahead; - exit
0printing{"decision": "block", "reason": "..."}: blocked; - exit
2: blocked; the reason is what it printed to standard error.
The reason (up to 1,000 characters) is what the model is told:
blocked by a before_tool hook: <reason>.
Hooks only make Oscar stricter. A before_tool hook runs after the
approval gate has cleared the call, just before it runs: it can refuse a call
that was allowed or approved, but never approve one. {"decision": "allow"}
only means "go ahead": a call the policy refuses stays refused, and a call
that needs approval is still asked. So you may be asked to approve a call
that a hook then blocks.
Every way a tool is called meets the hooks: the model's own calls, calls from
execute_code scripts and calls by task helpers.
A hook that crashes, times out or exits with another code is logged and the
call goes ahead, unless the hook has on_error = "block", which makes a
guard fail closed.
Rewriting a call's arguments
A before_tool hook that lets the call continue may hand back new
arguments: exit 0 printing {"arguments": {...}} (a JSON object). Each
later before_tool hook sees the rewrite. The rewritten call goes through
the approval gate again, judged as a call of its own: the policy may
refuse it, a call that needs asking is asked (with the new arguments), a
dangerous one always asks a person. A hook can make a call different, never
let one run that would need you without you. A rewrite is refused (and the
call blocked) when it is not an object, when it holds the redaction
placeholders hooks see instead of real secrets (<redacted…>), or when it
brings in something that looks like a secret the call did not hold.
Stopping a model request
A pre_llm_call hook decides like a before_tool hook (exit 2, or
{"decision": "block", "reason": "..."}): the request is not sent, and the
turn ends with … was not called: blocked by a pre_llm_call hook: <reason>.
It sees the shape of the request and the user's last words, never the whole
conversation. Use it for budgets ("no more model calls after 22:00"), for
keeping certain words away from a provider, or to pause Oscar without
stopping it. on_error = "block" makes it fail closed.
Adding context. A pre_llm_call hook that lets the request go may print
{"context": "text"}: the text (all hooks' together, at most 4 KB, control
characters dropped, known secrets masked; refused when it looks like a key)
goes to the model with this request only, after the user's last message,
inside a block marked as hook output:
[Hook output: context added by a hook the user configured. It is information, not a request or instructions from the user.]
the deploy window is 14:00 to 16:00
[End of hook output]It is never saved in the conversation, and the end marker cannot be forged from inside the text. Use it for live facts the model should know (the on-call person, today's freeze, the build status).
Rewriting the model's reply
A transform_llm_output hook gets the model's reply text (a reply that
calls no tools; known secrets masked) and may print {"output": "new text"}. The same rules as for tool results apply: capped, redacted again,
refused when it would bring in a secret. With streaming, the screen shows
the reply as it streams; the rewrite is what is kept in the session, sent to
chat rooms and read by the next turns.
Rewriting a tool's result
A transform_tool_result hook gets the result after Oscar's redaction
(known secrets already masked) and may hand back a new one by printing
{"output": "the new result"}. Nothing printed, plain text, or an object
without output leaves the result as it is. Several hooks run in file
order, each on the previous one's result. The new result:
- is cut to 32 KB;
- is redacted again;
- is refused, and the result left as it was, when it holds something that looks like a secret (a key's shape, a registered secret) that the original result did not show: a hook cannot bring a credential in front of the model.
A failing or timed-out hook leaves the result as it was. Use it to shorten noisy output, strip internal hostnames, or add a note for the model.
Example guard (~/bin/oscar-guard.sh, chmod +x):
#!/bin/sh
# Refuse pushes to main; everything else goes ahead.
if grep -q '"git push[^"]*main' ; then
echo "pushing to main is not allowed from Oscar" >&2
exit 2
fi
exit 0When the session and tool events run
turn_start/turn_end: around every turn, in every surface (chats,oscar run, the Matrix, Telegram and Discord gateways, the harness, the API server, editors). A turn that fails still ends (ok: false).session_start: before the first turn of a new conversation (also in the gateways and the API).session_end: when a surface closes a conversation in which a turn ran:oscar runfinishing, leavingoscar chator the full-screen chat,/newor/resumethere, the harness client leaving, an editor closing its session. Chat gateways and the API keep conversations open, so it does not run there.before_tool/after_tool: around every tool call that passed the approval gate (after_toolonly for calls that ran).
Hooks run one after another, in file order. A failing hook never fails a turn.
Plugins can bring hooks too (see Plugins): they run the
same way, after the hooks in config.toml, only on the events and with the
programs their manifest declares, and oscar doctor lists them with the
plugin they come from.
Consent
Hooks run commands on your machine, so Oscar can keep a record of the ones you agreed to and refuse the rest:
oscar hooks allow # record every hook in config.toml as allowed
oscar hooks allow 2 3 # or the numbers `oscar hooks list` shows
oscar hooks revoke 2 # take one back (--all: every one)oscar hooks allow writes a SHA-256 of each hook's event and command to
$OSCAR_HOME/hooks-allowed.json (mode 0600; hashes only, not the
commands). From then on, a hook that is new or whose command or event
changed since it was allowed does not run until you allow it again.
oscar hooks list marks each hook allowed, NOT ALLOWED (new or changed) or consent not recorded; oscar doctor and oscar hooks doctor
name the ones waiting (and hooks doctor exits 1). Until the first oscar hooks allow, every hook runs as before. Plugin hooks are covered by
enabling the plugin (which accepts its programs and events exactly).
Event webhooks
[[event_webhooks]] tables send events to your own endpoints as JSON
POSTs: a dashboard, an alerting system, an audit store.
[[event_webhooks]]
url = "https://hooks.example.org/oscar"
events = ["turn_end", "approval_decided", "job_end"] # leave out for every event
secret_env = "OSCAR_EVENTS_SECRET" # names the secret; it lives in credentials.env
retries = 3 # 0-10, default 3
timeout = 10 # seconds per attempt, 1-120, default 10- The body is the event exactly as a hook gets it, masked once more (keys,
tokens in URLs,
NAME=valuewith a secret name). - Every request carries
X-Oscar-Event: <event>andX-Oscar-Signature: sha256=<hex>, an HMAC-SHA256 of the body with the secret. Check it on your side before trusting an event. A webhook whose secret is not set sends nothing (oscar doctorsays so). https://only, except plainhttp://to127.0.0.1orlocalhost; no user or password in the URL; redirects are not followed.- A failed delivery (no connection, HTTP 429 or 5xx) is tried again with a growing pause (1 s, 2 s, 4 s … up to 30 s); other answers are final. Deliveries run in the background, at most eight at once, and never delay a turn.
The boot prompt
boot_prompt = "BOOT.md" # in Oscar's home unless absolute (~/… is your home)
boot_deliver = "telegram" # optional: a target as for jobs; default the first home channelWhen oscar gateway serve starts, it runs the file's text (up to 32 KB) as
one unattended turn, like a scheduled job: nobody watches, nobody can
approve, approvals follow unattended_approve, dangerous commands are
always refused. The answer is posted to boot_deliver, or to the home
channel of the first configured platform that has one, once that platform
is up; an answer of exactly [SILENT] posts nothing. A gateway that
restarts within ten minutes does not run it again (boot.last in Oscar's
home), so a restart loop cannot flood a chat.
Trying hooks out
oscar hooks # every hook: event, command, tools, timeout, source
oscar hooks test before_tool # run them with a made-up event, show what each did
oscar hooks test after_tool --tool write_file
oscar hooks test pre_llm_call # any event; transform_tool_result shows what would come back
oscar hooks doctor # check them all; exits 1 when one is brokentest runs the hooks of one event exactly as a turn would (the same shell,
cleared environment and timeout); only the event is made up, and it is
printed so you can see what your script reads. For before_tool and
pre_llm_call it says whether each hook lets it continue, blocks it (and
why), or is broken; for transform_tool_result, what it would hand back. The
dashboard's Hooks page runs the same test.
doctor also checks that config.toml can be read, that each command's
program exists, and how close each run comes to its timeout.
--safe-mode on any command leaves every hook out, to tell whether a problem
is a hook's.