chenhg5/cc-connect · error

command is required for type=command

Error message

command is required for type=command

What it means

validateHookConfig requires a Command for hooks whose handler type is "command". A command-type hook executes a shell command when its event fires; without a command there is nothing to run, so the configuration is rejected.

Source

Thrown at core/hooks.go:114

	}
	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
}

// Emit dispatches an event to all matching hooks.
func (hm *HookManager) Emit(event HookEvent) {
	if hm == nil {
		return

View on GitHub (pinned to 4000b2338a)

Solutions

  1. Add the `command` key with the executable to run for this hook
  2. Fix the field name spelling (must be `command`, not `cmd`)
  3. Uncomment or restore the command line that was removed
  4. Change type to "http" with a url if you intended an HTTP hook instead

Example fix

// before (config.toml)
[[hooks]]
event = "before_agent"
type = "command"
// after
[[hooks]]
event = "before_agent"
type = "command"
command = "/usr/local/bin/audit-hook.sh"
Defensive patterns

Strategy: validation

Validate before calling

for i, h := range hooks {
    if h.Type == "command" && h.Command == "" {
        return fmt.Errorf("hooks[%d]: command required for type=command", 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

When it happens

Trigger: NewHookManager receives a hook with Type == "command" and an empty Command field — e.g. a [[hooks]] config entry with type = "command" but no command key.

Common situations: Config entry has type = "command" but the command line was omitted or commented out; field misspelled (e.g. `cmd` instead of `command`); converting an http hook to command type without filling in the command.

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


AI-assisted analysis of chenhg5/cc-connect@4000b2338a (2026-09-06). Data as JSON: /api/errors/6a2f10aa1d8b7601. Report an issue: GitHub.