Skip to content

perf(cli): speed up generation via direct spawn and settings isolation - #18

Merged
uaoa merged 3 commits into
uaoa:mainfrom
yelmuratoff:perf/cli-startup-speedup
Jun 13, 2026
Merged

uaoa merged 3 commits into
uaoa:mainfrom
yelmuratoff:perf/cli-startup-speedup

Conversation

@yelmuratoff

@yelmuratoff yelmuratoff commented Jun 12, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Commit message generation through the Claude CLI is slow — and for anyone with a customized Claude Code setup (global CLAUDE.md/rules, hooks, MCP servers) it is also unreliable, because the CLI loads the user's entire global configuration on every invocation:

  • the user-level CLAUDE.md/rules set is injected into every call (~112 KB in my case), slowing generation and steering the model away from the task — it sometimes answered my global rules instead of returning a commit message;
  • Stop hooks add a whole extra model turn;
  • every configured MCP server is booted, even though commit generation needs no tools;
  • the startup update check and telemetry add to every cold start.

Measured on macOS with haiku:

Scenario Before After
Real commit generation (heavy global config) ~26.8 s 6–12 s
Trivial-prompt cold start ~4.2 s ~2.4 s

Changes

  • Run the CLI directly via spawn, feeding the prompt through stdin — no login shell, no cat, no temp files. The diff never touches disk anymore, so the privacy guarantee that privacyMode approximated with file permissions now always holds for the CLI path.
  • Pass --setting-sources "" and --strict-mcp-config so user/project settings, rules, hooks and MCP servers stay out of generation. Subscription auth is unaffected.
  • Set DISABLE_AUTOUPDATER=1 and CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC=1 for the spawned process.
  • Backward compatibility: older CLI versions don't know the isolation flags. On an unknown option error the call is retried without them and the result is remembered for the session, so old CLIs keep working and pay the extra probe only on the first generation. Other errors propagate unchanged.

Notes for review

  • Managed mode is now also isolated from user settings. That is intentional (same speed/correctness reasoning), but it is a behavior change — happy to scope it differently if you prefer.
  • The Windows path (.cmd wrapper via shell; system prompt still skipped there, as before) is logically equivalent to the previous code but I could not test it on a real Windows machine.
  • Verified: lint + webpack build green; the fallback was exercised against stub CLIs (old CLI retries once then remembers, new CLI always uses the flags, real errors do not trigger a retry); end-to-end smoke test against the real CLI.

Run the CLI directly via spawn instead of a login shell with temp files;
the prompt is fed through stdin and never touches disk. Add
--setting-sources "" and --strict-mcp-config so the user's global
CLAUDE.md/rules, hooks and MCP servers are not loaded into every call
(they slowed generation several times over and polluted the output).
Disable the startup update check and telemetry (DISABLE_AUTOUPDATER,
CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC).
--strict-mcp-config and --setting-sources are not known to older Claude
CLI releases and would fail with "unknown option" where the extension
previously worked. Probe once per session: on an unknown-option error
retry without the isolation flags and remember the result, so old CLIs
pay the extra spawn only on the first generation. Other errors still
propagate unchanged.
@yelmuratoff yelmuratoff changed the title Perf/cli startup speedup perf(cli): speed up generation via direct spawn and settings isolation Jun 12, 2026
@uaoa
uaoa merged commit 28f93c9 into uaoa:main Jun 13, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants