Skip to content

claude accountUsage spawns a full-config CLI: user hooks fire and MCP servers start on every usage read #28

Closed

Description

@TennyZhuang

Found while upgrading Raft's daemon from OAR 0.0.7 to 0.8.0 (https://github.com/botiverse/slock/pull/8608); @XX asked for a live check.

What happens: claudeAccountUsage spawns claude -p --input-format stream-json --output-format stream-json --verbose --no-session-persistence with no option that limits which configuration is loaded. The child process therefore starts with the user's full configuration.

Repro (Claude Code 2.1.283, macOS): I set up a temporary project directory whose .claude/settings.json has a SessionStart hook, plus a .mcp.json server (with enableAllProjectMcpServers). Both write a marker file when they run. Then I ran claudeRuntime.accountUsage() from that directory.

  • OAR 0.8.0 as shipped: the SessionStart hook ran and the MCP server was started, and usage was returned.
  • The same control sequence (initialize then get_usage) with --safe-mode added: usage was still returned with the same shape (session, subscription_type, rate_limits_available, rate_limits, behaviors), and neither the hook nor the MCP server ran.

The 0.0.7 HTTP reader had no such side effect. With 0.8.0, every usage refresh now runs the user's hooks and starts their MCP servers.

Suggested fix: pass --safe-mode when spawning. Per claude --help, it disables CLAUDE.md, hooks, MCP servers and plugins while keeping auth. --bare is not an option, because it restricts auth to ANTHROPIC_API_KEY and skips keychain reads, which breaks OAuth subscriptions.
Open question: I haven't checked which CLI version introduced --safe-mode. An older CLI may reject the flag, so the fix needs a fallback, such as retrying without the flag or gating on version.

Scope of what I tested: project-level hooks and MCP only. That user-level configuration is also disabled by --safe-mode comes from the help text; I didn't test it.

Activity

  1. TennyZhuang commented on Sep 29, 2026

    @TennyZhuang
    ContributorAuthor

    Update after @XX's suggestion to test user-level config (CLAUDE_CONFIG_DIR pointed at a temp dir, CLI 2.1.283):

    • User-level SessionStart hook ran in 4 of 4 reads.
    • A user-level MCP server started in 3 of 4 reads. The first read was on a fresh config dir; claude mcp list confirmed the server config itself starts.
    • With --safe-mode: 3 of 3 reads returned usage, and neither the hook nor the MCP server ran.

    So both user-level and project-level config are affected, and --safe-mode isolates both.

  2. added a commit that references this issue on Sep 29, 2026
    b151959
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions