Skip to content

osodevops/slack-cli

Repository files navigation

slk

An agentic Slack CLI with structured JSON output and 200+ API methods — purpose-built for AI agents, LLMs, and DevOps automation.

Send messages, manage channels, search, upload files, and automate Slack from your terminal or agent toolchain. Ships as a single static binary (<15 MB) with structured { ok, data, meta } JSON envelope, non-interactive execution, idempotent writes, and slk schema for runtime tool discovery.

CI Release License: MIT

Install

# Homebrew (macOS/Linux)
brew install osodevops/tap/slk

# Shell installer (macOS/Linux)
curl -fsSL https://raw.githubusercontent.com/osodevops/slack-cli/main/install.sh | sh

# PowerShell (Windows)
irm https://raw.githubusercontent.com/osodevops/slack-cli/main/install.ps1 | iex

# Pre-built binaries — download from GitHub Releases
# https://github.com/osodevops/slack-cli/releases

# Docker
docker run --rm -e SLK_TOKEN ghcr.io/osodevops/slk channel list

# From source
cargo install --git https://github.com/osodevops/slack-cli

Setup

Store a bot token (from your Slack app settings):

slk auth add myworkspace --token xoxb-your-bot-token
# Credentials stored in OS keychain
# You're ready to go! Try: slk channel list

Or set it as an environment variable:

export SLK_TOKEN=xoxb-your-bot-token

For cookie-based auth (xoxc + xoxd), extract directly from the Slack desktop app:

slk auth extract
# Reads token from Slack's LevelDB and decrypts cookies from Chromium DB

Quick Start

# Send a message
slk msg send C123 "Hello from slk!" --yes

# List channels
slk channel list -o json

# Get channel history
slk msg history C123 -n 20 --fields ts,text,user

# Reply in a thread
slk msg reply C123 1234567890.123456 "Thread reply" --yes

# Search messages
slk search messages "deploy failure" --from U456

# React to a message
slk react add C123 1234567890.123456 thumbsup --yes

# Get user info
slk user info U456 -o json --fields id,real_name,email

# Upload a file
slk file upload report.pdf --channels C123 --title "Q4 Report" --yes

Messages

# Plain text
slk msg send C123 "Hello world" --yes

# Block Kit templates (deploy, incident, approval, pr)
slk msg send C123 "Deploy" --template deploy --var app=api --var env=prod --yes

# Block Kit JSON from file
slk msg send C123 "Custom blocks" --blocks-file blocks.json --yes

# Edit a message
slk msg edit C123 1234567890.123456 "Updated text" --yes

# Delete a message
slk msg delete C123 1234567890.123456 --yes

# Schedule a message
slk msg schedule send C123 "Good morning" --post-at 1700000000 --yes

# Ephemeral message (visible to one user)
slk msg ephemeral C123 U456 "Only you can see this" --yes

# Get a permalink
slk msg permalink C123 1234567890.123456

# Save a draft (requires cookie auth)
slk msg draft C123 "WIP message" --yes

Channel Export

# Export full channel history to NDJSON
slk msg export C123

# With thread replies and human-like pacing
slk msg export C123 --threads --pace slow -f backup.ndjson

# JSON array format
slk msg export C123 --format json -f archive.json

# Resume an interrupted export
slk msg export C123 --resume

# Export with stealth pacing (2-8s random delays)
slk msg export C123 --threads --pace stealth

Channels

# List all channels
slk ch list -o json --fields id,name,num_members

# Filter by type
slk ch list --types public_channel,private_channel

# Create a channel
slk ch create my-project --yes

# Set topic and purpose
slk ch topic C123 "Sprint 42 discussion" --yes
slk ch purpose C123 "Coordinate sprint work" --yes

# Manage members
slk ch members C123 -n 500 -o json
slk ch invite C123 --users U456,U789 --yes
slk ch kick C123 U456 --yes

Search

# Search messages
slk search messages "budget" --after 2025-01-01 --sort timestamp

# Search with sender filter
slk search messages "deploy" --from U456 -o json

# Search files
slk search files "report" --in-channel C123

# Search users and channels
slk search users "alice"
slk search channels "engineering"

Files

# Upload with comment
slk file upload screenshot.png --channels C123 --comment "Bug screenshot" --yes

# List files in a channel
slk file list --channel C123 -n 10 -o json

# Download a file
slk file download F456 -o ./downloads/

# Delete a file
slk file delete F456 --yes

Auth Parse-Curl

# Extract tokens from a browser DevTools curl command
slk auth parse-curl --from-clipboard --login

# Pipe from clipboard
pbpaste | slk auth parse-curl --login --workspace mycompany

# Pass directly
slk auth parse-curl "curl 'https://myco.slack.com/api/...' -H 'Cookie: d=xoxd-...' --data 'token=xoxc-...'" --login

Socket Mode Events

# Listen for real-time events
slk events listen --app-token xapp-your-app-token

# Filter by event type
slk ev listen --app-token xapp-... --types message,reaction_added

# Filter by channel
slk ev listen --app-token xapp-... --channels C123,C456

# Pipe to a processor
slk ev listen --app-token xapp-... | jq '.event'

Schema Introspection

# Full command tree as JSON (for agent tool discovery)
slk schema

# Single command details
slk schema --command msg.send

# API method registry with rate limit tiers
slk schema --methods

Human-Like Pacing

# Add random delays between API calls
slk msg history C123 --pace stealth      # 2-8s random delays
slk ch list --pace normal                # 0.5-2s delays
slk msg export C123 --pace slow          # 1-4s delays

# Custom delay range
slk ch list --pace-min-ms 1000 --pace-max-ms 5000

Use Cases

OpenClaw / AI Agents

slk is purpose-built for AI agents that need to interact with Slack. Every command outputs structured JSON, requires no interactive prompts, and supports safe-by-default write protection — making it ideal for autonomous agent workflows.

# Agent reads channel history, processes it, and responds
slk msg history C123 -n 10 -o json --fields ts,text,user | agent-process
slk msg send C123 "$(agent-generate-response)" --yes --idempotency-key $(uuidgen)

# Agent discovers available commands at runtime
slk schema                           # Full command tree as JSON
slk schema --methods                 # API method → CLI mapping with rate tiers

# Agent monitors events in real time
slk ev listen --app-token xapp-... --types message | agent-event-handler

# Agent exports channel for analysis with human-like pacing
slk msg export C123 --threads --pace stealth -f data.ndjson

# Dry-run to validate before executing
slk msg send C123 "Deploy notification" --dry-run

Why slk for agents:

  • Structured output — JSON envelope with { ok, data, meta } on stdout, logs on stderr
  • Non-interactive — all input via args, env vars, or stdin — no prompts
  • Safe by default — writes require --yes or SLK_ALLOW_WRITE=true
  • Idempotent--idempotency-key for safe retries on write operations
  • Introspectableslk schema emits full JSON command tree for tool discovery
  • Context-efficient--fields projection reduces token usage for LLM context
  • Exit codes — deterministic codes (0-7) for programmatic error handling

DevOps & CI/CD

# Post deploy notifications with Block Kit
slk msg send C123 --template deploy --var app=api --var version=v1.2.3 --var env=prod --yes

# Incident alerts
slk msg send C123 --template incident --var title="DB outage" --var severity=high --yes

# Notify on PR merge
slk msg send C123 --template pr --var title="Add caching" --var repo=myapp --yes

# Scheduled reminders
slk msg schedule send C123 "Deploy window closes in 1 hour" --post-at 1700000000 --yes

Compliance & Archival

# Export full channel history for compliance
slk msg export C123 --threads --pace slow -f compliance-export.ndjson

# Export with date range
slk msg export C123 --oldest 1700000000 --latest 1710000000 -f q4-archive.ndjson

# Resume interrupted exports
slk msg export C123 --resume

Workspace Administration

# Audit channel membership
slk ch members C123 -n 1000 -o json | jq '.[].id'

# Bulk user lookup
slk user list --include-bots -o json --fields id,real_name,is_bot

# Manage user groups
slk usergroup members S0614TZR7 -o json
slk usergroup members-set S0614TZR7 --users U1,U2,U3 --yes

Features

  • 200+ Slack API methods — messages, channels, files, reactions, search, users, pins, stars, bookmarks, reminders, status, DND, user groups, canvases
  • Built for AI agents — structured JSON, non-interactive, idempotent, safe-by-default, introspectable via slk schema
  • Human-like pacing — configurable random delays between API calls (none/fast/normal/slow/stealth)
  • Channel export — stream full channel history to NDJSON/JSON with thread fetching and resume
  • Block Kit templates — deploy, incident, approval, and PR notification templates built in
  • Five auth methods — app extraction, browser login, parse-curl, OAuth PKCE, direct token
  • Socket Mode — real-time event streaming via WebSocket
  • Dry-run mode — preview API calls without executing
  • Multiple output formatsjson (default), yaml, text, table, ndjson
  • Field projection--fields ts,text,user to select only needed data
  • Rate limit handling — automatic retry with exponential backoff on 429
  • Multi-workspace — named profiles with credential storage in OS keychain
  • Schema introspectionslk schema emits full JSON command tree for agent tool discovery
  • Shell completions — bash, zsh, fish, PowerShell
  • Man pagesslk docs --man-pages ./man/ generates 111 man pages
  • Cross-platform — macOS (Apple Silicon + Intel), Linux (x86_64 + ARM64), Windows
  • Zero runtime dependencies — single statically-linked binary (<15 MB)

Authentication

slk supports five authentication methods. Credentials are resolved in priority order:

  1. CLI flags (--token / --cookie) or env vars (SLK_TOKEN / SLK_COOKIE)
  2. Stored credentials for the active workspace (OS keychain)

Bot / User Token (simplest)

export SLK_TOKEN=xoxb-your-bot-token

# Or store persistently
slk auth add myworkspace --token xoxb-your-bot-token

# Read from a secret manager
vault read -field=token secret/slack | slk auth add myworkspace --token-stdin

Slack Desktop App Extraction

slk auth extract                        # From Slack app (default)
slk auth extract --source chrome        # From Chrome
slk auth extract --source firefox       # From Firefox
slk auth extract --list                 # Show available workspaces

Reads the xoxc- token from Slack's LevelDB and decrypts the xoxd- cookie from the Chromium cookie database using the OS keychain password (macOS Keychain / GNOME Keyring).

Browser DevTools (parse-curl)

slk auth parse-curl --from-clipboard --login

Copy a Slack API request as cURL from browser DevTools, then paste. Extracts xoxc- token and xoxd- cookie automatically.

Interactive Browser Login

slk auth login myworkspace.slack.com
slk auth login myworkspace --headless

Opens a Chromium window via CDP. Supports SSO, SAML, and 2FA.

OAuth 2.0 PKCE

slk auth oauth --client-id 12345.67890 --scopes chat:write,channels:read

Workspace Management

slk auth list                    # List configured workspaces
slk auth status                  # Validate current credentials
slk auth switch production       # Switch active workspace
slk auth logout old-workspace    # Remove credentials

Platform Support

Feature macOS Linux Windows
Slack app extraction Yes Yes Yes
Cookie decryption Yes (Keychain) Yes (GNOME Keyring) Not yet (DPAPI)
Chrome/Edge extraction Yes Yes Not yet
Firefox extraction Yes Yes Not yet
Browser login (CDP) Yes Yes Yes
OAuth 2.0 PKCE Yes Yes Yes
Bot/user token Yes Yes Yes
Keyring storage Keychain Secret Service Credential Manager

Configuration

~/.config/slk/config.toml:

[default]
workspace = "myworkspace"
output = "json"
default_pace = "normal"
user_agent = "Mozilla/5.0 ..."

[workspaces.myworkspace]
token_type = "bot"
team_id = "T12345"

Environment Variables

Variable Description
SLK_TOKEN Slack API token (xoxb-, xoxp-, xoxc-)
SLK_COOKIE Cookie value (xoxd-) for xoxc- token auth
SLK_WORKSPACE Default workspace name
SLK_OUTPUT Default output format (json, yaml, text, table, ndjson)
SLK_ALLOW_WRITE Set to true to enable writes without --yes
SLK_CONFIG_DIR Custom config directory (default: ~/.config/slk/)
SLK_API_BASE_URL Override Slack API base URL (for testing)
SLK_APP_TOKEN App-level token (xapp-) for Socket Mode

Output

Every command returns a structured envelope on stdout:

{
  "ok": true,
  "data": { "channel": "C123", "ts": "1234567890.123456" },
  "meta": { "method": "chat.postMessage", "workspace": "myworkspace" }
}
# JSON (default, best for agents)
slk ch list -o json

# YAML
slk ch list -o yaml

# ASCII table (human-friendly)
slk ch list -o table

# Plain text
slk user info U456 -o text

# NDJSON (one JSON object per line, good for streaming)
slk ch list -o ndjson

# Raw Slack API response (no envelope)
slk ch list --raw

# Field projection
slk ch list -o json --fields id,name,num_members

Exit Codes

Code Meaning
0 Success
1 Slack API error (check .data.error)
2 Authentication error
3 Rate limited (retry with backoff)
4 Network / WebSocket error
5 Configuration error
6 Write denied (missing --yes or SLK_ALLOW_WRITE)
7 Validation error (bad arguments)
130 Interrupted (SIGINT)

CLI Reference

slk [OPTIONS] <COMMAND>

Commands:
  auth         Authentication management (extract, login, add, oauth, parse-curl)
  message      Send, reply, edit, delete, schedule, export messages  [alias: msg]
  channel      List, create, archive, rename, manage channels       [alias: ch]
  file         Upload, download, list, delete files
  reaction     Add, remove, list emoji reactions                     [alias: react]
  search       Search messages, files, users, channels
  user         User info, list, presence, lookup
  pin          Pin and unpin messages
  star         Star and unstar items
  bookmark     Manage channel bookmarks
  reminder     Create and manage reminders
  status       Set and manage user status
  dnd          Do Not Disturb settings
  usergroup    Manage user groups and memberships
  canvas       Create and manage canvases
  api          Call any Slack API method directly
  schema       Introspect CLI commands and API methods (JSON)
  events       Real-time event streaming via Socket Mode             [alias: ev]
  completions  Generate shell completions (bash/zsh/fish/powershell)
  docs         Generate man pages and documentation

Global Options:
  -w, --workspace <NAME>      Target workspace (overrides SLK_WORKSPACE)
  -o, --output <FORMAT>       Output format: json, yaml, text, table, ndjson
      --raw                   Raw API response without envelope
      --fields <FIELDS>       Comma-separated fields to include
  -q, --quiet                 Suppress output except errors
  -v, --verbose               Enable debug logging (to stderr)
      --yes                   Skip confirmation prompts (required for writes)
      --dry-run               Show what would happen without executing

Auth Options:
      --token <TOKEN>         Slack API token (xoxb-, xoxp-, xoxc-)
      --cookie <COOKIE>       Cookie (xoxd-) for xoxc- token auth

Retry Options:
      --retry <N>             Max retry attempts [default: 3]
      --no-retry              Disable automatic retries
      --timeout <SECS>        Request timeout in seconds [default: 30]
      --idempotency-key <K>   Idempotency key for write operations

Pacing Options:
      --pace <PROFILE>        none, fast, normal, slow, stealth
      --pace-min-ms <MS>      Custom minimum delay (overrides profile)
      --pace-max-ms <MS>      Custom maximum delay (overrides profile)
      --user-agent <STRING>   Custom User-Agent header

Building from Source

git clone https://github.com/osodevops/slack-cli
cd slack-cli
cargo build --release
# Binary at target/release/slk

Requirements: Rust 1.75+

# Run tests
cargo test

# Lint
cargo clippy --all-targets -- -D warnings

# Generate man pages
cargo run -- docs --man-pages docs/man

# Generate shell completions
cargo run -- completions zsh > ~/.zfunc/_slk

Roadmap

  • Phase 1: Core — CLI scaffold, HTTP client, auth system (5 methods), output formatting, rate limiting
  • Phase 2: Essential — messages, channels, files, reactions, search, users
  • Phase 3: Extended — pins, stars, bookmarks, reminders, status, DND, user groups, canvases
  • Phase 4: Advanced — Socket Mode events, Block Kit templates, schema introspection
  • Phase 5: Polish — integration tests (63), cross-platform builds (5 targets), Docker, Homebrew, release workflow
  • Phase 6: Human-Like — pacing system, channel export, parse-curl auth, message drafts, man pages, agent-optimized help

License

MIT

About

Agentic Slack CLI with structured JSON output and 200+ API methods — built for AI agents, LLMs, and DevOps automation

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages