SubagentStop Hook

SubagentStop

Triggered when the Subagent conversation ends. Can be used to prevent the Subagent from ending and allow it to continue working.

Input Parameters

Parameter Description
session_id Current session ID
transcript_path Path to the current session’s message log file
permission_mode Current Agent running mode
hook_event_name Hook event name
stop_hook_active Whether the stop hook has been triggered. true means triggered, false means not triggered. Used to avoid infinite loops
{
"session_id": "abc123",
"transcript_path": "~/.Hawa Code/projects/.../00893aaf-19fa-41d2-8238-13269b9b3ca0.jsonl",
"permission_mode": "default",
"hook_event_name": "Stop",
"stop_hook_active": true
}

Output Parameters

JSON Format

When the following data structure is returned, Hawa Code will end normally:

{"ok": true}

When the following data structure is returned, Hawa Code will continue working and send the reason to the model as the reason for continuing:

{"ok": false, "reason": "your explanation"}

Exit Code Format

  • Exit code 0: Success, Hawa Code will stop the task
  • Exit code 2: Failure, Hawa Code will continue working and send stderr to the model as the reason for continuing

Configuration Methods

Prompt Method

Configure Prompt using the $ARGUMENTS placeholder:

{
"hooks": {
"SubagentStop": [
{
"hooks": [
{
"type": "prompt",
"prompt": "Evaluate if Hawa Code should stop: $ARGUMENTS. Check if all tasks are complete."
}
]
}
]
}
}

Command Method

Execute Shell script:

{
"hooks": {
"SubagentStop": [
{
"hooks": [
{
"type": "command",
"command": "node ./hooks/subagent-stop.js"
}
]
}
]
}
}

Example script:

import * as fs from 'fs';
const input = fs.readFileSync(0, 'utf-8');
console.log({
"ok": false,
"reason": input + " Root cause analysis"
});