[FEATURE] Agent-level command/bash history with success/failure tracking (Ctrl+R for agents)
Preflight Checklist
- [x] I have searched existing requests and this feature hasn't been requested yet
- [x] This is a single feature request (not multiple features)
Problem Statement
When the agent runs bash/shell commands during a session, it often needs multiple attempts to get a command right — for example, connecting to a Docker container, setting up an environment, or running a specific build command. Once the agent finds the working command, that knowledge is lost when the session ends.
In a new session, if the agent faces the same task (e.g., "connect to my Docker container"), it starts from scratch and repeats the same trial-and-error process, wasting time and tokens on commands it has already tried and failed before.
This is the same problem that Ctrl+R (reverse search) solves for humans in the terminal — except applied to the agent itself. Humans learn from their shell history; agents currently don't.
Proposed Solution
Introduce a persistent, searchable command history for the agent that tracks:
- The bash/shell commands the agent has executed
- Whether each command succeeded or failed (exit code, stderr output)
- The context/intent of the command (e.g., "connect to Docker", "start dev server")
- The working directory and project context
Before running a command, the agent could search this history to find previously successful commands for similar tasks, avoiding repeated trial-and-error. Think of it as Ctrl+R but for the agent's own tool use — a way to recall what worked (and what didn't) in the past.
This could be stored locally (e.g., in ~/.claude/ alongside existing session data) and scoped per project or globally, depending on user preference.
Alternative Solutions
- Manually adding successful commands to
CLAUDE.mdor project memory files after each session — this works but is tedious and error-prone, and doesn't capture the success/failure metadata automatically. - Using system prompt instructions to remind the agent of specific commands — this doesn't scale and uses context window tokens.
- Relying on the agent reading shell history files (
~/.bash_history,~/.zsh_history) — these don't track success/failure outcomes and aren't specific to the agent's own executions.
Priority
Medium - Would be very helpful
Feature Category
Performance and speed
Use Case Example
- I ask the agent to "connect to my running Docker container and check the logs"
- The agent tries
docker exec -it myapp bash— fails because the container name is different - It tries
docker psto list containers, thendocker exec -it myapp-dev-1 bash— succeeds - Session ends
- Next day, I ask the same thing in a new session
- Currently: The agent goes through the same trial-and-error process again (2-3 failed attempts before finding the right container name pattern)
- With this feature: The agent searches its command history, finds that
docker exec -it myapp-dev-1 bashwas previously successful for this project, and uses it directly — saving time and tokens
Additional Context
This is conceptually similar to how Ctrl+R works in bash/zsh for humans — a reverse search through command history to find previously successful commands. The key difference is that this would also track command outcomes (success/failure), making it even more powerful than traditional shell history.
This feature would complement the existing memory/CLAUDE.md system by automatically capturing operational knowledge (working commands) without requiring the user to manually document them.
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗