chenhg5/cc-connect · error
event is required
Error message
event is required
What it means
validateHookConfig in core/hooks.go checks each HookConfig before a HookManager accepts it. Every hook must declare which event it listens for; an empty Event field is rejected with this error. This runs when NewHookManager is constructed (e.g. from parsed config.toml hooks entries).
Source
Thrown at core/hooks.go:109
if err := validateHookConfig(h); err != nil {
slog.Warn("hooks: skipping invalid config", "project", project, "error", err)
continue
}
valid = append(valid, h)
}
return &HookManager{
hooks: valid,
project: project,
shell: shell,
shellFlag: shellFlag,
shellProfile: shellProfile,
client: &http.Client{},
}
}
func validateHookConfig(h HookConfig) error {
if h.Event == "" {
return fmt.Errorf("event is required")
}
switch HookHandlerType(h.Type) {
case HookHandlerCommand:
if h.Command == "" {
return fmt.Errorf("command is required for type=command")
}
case HookHandlerHTTP:
if h.URL == "" {
return fmt.Errorf("url is required for type=http")
}
if !strings.HasPrefix(h.URL, "http://") && !strings.HasPrefix(h.URL, "https://") {
return fmt.Errorf("url must start with http:// or https://")
}
default:
return fmt.Errorf("unknown handler type %q (must be command or http)", h.Type)
}
return nil
}View on GitHub (pinned to 4000b2338a)
Solutions
- Add the `event` key to the hook entry in config.toml (e.g. event = "before_agent")
- Check the field name spelling matches the HookConfig struct's expected key
- Set h.Event programmatically before constructing the HookManager
- Consult the docs for the list of valid hook event names
Example fix
// before (config.toml) [[hooks]] type = "command" command = "/scripts/notify.sh" // after [[hooks]] event = "after_agent" type = "command" command = "/scripts/notify.sh"
Defensive patterns
Strategy: validation
Validate before calling
for i, h := range hooks {
if h.Event == "" {
return fmt.Errorf("hooks[%d]: event is required", i)
}
} Try / catch
mgr, err := NewHookManager(hooks)
if err != nil {
slog.Error("invalid hook config", "err", err)
return fmt.Errorf("hook config: %w", err)
} Prevention
- Always include the `event` key in every [[hooks]] config entry
- Validate hook config at deploy time, not just at daemon start
- Keep a copy-paste-ready hook template in docs
- Strict TOML decoding surfaces misspelled keys — prefer it
When it happens
Trigger: Creating a NewHookManager with a hook entry whose Event field is the empty string — e.g. a [[hooks]] table in config.toml missing the event key, or a programmatically built HookConfig with Event left unset.
Common situations: config.toml hook entry missing the `event` key; typo of the field name so it fails to unmarshal; building hooks in code and forgetting to set Event.
Understand the failure class
Background: "is required", "must be set", "missing required field": configuration validation errors across open-source libraries — this error's family across 36 libraries.
Related errors
- command is required for type=command
- url is required for type=http
- tmux: 'session' option is required (name of the tmux session
- config: relay.visibility must be "full", "summary", or "none
- config: at least one [[projects]] entry is required
AI-assisted analysis of chenhg5/cc-connect@4000b2338a (2026-09-06).
Data as JSON: /api/errors/634894f2505314f0.
Report an issue: GitHub.