Suggest optimizing repetitive slow commands
Feature Request
Claude Code should detect and suggest optimizing repetitive slow commands during a session.
Problem
In a long session building an LLVM backend, I ran Docker builds ~50 times. Each invocation included apt-get update && apt-get install -y cmake ninja-build clang lld python3 (~30 seconds). Over the session, this wasted ~25 minutes. I never noticed or suggested caching it in a pre-built Docker image until the user pointed it out.
Expected Behavior
When a Bash command with the same expensive prefix is executed more than 2-3 times, Claude should proactively suggest optimization:
- Docker: "This docker run installs the same packages every time. Want me to create a cached image?"
- npm/pip/cargo: "This install step has run N times. Consider caching in a lockfile or pre-built environment."
- cmake configure: "This configure step is identical to the last run. The build directory already exists."
- General: Track command prefixes and durations. Flag when cumulative time for repeated patterns exceeds a threshold (e.g., 2 minutes).
Why This Matters
- Users trust Claude to be efficient with their time
- Repetitive setup commands are an obvious optimization that a human developer would spot immediately
- The fix is usually trivial (cache the result) but Claude gets tunnel-visioned on the task and treats infrastructure as boilerplate
Suggested Implementation
Track (command_prefix_hash, duration_ms, count) per session. When count > 3 && total_duration > 60s, suggest optimization. The prefix could be the first N tokens of the command, normalized to ignore variable arguments.
This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗