Read-only Slack client using browser token authentication. No Slack app required.
# 1. Install
uv sync
# 2. Get your Slack credentials (see below)
# 3. Use it
python
>>> from slack_agent import SlackClient
>>> client = SlackClient(token="xoxc-...", cookie="xoxd-...")
>>> client.get_unread_channels()- Open Slack in browser and log in
- Open DevTools (F12)
- Cookie: Application → Cookies → copy
dvalue - Token: Console → paste this:
JSON.parse(localStorage.localConfig_v2).teams[Object.keys(JSON.parse(localStorage.localConfig_v2).teams)[0]].token
convos = client.get_all_conversations()
# Returns: {"channels": ["C1", "C2"], "ims": ["D1"], "mpims": ["G1"]}# Get unread conversation IDs with mention counts
unreads = client.get_unreads()
for u in unreads:
print(f"{u.channel_id}: {u.mention_count} mentions")
# Get full channel info for unreads
channels = client.get_unread_channels()
for ch in channels:
print(f"Unread in: {ch.name}")# Read channel/DM history
messages = client.get_channel_history("C123ABC", limit=20)
for msg in messages:
print(f"{msg.user}: {msg.text}")
# Read thread replies
thread = client.get_thread("C123ABC", thread_ts="1234567890.123456")results = client.search_messages("quarterly report", limit=10)
for msg in results:
print(msg.text)user = client.get_user_info("U123ABC")
print(f"{user.name} ({user.real_name})")
channel = client.get_channel_info("C123ABC")
print(f"{channel.name} (private: {channel.is_private})")# Find a group DM containing specific people (case-insensitive)
mpim_id = client.find_conversation_by_members(["shiv", "mihir"])
if mpim_id:
messages = client.get_channel_history(mpim_id)# Most recent message from each conversation, sorted by time
activity = client.get_recent_activity(limit=10)
for channel, message in activity:
print(f"[{channel.name}] {message.text[:50]}...")Instead of passing credentials directly, use a .env file:
cp .env.example .env
# Edit .env with your SLACK_TOKEN and SLACK_COOKIEimport os
from dotenv import load_dotenv
from slack_agent import SlackClient
load_dotenv()
client = SlackClient(
token=os.environ["SLACK_TOKEN"],
cookie=os.environ["SLACK_COOKIE"],
)This repo includes a starter agent for Claude Code that lets you interact with Slack using natural language.
-
Install the package in editable mode:
uv sync uv pip install -e . -
Copy the agent to your Claude agents directory:
# For global access (all projects) mkdir -p ~/.claude/agents cp agents/slack-agent.md ~/.claude/agents/ # Or for project-specific access mkdir -p .claude/agents cp agents/slack-agent.md .claude/agents/
-
Edit the agent file and replace
/PATH/TO/slack_agentwith your actual repo path:# Example: if you cloned to ~/projects/slack_agent sed -i '' 's|/PATH/TO/slack_agent|/Users/yourname/projects/slack_agent|g' ~/.claude/agents/slack-agent.md
-
Set up your credentials (see Quick Start above)
Once installed, just ask Claude Code about Slack:
> Check my Slack unreads
> What did [person] say yesterday?
> Summarize the latest thread in #channel-name
> Find messages about "topic"
The agent will automatically be invoked when Claude detects Slack-related requests.
# Install with dev dependencies
uv sync --extra dev
# Run tests
uv run pytest tests/ -v