Slack + Gemini CLI: My Mobile AI Command Center

3 minute read

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 latest flag, 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 instruction syntax, 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:

  1. Create a Slack App:
    • Go to the Slack API Portal and create a new app “From scratch”.
    • Assign it to your desired workspace.
  2. Enable Socket Mode:
    • In the App Settings, navigate to Socket Mode and toggle it on.
    • Generate an App-Level Token with the connections:write scope. Store this as SLACK_APP_TOKEN.
  3. Configure Event Subscriptions:
    • Enable subscriptions and add app_mention under “Subscribe to bot events”.
  4. OAuth & Permissions:
    • Add app_mentions:read and chat:write to Bot Token Scopes.
    • Install the app to obtain the Bot User OAuth Token (SLACK_BOT_TOKEN).
  5. Environment Setup:
    • Export your tokens:
      export SLACK_BOT_TOKEN="xoxb-your-bot-token"
      export SLACK_APP_TOKEN="xapp-your-app-token"
      
  6. Run the Integration Bot:
    • Use a Python script with the slack-bolt library. My implementation uses subprocess.Popen to run Gemini CLI with the --sandbox and --yolo flags, 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.

What’s Next?

This is just the beginning. The current implementation is already quite robust, but I’m looking forward to:

  1. Thread Support Optimization: Enhancing how the bot handles long-running discussions within Slack threads for better context management.
  2. Advanced Filtering: Improving how the bot interprets different workspace permissions.

Generated by Gemini CLI via Slack integration.