Skip to content

jborkowski/claude-agent-daemon

Repository files navigation

Claude Agent Daemon

Remote agentic workflow system for Claude Code with Discord integration.

Features

  • Thread-based parallel agent execution (each Discord thread = separate Claude CLI process)
  • Direct Message (DM) support for private sessions
  • Git worktree isolation for conflict-free parallel work
  • Human-in-the-loop (HITL) approval workflow via Discord
  • SQLite persistence for session state and audit logs
  • Atomic commits per session
  • Session lifecycle management

Architecture

claude-agent-daemon/
├── daemon/              # Main binary
├── bot-interface/       # Discord bot
├── session-manager/     # Multi-session orchestration
├── claude-executor/     # Claude CLI wrapper
├── job-queue/          # Job management & persistence
├── repo-manager/       # Git operations
└── shared/             # Common types & errors

Prerequisites

  • Rust 1.75+
  • Claude Code CLI installed and authenticated (claude command available)
  • Git repository
  • Discord bot token with correct permissions (see Bot Setup below)

Installation

Bot Setup

  1. Go to Discord Developer Portal

  2. Create a new application or select your existing bot

  3. Go to the "Bot" section and get your bot token

  4. Enable the following Privileged Gateway Intents:

    • ✅ Message Content Intent
  5. Go to OAuth2 → URL Generator and select:

    • Scopes: bot
    • Bot Permissions:
      • View Channels
      • Send Messages
      • Send Messages in Threads
      • Create Public Threads
      • Manage Threads
      • Read Message History
      • Embed Links
  6. Use this OAuth2 URL to invite your bot (replace YOUR_CLIENT_ID):

https://discord.com/api/oauth2/authorize?client_id=YOUR_CLIENT_ID&permissions=326432598048&scope=bot

Permission Integer: 326432598048

Build from source

git clone <repo>
cd claude-agent-daemon
cargo build --release

Binary will be at target/release/claude-daemon

Configuration

  1. Copy example config:
cp daemon.toml.example daemon.toml
  1. Edit daemon.toml:
[repository]
path = "/path/to/your/repo"

[discord]
bot_token = "your_bot_token"
guild_id = "your_guild_id"
authorized_users = ["discord_user_id_1", "discord_user_id_2"]
  1. Set environment variable:
export DISCORD_BOT_TOKEN="your_token"
  1. Ensure Claude Code CLI is authenticated:
claude --version
# Should work without asking for credentials

Usage

Start daemon

./target/release/claude-daemon --config daemon.toml

Or with verbose logging:

./target/release/claude-daemon --config daemon.toml --verbose

Discord Commands

Main Channel:

  • /new-task <description> - Create new thread and spawn Claude session
  • /list-tasks - Show all active sessions
  • /help - Show available commands

In Thread or DM:

  • <message> - Send message to Claude CLI
  • /status - Show session info and runtime
  • /diff - Show git changes in this session
  • /commit <message> - Commit changes atomically
  • /cancel - Terminate session and cleanup

Direct Messages: You can also DM the bot directly! It will automatically create a private session for you.

Example Workflow

Main Channel:
You: /new-task Fix authentication bug in login.rs
Bot: Created thread and session: Fix authentication bug in login.rs

Thread "Fix authentication bug in login.rs":
You: Find the auth bug
Bot: I found the issue in login.rs:45. The token validation is missing...
You: Fix it and add tests
Bot: Done. Fixed the bug and added 3 unit tests. All tests passing.
You: /diff
Bot: [shows git diff]
You: /commit "Fix token validation bug"
Bot: Committed to branch session-abc123. Commit: a1b2c3d

Systemd Service

Create /etc/systemd/system/claude-daemon.service:

[Unit]
Description=Claude Agent Daemon
After=network.target

[Service]
Type=simple
User=youruser
WorkingDirectory=/opt/claude-agent-daemon
ExecStart=/opt/claude-agent-daemon/target/release/claude-daemon --config /opt/claude-agent-daemon/daemon.toml
Restart=on-failure
RestartSec=10
Environment="ANTHROPIC_API_KEY=sk-ant-..."
Environment="DISCORD_BOT_TOKEN=..."

[Install]
WantedBy=multi-user.target

Enable and start:

sudo systemctl enable claude-daemon
sudo systemctl start claude-daemon
sudo systemctl status claude-daemon

Development

Run tests

cargo test

Run with logging

RUST_LOG=debug cargo run -- --config daemon.toml

Check code

cargo clippy
cargo fmt --check

Architecture Details

Session Isolation

Each Discord thread creates:

  • Separate Claude Code CLI process
  • Isolated working directory (/tmp/claude-sessions/{thread-id}/)
  • Git worktree with unique branch (session-{uuid})
  • Independent conversation context

Git Worktrees

Git worktrees enable true parallel work:

  • Each session works on its own branch
  • No merge conflicts between sessions
  • Can commit/discard independently
  • Automatic cleanup on session termination

State Management

Sessions persist to SQLite with states:

  • active - Running normally
  • awaiting_review - HITL checkpoint
  • completed - Successfully finished
  • failed - Error occurred
  • cancelled - User terminated

Troubleshooting

Claude CLI not found

Ensure Claude Code CLI is installed and in PATH:

which claude
claude --version

Permission denied on worktree

Check repository permissions and ensure user has write access:

ls -la /path/to/repo

Database locked

Stop daemon and check for stale processes:

systemctl stop claude-daemon
ps aux | grep claude

Discord bot not responding

  1. Verify bot token in config
  2. Check bot has required permissions in Discord
  3. Ensure bot is added to your server
  4. Check logs: tail -f logs/daemon.log

Security

  • Bot tokens stored in config (use environment variables)
  • User whitelist enforced via authorized_users
  • Audit log tracks all commands and commits
  • Sessions isolated in separate directories
  • No auto-push to remote (manual only)

Performance

  • Supports 3+ concurrent sessions (configurable)
  • Session creation: <5 seconds
  • Message response: <3 seconds
  • Minimal daemon overhead: ~50MB memory idle

Roadmap

  • Slack integration (v1.1)
  • Web dashboard (v2.0)
  • Multi-repository support (v1.2)
  • CI/CD integration (v1.3)
  • Real-time output streaming (v1.5)

License

MIT

Contributing

See PRD at claude-agent-daemon-prd.md

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages