Skip to content

postcli/slack

Repository files navigation

postcli slack

@postcli/slack

Your entire Slack, from the terminal.

Browse channels. Post messages. React. Search. Power AI agents.

npm version CI license node MCP issues


Getting StartedCLIMCP ServerAPIContributing


Why @postcli/slack?

Slack's official API requires bot tokens, OAuth apps, and admin approval. PostCLI Slack works like the web client: it grabs your session from the Slack desktop app and talks directly to the same endpoints your browser uses. No bots, no apps, no admin.

CLI

Full command suite for channels, messages, threads, search, reactions, and status. Pipe-friendly --json output.

MCP Server

16 tools for Claude, GPT, and any MCP-compatible AI agent. Read, write, react, and search through natural language.

Multi-workspace

Auto-detects all workspaces from your Slack desktop app. Switch between them seamlessly.

Getting Started

Prerequisites

  • Node.js 18+ (LTS recommended)
  • Slack desktop app logged into your workspace(s)
  • macOS or Linux

Install

npm install -g @postcli/slack

Authenticate

PostCLI grabs session tokens directly from the Slack desktop app (Flatpak, native, or snap):

postcli-slack auth login

It auto-detects your workspaces:

Found 4 token(s). Detecting workspaces...
  Apache Airflow Community (@andre451)
  Building AI Together by Union.ai (@andre259)
  Provero (@andre)
  Apache Hamilton Open Source (@andre)

Connected as andre451 in workspace Apache Airflow Community
Credentials saved to .env

Alternative: manual token paste from browser DevTools with postcli-slack auth setup.

Verify

postcli-slack auth test
# Connected as andre451 in workspace Apache Airflow Community

CLI

Read

postcli-slack channels list                           # list channels
postcli-slack channels info general                   # channel details
postcli-slack messages history general --limit 20     # message history
postcli-slack messages thread general 1234567890.123  # read a thread
postcli-slack users list                              # list users
postcli-slack users info kumare3                      # user details
postcli-slack search messages "from:kumare3"          # search messages

Write

postcli-slack post send general "Hello from the terminal"     # post a message
postcli-slack post reply general 1234.5678 "Good point"       # reply in thread
postcli-slack post edit general 1234.5678 "Updated text"      # edit message
postcli-slack post delete general 1234.5678                   # delete message

React

postcli-slack post react general 1234.5678 thumbsup    # add reaction
postcli-slack post unreact general 1234.5678 thumbsup   # remove reaction
postcli-slack post pin general 1234.5678                # pin message
postcli-slack post star general 1234.5678               # star message

Status

postcli-slack status set "In a meeting" -e ":calendar:"    # set status
postcli-slack status set "BRB" -d 30                       # auto-clear in 30min
postcli-slack status clear                                 # clear status
postcli-slack status away                                  # set away
postcli-slack status active                                # set active

JSON output

Every command supports --json for piping and scripting:

postcli-slack channels list --json | jq '.[].name'
postcli-slack search messages "deploy" --json | jq '.messages[].text'

MCP Server

Connect your Slack to Claude, GPT, or any AI agent via the Model Context Protocol.

Start the server

postcli-slack --mcp

Claude Code

Add to .claude/settings.json:

{
  "mcpServers": {
    "slack": {
      "command": "postcli-slack",
      "args": ["--mcp"]
    }
  }
}

Claude Desktop

Add to claude_desktop_config.json:

{
  "mcpServers": {
    "slack": {
      "command": "postcli-slack",
      "args": ["--mcp"]
    }
  }
}

Available tools (16)

Tool Description
test_connection Test authentication
list_channels List workspace channels
get_messages Message history from a channel
get_thread All replies in a thread
list_users List workspace users
get_user User details by ID or username
search_messages Search across channels
post_message Post a message
reply_to_thread Reply in a thread
edit_message Edit a message
delete_message Delete a message
add_reaction React with emoji
remove_reaction Remove a reaction
set_status Set your status
pin_message Pin a message
mark_read Mark channel as read

Programmatic API

Use the client in your own Node.js projects:

import { SlackClient } from '@postcli/slack/client';

const client = new SlackClient({
  token: process.env.SLACK_TOKEN,
  cookie: process.env.SLACK_COOKIE,
  workspace: 'slack',
});

// Read
const channels = await client.listChannels();
const messages = await client.getMessages('C01234ABCD', { limit: 10 });
const thread = await client.getThread('C01234ABCD', '1234567890.123456');
const results = await client.searchMessages('from:kumare3');

// Write
await client.postMessage('C01234ABCD', 'Hello from API');
await client.replyToThread('C01234ABCD', '1234.5678', 'Great point');
await client.addReaction('C01234ABCD', '1234.5678', 'thumbsup');
await client.setStatus('Coding', ':computer:');

Project Structure

src/
  cli/
    commands/         # auth, channels, messages, users, search, post, status
    chrome-cookies.ts # Slack desktop cookie + token extraction
  lib/
    slack.ts          # SlackClient (core API wrapper)
    http.ts           # HTTP client with throttling + cookie auth
    models.ts         # Domain models (Channel, Message, User, Thread)
  mcp/
    index.ts          # MCP stdio server
    tools.ts          # 16 tool definitions + handlers
  client.ts           # Client initialization & config
  plugin.ts           # Plugin registration for PostCLI ecosystem
  types.ts            # Slack API response types

How Authentication Works

PostCLI Slack extracts credentials directly from the Slack desktop app. No bot tokens, no OAuth apps, no admin approval needed.

Two credentials, one session

Slack's web client uses two pieces to authenticate API calls:

Credential Format Scope Where it lives
Cookie d xoxd-... (URL-encoded) Shared across all workspaces SQLite cookie DB (Cookies file)
Token xoxc- xoxc-TEAM-USER-RANDOM-HASH One per workspace LevelDB LocalStorage

The cookie d is a single session cookie stored at .slack.com, valid for every workspace you're logged into. The token xoxc- is workspace-specific and identifies which team you're acting on.

Where Slack stores them

Cookie DB (SQLite):

Installation Path
Flatpak ~/.var/app/com.slack.Slack/config/Slack/Cookies
Native (deb/rpm) ~/.config/Slack/Cookies
Snap ~/snap/slack/common/.config/Slack/Cookies
macOS ~/Library/Application Support/Slack/Cookies

Token storage (LevelDB):

Same base directory, under Local Storage/leveldb/. Tokens are written when you navigate to a workspace in the Slack app. If you only have one workspace active, only that token will be in storage. Navigate to other workspaces to make their tokens available.

Decryption

The cookie d is encrypted with AES-128-CBC. The encryption key is derived via PBKDF2 from a password stored in the OS keyring:

OS Keyring lookup
Linux secret-tool lookup application Slack
macOS Keychain: "Slack Safe Storage"

This is the same key derivation that Chrome/Electron uses for its cookie encryption (PBKDF2 with saltysalt, 1 iteration on Linux, 1003 on macOS).

What auth login does

  1. Finds the Slack desktop app directory (Flatpak, native, snap, or macOS)
  2. Scans LevelDB files for xoxc- tokens (binary scan, no LevelDB library needed)
  3. Decrypts the d cookie from the SQLite database
  4. Calls auth.test with each token to identify the workspace name and user
  5. Saves the selected token + cookie to ~/.config/postcli/.env (0600 permissions)

No data leaves your machine. The saved credentials are the same ones your Slack desktop app uses.

Contributing

git clone https://github.com/postcli/slack.git
cd slack
npm install
npm run build
npm test

Development

npm run cli -- channels list           # run CLI in dev mode
npm run dev:mcp                        # MCP with inspector
npm test                               # run tests

Guidelines

  1. Open an issue first to discuss the change
  2. Fork the repo and create a branch from main
  3. Write tests for new functionality
  4. Run npm test and npm run build before submitting
  5. Keep PRs focused on a single change

Disclaimer

This is an unofficial tool, not affiliated with or endorsed by Slack. It interacts with undocumented internal APIs that may change without notice. Use at your own risk.

License

AGPL-3.0

About

Slack plugin for PostCLI - channels, messages, threads, reactions, search from the terminal and AI agents

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors