Incident Response
Configure automated incident detection, classification, and response with AI-powered root cause analysis.
Overview
Modern systems generate thousands of alerts daily. Without automation, SRE teams spend most of their time triaging rather than fixing issues. Autohand Code CLI helps by reading alert data, logs and your runbooks, then proposing or carrying out a fix under the permissions you set.
Autohand Code CLI has no dedicated sre command or alert listener. You build incident response from its general pieces:
- Headless runs (
-p) that your alerting system or a script triggers - Piped input, so alert payloads and log excerpts become context
- MCP servers for access to your monitoring and ticketing tools
- Permission controls, run budgets and hooks as guardrails, with a human approving changes
Prerequisites
Before setting up incident response, ensure you have:
- Autohand Code CLI installed and signed in, or configured with a provider API key
- Read access to your monitoring platform (Datadog, PagerDuty, or similar), through its API, CLI or an MCP server
- A runbook repository with documented procedures
# Verify Autohand installation
autohand --version
# List the MCP servers Autohand can use
autohand mcp list
Monitoring integration
Give Autohand access to your monitoring stack in one of two ways.
Pipe the data in. Fetch the alert and the relevant logs with your own tools and pipe them to Autohand. Piped input is added to the prompt as context:
cat alert.json recent-errors.log \
| autohand -p "Triage this alert. Name the likely cause, the affected service, and the runbook in runbooks/ that applies." \
--restricted
Add an MCP server. If your monitoring vendor or a community project provides an MCP server, register it so Autohand can query metrics and logs itself:
# Local (stdio) server. The -- keeps Autohand from reading -y as its own --yes flag
autohand mcp add monitoring -- npx -y <your-monitoring-mcp-package>
# Remote (HTTP) server
autohand mcp add --transport http monitoring https://mcp.example.com/mcp
Keep the credentials those tools need in their own configuration or environment. Autohand has no native Datadog or PagerDuty integration yet; see Datadog.
Incident response flow
A practical flow has four phases. Each is one or more Autohand runs that you or your automation start.
Phase 1: Observation
Your alerting system detects the problem and calls a webhook or script. That script gathers the alert payload, recent logs, and the deploys since the last good state:
git log --since="2 hours ago" --oneline > recent-deploys.txt
Phase 2: Diagnosis
Run a read-only diagnosis. --output-schema makes the answer a JSON document your script can route on:
cat alert.json recent-errors.log recent-deploys.txt \
| autohand --ephemeral -p "Diagnose this incident using the code in this repository and the runbooks in runbooks/." \
--restricted --output-schema diagnosis.schema.json --json local \
| jq -r .content > diagnosis.json
With diagnosis.schema.json asking for, for example, suspect_component, likely_cause, confidence and runbook. If the answer does not match the schema, the command exits with status 1.
Phase 3: Action
Have Autohand prepare the fix as a patch, so a person reviews it before anything changes:
autohand -p "Apply the fix described in diagnosis.json, following runbooks/$(jq -r .runbook diagnosis.json)." \
--disallowed-tools run_command,shell --patch --output incident-fix.patch
Post the diagnosis and patch to your incident channel or ticket for approval. For hands-on work, an engineer can open an interactive session in an isolated worktree with autohand --worktree incident-1234.
Phase 4: Learning
After the incident, ask Autohand to draft the postmortem and update the runbook, then review both like any other change:
cat diagnosis.json incident-timeline.md \
| autohand -p "Write a postmortem in postmortems/ and update the matching runbook with what we learned." \
--disallowed-tools run_command,shell --patch --output postmortem.patch
Safeguards and controls
Automated incident response requires careful guardrails. These CLI controls apply:
- Read-only by default:
--restricteddenies all dangerous operations. Use it for triage and diagnosis. - Review before change:
--patch --outputproduces a patch without changing files, and--dry-runpreviews actions without applying them. Patch mode approves tool calls automatically, so the examples add--disallowed-tools run_command,shellto keep it from running commands. - Command limits:
permissions.denyListin the config blocks commands outright, for example"run_command:kubectl delete:*"plus"shell:kubectl delete:*"for theshelltool.--allowed-toolsand--disallowed-toolslimit tools for one run. - Run budgets:
--max-duration,--max-requestsand--max-tokensstop a run that goes on too long. - Audit: a
post-toolorfile-modifiedhook records each action, and--output-format stream-jsoncaptures every tool event. Hooks do not run with--bare.
Write runbooks as plain Markdown in the repository so both people and Autohand can read them:
# runbooks/high-cpu.md
Trigger: system.cpu.user above 90% for 5 minutes.
1. List the top processes and compare with the last deploy.
2. If a deploy in the last hour matches, propose a rollback.
3. Scale out by at most 2x. Never scale down during an incident.
4. Wait 10 minutes before taking a second action.
Deployment options
Autohand runs wherever your incident automation runs:
- On-call workstation: an engineer runs the commands above, or an interactive session, during the incident
- CI job: your alerting system triggers a pipeline (for example GitHub Actions
workflow_dispatch) that runs the diagnosis step with--bare - Container: a small service receives the alert webhook and runs
autohand --bare -p; see Run Autohand on Cloudflare Containers
In CI and containers, --bare reads credentials from AUTOHAND_PROVIDER, AUTOHAND_API_KEY and AUTOHAND_AI_API_KEY. See Headless mode.
Testing your setup
Replay a past alert through the flow with nothing applied:
# Diagnose a saved alert, read-only
cat fixtures/high-cpu-alert.json \
| autohand --ephemeral -p "Diagnose this incident using runbooks/." --restricted
# Preview the actions a fix would take, without applying them
cat fixtures/high-cpu-alert.json \
| autohand --ephemeral -p "Follow runbooks/high-cpu.md for this alert." --dry-run
Always test runbooks in a staging environment before enabling production automation.