Slack + Gemini CLI: My Mobile AI Command Center
Published:
I’m thrilled to share a major milestone in my personal AI workflow: Gemini CLI is now fully integrated with Slack!
This integration allows me to interact with my local Gemini agent directly through a Slack bot. By bridging these two powerful tools, I’ve transformed how I manage my coding and research tasks.
Why This Matters
The biggest game-changer is mobility. I am no longer tethered to my workstation to keep projects moving. Whether I’m on a walk, grabbing coffee, or just away from my desk, I can now:
- Orchestrate from Mobile: Send complex instructions to Gemini CLI via the Slack mobile app.
- Real-time Updates: Receive immediate feedback and logs as Gemini executes tasks in my workspace.
- Collaborative AI: Treat the agent like a highly capable colleague who is always available for a “quick sync” in a chat thread.
The Experience
It’s incredibly satisfying to see Gemini picking up tasks and reporting progress while I’m out and about. The integration is more than just a bridge; it’s a context-aware system:
- Thread-Based Memory: The bot maps the Slack
thread_ts(thread timestamp) to the Gemini CLI’s--session-id. While Gemini CLI normally uses UUIDs, this mapping effectively turns a Slack timestamp into a persistent session identifier. This means every reply in a Slack thread maintains the conversation context, allowing for iterative debugging and multi-step reasoning. - Smart Resume: If I start a new message (not in a thread), the bot automatically checks for any active sessions in the last 8 hours. If one exists, it uses the
--resume latestflag, letting me pick up exactly where I left off without manual configuration. - Whitelisted Control: For security, I’ve implemented a project whitelist. I can switch between contexts using a simple
cd project_name; your instructionsyntax, ensuring the agent only operates within my approved research and development folders.
How to Set It Up
To implement this integration for your own workspace, follow these steps:
- Create a Slack App:
- Go to the Slack API Portal and create a new app “From scratch”.
- Assign it to your desired workspace.
- Enable Socket Mode:
- In the App Settings, navigate to Socket Mode and toggle it on.
- Generate an App-Level Token with the
connections:writescope. Store this asSLACK_APP_TOKEN.
- Configure Event Subscriptions:
- Enable subscriptions and add
app_mentionunder “Subscribe to bot events”.
- Enable subscriptions and add
- OAuth & Permissions:
- Add
app_mentions:readandchat:writeto Bot Token Scopes. - Install the app to obtain the Bot User OAuth Token (
SLACK_BOT_TOKEN).
- Add
- Environment Setup:
- Export your tokens:
export SLACK_BOT_TOKEN="xoxb-your-bot-token" export SLACK_APP_TOKEN="xapp-your-app-token"
- Export your tokens:
- Run the Integration Bot:
- Use a Python script with the
slack-boltlibrary. My implementation usessubprocess.Popento run Gemini CLI with the--sandboxand--yoloflags, capturing output in real-time and feeding it back into the Slack thread. - Pro Tip: I added a noise filter to remove common CLI warnings (like Ripgrep unavailability) to keep the Slack chat clean and focused on the results.
- Use a Python script with the
What’s Next?
This is just the beginning. The current implementation is already quite robust, but I’m looking forward to:
- Thread Support Optimization: Enhancing how the bot handles long-running discussions within Slack threads for better context management.
- Advanced Filtering: Improving how the bot interprets different workspace permissions.
Generated by Gemini CLI via Slack integration.
