agentleFS
DevRohit06DevRohit06/discli/CLAUDE.md

discli

CLAUDE.md35 starsChanged 9 months agoMITView on GitHub

discli is a Discord CLI for AI agents and humans — a Python command-line tool for managing Discord servers, messages, reactions, threads, DMs, events, voice audio, and rich interactive components (modals, workflows, dashboards) from the terminal. Published on PyPI as discord-cli-agent. This project uses uv for dependency management. No linter is configured. Commit style: conventional commits (feat:, fix:, docs:, chore:). There is no pytest config, and asyncio_mode is unset, so async tests need explicit @pytest.mark.asyncio. tests/conftest.py holds one autouse fixture,…

  • Reads credentials
  • Commits and pushes

The file

We split this CLAUDE.md into the rules it gives an agent

5 rules. About 0 are common, 0 are distinctive, and 5 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈0

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 5

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    No linter is configured. Commit style: conventional commits (feat:, fix:, docs:, chore:).

    line 33
  2. Very specific:

    Create file in src/discli/commands/

    line 99
  3. Very specific:

    Add tests in tests/

    line 102
  4. Very specific:

    Update agents/discord-agent.md with command reference

    line 103
  5. Very specific:

    Update the relevant skills/*/SKILL.md if the command appears there (7 skills ship in skills/)

    line 104

≈ “Common” is an estimate: at least 1 in 5 of the 29,248 CLAUDE.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
CLAUDE.md

CLAUDE.md

This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.

Project Overview

discli is a Discord CLI for AI agents and humans — a Python command-line tool for managing Discord servers, messages, reactions, threads, DMs, events, voice audio, and rich interactive components (modals, workflows, dashboards) from the terminal. Published on PyPI as discord-cli-agent.

Commands

This project uses uv for dependency management.

# Install (editable, with dev deps) — creates .venv/ automatically
uv sync --dev

# Install with voice features (TTS/STT providers)
uv sync --dev --extra voice --extra elevenlabs --extra deepgram

# Run tests
uv run pytest tests/ -v

# Run a single test
uv run pytest tests/test_utils.py -v

# Run the CLI
uv run discli --help

# Build package
uv build

No linter is configured. Commit style: conventional commits (feat:, fix:, docs:, chore:).

There is no pytest config, and asyncio_mode is unset, so async tests need explicit @pytest.mark.asyncio. tests/conftest.py holds one autouse fixture, no_network, which patches discord.http.HTTPClient.request/static_login to raise — without it a test that drives the CLI end to end falls back to the developer's own token in ~/.discli/config.json and makes live API calls that pass locally and fail in CI. tests/test_examples.py imports and executes every file in examples/, so a broken example breaks the suite.

Environment Variables

  • DISCORD_BOT_TOKEN — bot token (Click envvar, also read by client.py)
  • DISCLI_TTS / DISCLI_STT / DISCLI_TTS_VOICE — provider selection
  • DISCLI_DEEPGRAM_MODEL (default nova-3), DISCLI_DEEPGRAM_LANGUAGE (default multi)
  • ELEVENLABS_API_KEY, DEEPGRAM_API_KEY, OPENAI_API_KEY — provider credentials

Note: examples/meeting_transcriber.py reads DISCORD_TOKEN, not DISCORD_BOT_TOKEN.

Gotchas

  • discord-ext-voice-recv==0.5.2a179 is an exact pin — do not bump. See the justification comment in pyproject.toml (0.4.x lacks the required cipher; 0.5.0a167 has a circular import; 0.5.1a170 doesn't deliver audio).
  • Voice requires ffmpeg on PATH and the DAVE encryption patch. Run discli doctor first when voice misbehaves.
  • audioop-lts is a conditional dep for Python ≥3.13 (stdlib audioop removal).
  • Intents are only sent on the Gateway path (listen, serve, voice). One-shot commands use run_rest() and transmit no intents. Missing privileged intents fail the whole Gateway connection (PrivilegedIntentsRequired) but only fail individual REST calls with a 403.
  • run_rest_action() sets Intents.members = True on the login-only client. That flag never reaches Discord — it exists to defeat discord.py's client-side guard in Guild.fetch_members(), which raises ClientException (a sibling of HTTPException, so no handler catches it) before any request goes out. Do not "clean this up" to Intents.none().
  • Channel listings are scoped to what the bot can view, and from 2026-11-16 Discord drops channels without VIEW_CHANNEL from GET /guilds/{id}/channels and the Gateway entirely. No API reports how many were withheld. channel list and server info disclose this via warn_channel_visibility() on stderr — deliberately not stdout, so --json payloads stay parseable. serve's channel_list sets visible_only: true in-band instead, because JSONL has no stderr equivalent.
  • Discord split PIN_MESSAGES, BYPASS_SLOWMODE, CREATE_GUILD_EXPRESSIONS, and CREATE_EVENTS out of broader permissions during 2026. A bot invited before the split keeps the old bit and silently loses the new capability. discli doctor --server <name> detects exactly that case (holds legacy bit, lacks split bit); see PERMISSION_SPLITS in commands/doctor.py.
  • message search-server calls GET /guilds/{id}/messages/search through a raw discord.http.Route, because discord.py 2.7.1 does not wrap that endpoint. Going through Route keeps it inside discord.py's rate limiter and auth. Discord answers 202 with no messages key while it is still indexing a guild — treating that as an empty result set would report a wrong answer rather than a slow one.
  • schedule actions are discli command lines, never shell commands. parse_action() lexes with shlex(punctuation_chars=True) so ; and && become their own tokens, then walks the real Click tree. Backticks and $ are deliberately not rejected — no shell is involved, and a message containing backtick-wrapped code formatting is ordinary Discord content.
  • Scheduled actions run via asyncio.to_thread: discli commands call asyncio.run() internally, which raises if invoked from the scheduler's own running event loop.
  • tzdata is a Windows-only conditional dep. Windows ships no IANA tz database, so schedule --tz would otherwise raise ZoneInfoNotFoundError.
  • server apply is additive by default: it creates and updates what the spec names and leaves everything else alone. Deletions require --prune, which routes through confirm_destructive. Spec items are matched by name, not ID, so a rename reads as delete-plus-create — that is the price of a spec being portable between servers.
  • _compare() in server_spec.py only diffs fields the spec actually declares. An omitted field means "not managed here", not "set to null" — otherwise a hand-trimmed spec would blank out everything it left out.
  • Channel/role positions are exported but never applied. Discord renumbers siblings on every positional write, so applying them produces churn and ordering that depends on apply order.
  • Dashboard pages may set layout: "v2" for Components v2, but every page of one dashboard must use the same layout. Discord stamps IS_COMPONENTS_V2 on the message at send time and it cannot be toggled, so paging between an embed page and a v2 page is impossible; DashboardDefinition.__post_init__ rejects the mix. A v2 message also carries no content or embeds.
  • v2 buttons keep the same dash:<id>:<key> custom_id prefix as the embed layout, so interaction routing is identical across both.
  • The moderation permission profile is an allowlist, not ["*"]. It used to be byte-identical to full, which made selecting it for least privilege a no-op. Voice and interact are in scope on purpose (commit df6b606) and must stay; permission set must stay out or the profile can promote itself to full. tests/test_permission_profiles.py pins both, plus the moderation-is-a-superset-of-readonly invariant.
  • The permission profile is enforced in run_rest()/run_gateway(), so a command that never calls Discord skips it entirely. Local commands (permission set, audit clear, config set, schedule *, serve, listen) must call enforce_profile(ctx) themselves. test_no_command_silently_skips_the_permission_check fails if a new one forgets.
  • resolve_guild() by name goes through GET /users/@me/guilds, which returns partial guilds with no roles and no owner_id. Anything reading Member.guild_permissions or guild.get_role() off one computes zero instead of failing, so _ensure_full_guild() re-fetches by ID. Do not remove it.
  • fetch_channels() does not populate the guild's channel cache either, so channel.category is always None on a REST client. server_spec._channel_spec() resolves the parent from category_id against the fetched list instead.
  • cli.py reconfigures stdout/stderr to UTF-8 at startup. Windows consoles and redirected pipes default to a legacy code page, and emoji in Discord channel names would otherwise raise UnicodeEncodeError.
  • Profile patterns match by prefix, so a bare group name in an allowed list grants every command that group will ever have. chat listed "config" and "server", which is how it came to allow config set (overwriting the stored token) and server apply. Spell out subcommands unless blanket access is intended; test_no_profile_grants_a_whole_group_by_bare_prefix enforces it against the live tree.
  • confirm_destructive() calls enforce_profile() before prompting. Otherwise a forbidden command asks "are you sure?" and only refuses after you say yes.

Architecture

Entry point: src/discli/cli.py → Click root group → registers all command groups.

Core flow: Click CLI → permission/audit check (security.py) → run_rest() for one-shot HTTP actions or run_gateway() for live state → async discord.py action → output() (utils.py).

Key modules:

  • client.py — Token resolution, REST/Gateway lifecycle separation, and minimal Gateway intent construction
  • security.py — Permission profiles (full/chat/readonly/moderation), audit logging to ~/.discli/audit.log (JSONL), token-bucket rate limiter
  • utils.py — Output formatting plus async, cache-first resource resolvers with REST fallbacks
  • config.py — Token storage at ~/.discli/config.json
  • voice_engine.py — VoiceEngine with AudioPlayer, AudioListener, VAD-based speech segmentation, audio codec handling
  • interact_engine.py — InteractEngine for modals, workflows, and dashboards with interaction routing and state management; also the Components v2 block builders (build_v2_block, build_v2_view)
  • tts.py — TTS provider protocol with ElevenLabs and OpenAI implementations
  • stt.py — STT provider protocol with Deepgram and OpenAI Whisper implementations
  • commands/server_spec.py — server export/diff/apply; decorates server_group from server.py, which imports it at the bottom for that side effect
  • commands/schedule.py — discli schedule, recurring discli commands stored in ~/.discli/schedules.json; schedule run drives them with discord.ext.tasks
  • commands/doctor.py — discli doctor, the first-stop diagnostic: checks token, ffmpeg on PATH, DAVE/Opus voice patches, provider API keys. All local unless --server is passed, which adds the network permission-bitfield check

The permission and audit command groups are defined inline in cli.py, not in commands/.

Command pattern: Each module in commands/ defines Click commands and an async action. One-shot commands call run_rest(ctx, action). Only live events, voice state, and persistent connections call run_gateway(ctx, action, features=...) or manage a long-lived Gateway client directly.

serve command (commands/serve.py): The largest module (~2100 lines). Runs a persistent bot with bidirectional JSONL over stdin/stdout. Features: event forwarding, action dispatch (send/reply/edit/delete/stream/typing/reactions/threads/polls/channels/members/roles/DMs), voice actions (connect/speak/play/listen/etc.), interactive actions (workflows, dashboards), slash command registration, streaming message edits with periodic flush, Windows-compatible stdin reading via threading.

Adding a New Command

  1. Create file in src/discli/commands/
  2. Define Click group/command following existing patterns
  3. Register in src/discli/cli.py
  4. Add tests in tests/
  5. Update agents/discord-agent.md with command reference
  6. Update the relevant skills/*/SKILL.md if the command appears there (7 skills ship in skills/)

Docs Development

# Start docs dev server (Lito, Astro-based)
npx @litodocs/cli dev -i ./docs

# Build docs for production
npx @litodocs/cli build -i ./docs -o ./docs/dist

Docs live in docs/ — Lito framework with docs-config.json for sidebar/theme. Custom landing page in docs/_landing/.

Release Process

Bump version in pyproject.toml → commit → git tag vX.Y.Z && git push origin vX.Y.Z → CI runs tests (Python 3.10–3.13), builds, creates GitHub Release, publishes to PyPI.

There is no CI on pushes or PRs — tests run only on v* tags, so run uv run pytest tests/ -v locally before pushing. The docs workflow is path-filtered to docs/** on main.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.