npx humanlayer contact_human

The contact_human command allows you to send a message to a human through your configured contact channels (Slack, email) and wait for their response. This is useful for getting human input, approvals, or feedback directly from the command line.

Usage

npx humanlayer contact_human <message> [options]

Arguments

ArgumentDescriptionRequired
<message>The message to send to the human. Use - to read from stdinYes

Options

General Options

FlagDescriptionDefault
--config-file <path>Path to config file~/.config/humanlayer/humanlayer.json

Slack Options

FlagDescriptionDefault
--slack-channel <id>Slack channel or user ID-
--slack-bot-token <token>Slack bot token-
--slack-context <context>Context about the Slack channel/user-
--slack-thread-ts <ts>Slack thread timestamp-
--slack-blocks [boolean]Use experimental Slack blockstrue

Email Options

FlagDescriptionDefault
--email-address <email>Email address to contact-
--email-context <context>Context about the email recipient-

Examples

Basic Usage

npx humanlayer contact_human "Should we proceed with the deployment?"

Reading from Stdin

echo "Review this code change" | npx humanlayer contact_human -

With Slack Configuration

npx humanlayer contact_human "Approve marketing campaign" \
  --slack-channel C123456789 \
  --slack-context "marketing team"

With Email Configuration

npx humanlayer contact_human "Need approval for budget increase" \
  --email-address manager@company.com \
  --email-context "Finance Manager"

Using Environment Variables

export HUMANLAYER_SLACK_CHANNEL=C123456789
export HUMANLAYER_SLACK_BOT_TOKEN=xoxb-your-bot-token
npx humanlayer contact_human "Quick question about the project"

Interactive Flow

$ npx humanlayer contact_human "Should we deploy to production?"
Contacting human...
Human response received
Yes, proceed with the deployment. Make sure to monitor the metrics closely.

Input Methods

Direct Message

Pass the message directly as an argument:

npx humanlayer contact_human "Your message here"

From Stdin

Use - to read the message from stdin, useful for piping:

cat message.txt | npx humanlayer contact_human -
echo "Dynamic message" | npx humanlayer contact_human -

Configuration

Required Configuration

You must configure at least one contact channel:

Slack Channel:

  • Channel/User ID: --slack-channel or HUMANLAYER_SLACK_CHANNEL
  • Bot Token: --slack-bot-token or HUMANLAYER_SLACK_BOT_TOKEN

Email:

  • Email Address: --email-address or HUMANLAYER_EMAIL_ADDRESS

Optional Configuration

  • Context about recipient: --slack-context / --email-context
  • Slack thread: --slack-thread-ts
  • Slack blocks: --slack-blocks

Response Handling

The command will:

  1. Send your message through the configured channel
  2. Wait for a human response
  3. Output the response to stdout
  4. Exit with code 0 on success

Error messages are sent to stderr, so you can capture just the human response:

response=$(npx humanlayer contact_human "Question?" 2>/dev/null)
echo "Human said: $response"

Error Handling

No Contact Channel Configured

$ npx humanlayer contact_human "test"
Error: No contact channel configured. Please specify --slack-channel, --email-address, or use environment variables/config file.

Invalid Configuration

The command will validate your configuration and provide helpful error messages for:

  • Missing API tokens
  • Invalid channel IDs
  • Network connectivity issues

Integration Examples

In Shell Scripts

#!/bin/bash
if npx humanlayer contact_human "Deploy to production?" 2>/dev/null | grep -i "yes"; then
    echo "Deployment approved, proceeding..."
    ./deploy.sh
else
    echo "Deployment not approved"
    exit 1
fi

With Git Hooks

# Pre-push hook
if [ "$remote_url" = "production" ]; then
    response=$(npx humanlayer contact_human "Push to production?" 2>/dev/null)
    if ! echo "$response" | grep -i "yes"; then
        echo "Push cancelled by human"
        exit 1
    fi
fi

Best Practices

  1. Clear messages: Be specific about what you’re asking
  2. Provide context: Use --slack-context or --email-context to help humans understand
  3. Error handling: Always check the exit code and handle failures
  4. Timeouts: Be aware that humans may take time to respond
  5. Automation: Use environment variables or config files for repeated usage