slackctl

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Slack automation with
slackctl

借助
slackctl
实现Slack自动化

slackctl
is a single-binary CLI on
$PATH
. Invoke directly (e.g.
slackctl user get @alice
).
slackctl
是一款可加入
$PATH
的单二进制CLI工具。可直接调用(例如:
slackctl user get @alice
)。

Installation

安装

If
slackctl
is not found on
$PATH
, install it:
  • brew tap cluas/tap && brew install slackctl
    (macOS/Linux, recommended)
  • go install github.com/cluas/slackctl/cmd/slackctl@latest
    (requires Go)
如果
$PATH
中未找到
slackctl
,请按以下方式安装:
  • brew tap cluas/tap && brew install slackctl
    (macOS/Linux,推荐方式)
  • go install github.com/cluas/slackctl/cmd/slackctl@latest
    (需要安装Go环境)

CRITICAL: Bash command formatting rules

重要提示:Bash命令格式规则

Claude Code's permission checker has security heuristics that force manual approval prompts. Avoid these patterns to keep commands auto-allowed.
  1. No
    #
    anywhere in the command string.
    Use bare channel names (
    general
    not
    #general
    ).
  2. No
    ''
    (consecutive single quotes) or
    ""
    (consecutive double quotes).
    Triggers "potential obfuscation" check.
  3. Only
    | jq
    for filtering — no python3, no other commands.
    jq
    with single-quote-only expressions (no
    "
    inside) is safe:
    • RIGHT:
      slackctl search messages "query" | jq '.messages[] | .ts'
  4. No
    ||
    or
    &&
    chains.
    Run multiple slackctl commands as separate Bash tool calls.
  5. No file redirects (
    >
    ,
    >>
    ).
    Process JSON output directly, don't write to files.
Claude Code的权限检查器带有安全启发式规则,会触发手动审批提示。请避免以下模式,确保命令可自动通过审批。
  1. 命令字符串中不得包含
    #
    。请使用纯频道名称(如
    general
    而非
    #general
    )。
  2. 不得包含连续单引号
    ''
    或连续双引号
    ""
    。这会触发“潜在混淆”检查。
  3. 仅允许使用
    | jq
    进行过滤——禁止使用python3或其他命令
    。仅使用单引号表达式的
    jq
    是安全的:
    • 正确示例:
      slackctl search messages "query" | jq '.messages[] | .ts'
  4. 不得使用
    ||
    &&
    链式命令
    。请将多个slackctl命令作为独立的Bash工具调用执行。
  5. 不得使用文件重定向符
    >
    >>
    。请直接处理JSON输出,不要写入文件。

Quick start (auth)

快速开始(认证)

Authentication is automatic on macOS (Slack Desktop first, then Chrome/Firefox fallbacks).
If credentials aren't available, run one of:
  • Slack Desktop import (macOS):
bash
slackctl auth import-desktop
slackctl auth test
  • Firefox fallback:
bash
slackctl auth import-firefox
slackctl auth test
  • Chrome fallback:
bash
slackctl auth import-chrome
slackctl auth test
  • Or set env vars:
bash
export SLACK_TOKEN="xoxc-..."
export SLACK_COOKIE_D="xoxd-..."
export SLACK_WORKSPACE_URL="https://myteam.slack.com"
slackctl auth test
  • Or add manually:
bash
slackctl auth add --workspace-url https://myteam.slack.com --xoxc xoxc-... --xoxd xoxd-...
slackctl auth test
Check configured workspaces:
bash
slackctl auth whoami
在macOS上认证是自动完成的(优先使用Slack Desktop,其次是Chrome/Firefox作为备选)。
如果无法获取凭证,请运行以下其中一种方式:
  • 从Slack Desktop导入(macOS):
bash
slackctl auth import-desktop
slackctl auth test
  • Firefox备选方案:
bash
slackctl auth import-firefox
slackctl auth test
  • Chrome备选方案:
bash
slackctl auth import-chrome
slackctl auth test
  • 或设置环境变量:
bash
export SLACK_TOKEN="xoxc-..."
export SLACK_COOKIE_D="xoxd-..."
export SLACK_WORKSPACE_URL="https://myteam.slack.com"
slackctl auth test
  • 或手动添加:
bash
slackctl auth add --workspace-url https://myteam.slack.com --xoxc xoxc-... --xoxd xoxd-...
slackctl auth test
查看已配置的工作区:
bash
slackctl auth whoami

Canonical workflow (given a Slack message URL)

标准工作流(给定Slack消息URL)

  1. Fetch a single message:
bash
slackctl message get "https://workspace.slack.com/archives/C123/p1700000000000000"
  1. If you need the full thread:
bash
slackctl message list "https://workspace.slack.com/archives/C123/p1700000000000000" --thread-ts 1700000000.000000
  1. 获取单条消息:
bash
slackctl message get "https://workspace.slack.com/archives/C123/p1700000000000000"
  1. 如果需要完整线程:
bash
slackctl message list "https://workspace.slack.com/archives/C123/p1700000000000000" --thread-ts 1700000000.000000

Browse recent channel messages

浏览频道近期消息

bash
slackctl message list "general" --limit 20
slackctl message list "C0123ABC" --limit 10
bash
slackctl message list "general" --limit 20
slackctl message list "C0123ABC" --limit 10

Get unread messages

获取未读消息

List all channels with unread messages:
bash
slackctl message unread --limit 20
Also fetch the actual unread message content:
bash
slackctl message unread --fetch --max-per-channel 5
Note: For Enterprise Grid, use
--workspace
with the enterprise URL for unread counts:
bash
slackctl message unread --workspace longbridge-group --fetch
列出包含未读消息的所有频道:
bash
slackctl message unread --limit 20
同时获取实际未读消息内容:
bash
slackctl message unread --fetch --max-per-channel 5
注意:对于Enterprise Grid,需使用
--workspace
参数指定企业URL以获取未读计数:
bash
slackctl message unread --workspace longbridge-group --fetch

Send, edit, delete, or react

发送、编辑、删除消息或添加/移除反应

bash
slackctl message send "general" "here is the report"
slackctl message send U01AAAA "hello via DM"
slackctl message send "general" "threaded reply" --thread-ts 1700000000.000000
slackctl message edit "general" 1700000000.000000 "updated text"
slackctl message delete "general" 1700000000.000000
slackctl message react add "general" 1700000000.000000 "eyes"
slackctl message react remove "general" 1700000000.000000 "eyes"
Send to a user ID opens a DM automatically.
bash
slackctl message send "general" "here is the report"
slackctl message send U01AAAA "hello via DM"
slackctl message send "general" "threaded reply" --thread-ts 1700000000.000000
slackctl message edit "general" 1700000000.000000 "updated text"
slackctl message delete "general" 1700000000.000000
slackctl message react add "general" 1700000000.000000 "eyes"
slackctl message react remove "general" 1700000000.000000 "eyes"
向用户ID发送消息会自动打开私信。

List channels + create/invite

列出频道 + 创建/邀请用户

bash
slackctl channel list
slackctl channel list --limit 50
slackctl channel new "incident-war-room"
slackctl channel new "incident-leads" --private
slackctl channel invite "incident-war-room" "U01AAAA,U02BBBB"
bash
slackctl channel list
slackctl channel list --limit 50
slackctl channel new "incident-war-room"
slackctl channel new "incident-leads" --private
slackctl channel invite "incident-war-room" "U01AAAA,U02BBBB"

Search (messages + files)

搜索(消息+文件)

bash
slackctl search messages "deploy failed" --limit 10
slackctl search files "report" --limit 5
bash
slackctl search messages "deploy failed" --limit 10
slackctl search files "report" --limit 5

Mark as read

标记为已读

bash
slackctl channel mark "general" 1700000000.000000
bash
slackctl channel mark "general" 1700000000.000000

Canvas

Canvas功能

Fetch a Slack canvas and convert to Markdown:
bash
slackctl canvas get "https://workspace.slack.com/docs/T123/F456"
slackctl canvas get F0123ABCDEF
获取Slack canvas并转换为Markdown格式:
bash
slackctl canvas get "https://workspace.slack.com/docs/T123/F456"
slackctl canvas get F0123ABCDEF

Users

用户管理

bash
slackctl user list --limit 100
slackctl user get "@alice"
slackctl user get U01AAAA
bash
slackctl user list --limit 100
slackctl user get "@alice"
slackctl user get U01AAAA

Multi-workspace

多工作区支持

If you have multiple workspaces, pass
--workspace
to disambiguate:
bash
slackctl message list "general" --workspace "myteam" --limit 10
slackctl auth set-default https://myteam.slack.com
如果您有多个工作区,请传递
--workspace
参数以明确指定:
bash
slackctl message list "general" --workspace "myteam" --limit 10
slackctl auth set-default https://myteam.slack.com

All output is JSON

所有输出均为JSON格式

All commands output JSON to stdout. Use
| jq
for filtering:
bash
slackctl user get U01AAAA | jq '.email'
slackctl message list "general" --limit 5 | jq '.[].text'
所有命令均向标准输出(stdout)输出JSON。可使用
| jq
进行过滤:
bash
slackctl user get U01AAAA | jq '.email'
slackctl message list "general" --limit 5 | jq '.[].text'

References

参考文档

  • references/commands.md: full command map + all flags
  • references/targets.md: URL vs channel targeting rules
  • references/output.md: JSON output shapes
  • references/commands.md:完整命令映射及所有参数
  • references/targets.md:URL与频道定位规则
  • references/output.md:JSON输出结构