Expose hooks safely for automation
Outcome
Enable Carapace hooks endpoints with dedicated hooks auth, then trigger wake/agent actions from external automation.
Prerequisites
carainstalled.ANTHROPIC_API_KEYorOPENAI_API_KEY.curl.
1) Create config
Generate dedicated tokens:
export CARAPACE_GATEWAY_TOKEN="$(openssl rand -hex 32)"
export CARAPACE_HOOKS_TOKEN="$(openssl rand -hex 32)"Windows (PowerShell) alternative:
$bytes = [byte[]]::new(32)
[System.Security.Cryptography.RandomNumberGenerator]::Fill($bytes)
$env:CARAPACE_GATEWAY_TOKEN = [System.BitConverter]::ToString($bytes).Replace('-', '').ToLower()
$bytes = [byte[]]::new(32)
[System.Security.Cryptography.RandomNumberGenerator]::Fill($bytes)
$env:CARAPACE_HOOKS_TOKEN = [System.BitConverter]::ToString($bytes).Replace('-', '').ToLower()Create carapace.json5:
{
"gateway": {
"bind": "loopback",
"port": 18789,
"auth": {
"mode": "token",
"token": "${CARAPACE_GATEWAY_TOKEN}"
},
"hooks": {
"enabled": true,
"token": "${CARAPACE_HOOKS_TOKEN}",
"path": "/hooks"
}
},
"anthropic": {
"apiKey": "${ANTHROPIC_API_KEY}"
}
}
2) Run commands
CARAPACE_CONFIG_PATH=./carapace.json5 caraTrigger wake:
curl -sS \
-H "Authorization: Bearer ${CARAPACE_HOOKS_TOKEN}" \
-H "Content-Type: application/json" \
-X POST http://127.0.0.1:18789/hooks/wake \
-d '{"text":"wake now","mode":"now"}'Dispatch agent:
curl -sS \
-H "Authorization: Bearer ${CARAPACE_HOOKS_TOKEN}" \
-H "Content-Type: application/json" \
-X POST http://127.0.0.1:18789/hooks/agent \
-d '{"message":"Summarize the latest system status in one paragraph."}'3) Verify
/hooks/wakereturns{"ok":true,...}./hooks/agentreturns{"ok":true,"runId":"..."}.- Using service token for hooks fails, proving token separation works.
Common failures and fixes
- Symptom:
401 Unauthorized.- Fix: Use
CARAPACE_HOOKS_TOKENfor hooks endpoints, not service auth token.
- Fix: Use
- Symptom:
404 Not Foundfor hooks path.- Fix: Confirm
gateway.hooks.enabled=trueandgateway.hooks.pathmatches URL.
- Fix: Confirm
- Symptom:
400payload errors.- Fix: Send JSON body and required fields (
textfor wake,messagefor agent).
- Fix: Send JSON body and required fields (