Find the command Claude Code ran last week
Published · Updated · Checked against Claude Code 2.1.319
You remember Claude running some docker compose invocation on Tuesday and you need the exact flags. It is in the session transcript. Each shell command is a tool_use block with name Bash and the command text in input.command, inside ~/.claude/projects/<project>/<session-id>.jsonl, and one jq filter lists them. The output is a separate tool_result entry that points back by ID.
What is in a transcript
The sessions docs say transcripts live under ~/.claude/projects/ and that the entry format is internal and changes between versions. Treat every field name below as observed, not promised. Each command was run against real transcripts on Claude Code 2.1.319 (macOS), and the docs were re-read the docs on 10 Nov 2026. The folder layout is in where Claude Code stores sessions.
Per the claude-directory page, three other places matter for this job. Subagent transcripts are in <session-id>/subagents/, so a command a subagent ran is there and not in the main file. Large tool outputs that did not fit inline are in <session-id>/tool-results/. And ~/.claude/history.jsonl holds only the prompts you typed, never commands.
In a 2.1.319 session the shapes are:
| Entry | Where | Fields that matter |
|---|---|---|
| Assistant call | type is assistant, in message.content[] | type: "tool_use", name, id, input |
| Result | type is user, in message.content[] | type: "tool_result", tool_use_id, is_error, content |
| Time | top level | timestamp (ISO 8601, UTC) |
For a Bash call, input.command is the command. Other tools use other keys under input, such as a file path for Read and Edit.
List every command in one session
f=~/.claude/projects/-Users-me-myapp/<session-id>.jsonl
jq -r 'select(.type=="assistant")
| .timestamp as $t
| .message.content[]?
| select(.type=="tool_use" and .name=="Bash")
| "\($t[0:16]) \(.input.command | split("\n")[0] | .[0:100])"' "$f"
That prints the time and the first line of each command, cut to 100 characters, so the list stays readable. Drop the split and .[0:100] to see whole commands.
To see which tools it leaned on most:
jq -r 'select(.type=="assistant") | .message.content[]? | select(.type=="tool_use") | .name' "$f" |
sort | uniq -c | sort -rn
Find the session first
Usually you do not know which session. Narrow by project and date, then by content.
# sessions touched in the last 7 days, this project
find ~/.claude/projects/-Users-me-myapp -name '*.jsonl' -mtime -7
# which of them contain the string at all (fast, no JSON parsing)
grep -l 'docker compose' $(find ~/.claude/projects/-Users-me-myapp -name '*.jsonl' -mtime -7)
Then search commands only, across all those files, with the file name attached:
find ~/.claude/projects -name '*.jsonl' -mtime -7 -print0 |
xargs -0 jq -r 'select(.type=="assistant")
| input_filename as $f | .timestamp as $t
| .message.content[]?
| select(.type=="tool_use" and .name=="Bash" and (.input.command | test("docker compose")))
| "\($t[0:16]) \($f | split("/")[-1][0:8]) \(.input.command | split("\n")[0] | .[0:90])"'
The test(...) runs on the whole command but the printed line shows only its first line, so a match buried in a long heredoc can look like a miss. The first eight characters of the file name are enough to find the session again or hand to claude --resume.
-mtime -7 uses the file's modification time, so a session resumed this week has a new mtime even if the command ran a month ago. Filter on the timestamp field inside jq when the exact date matters.
Get the command's output
The result is a different line, matched by ID:
id=$(jq -r 'select(.type=="assistant") | .message.content[]?
| select(.type=="tool_use" and .name=="Bash" and (.input.command | test("docker compose up")))
| .id' "$f" | head -1)
jq -r --arg id "$id" 'select(.type=="user") | .message.content | arrays | .[]
| select(.type=="tool_result" and .tool_use_id==$id)
| .content | if type=="array" then map(.text? // "") | join("\n") else . end' "$f"
content is sometimes a string and sometimes an array of blocks, which is why the filter handles both. If the output was large, the transcript may hold a pointer instead of the text, and the full output is in <session-id>/tool-results/.
Find failed commands
jq -r 'select(.type=="user") | .message.content | arrays | .[]
| select(.type=="tool_result" and .is_error==true) | .tool_use_id' "$f"
This gives IDs of failed tool results; feed one to the tool_use filter above. Successful results had is_error set to null, not false, so test == true.
Subagent commands
If Claude delegated work, look under the session folder:
ls ~/.claude/projects/-Users-me-myapp/<session-id>/subagents/
Each file there has the same entry shapes, so run the same filters over <session-id>/subagents/*.jsonl.
When the command is gone
All of this reads files on disk. Claude Code deletes transcripts older than cleanupPeriodDays, 30 days by default (claude-directory docs), and no filter finds a command in a deleted file. ls -t ~/.claude/projects/<project>/ | tail -3 shows how far back yours go. More in Claude Code silently deletes transcripts after 30 days.
Sealkeep helps only if it sealed the session before the sweep. sealkeep index build followed by sealkeep search <query> --content searches inside sealed sessions, and sealkeep recover <id> <dest> restores the original bytes so the filters above work on the copy. It has no tool-call view: it does not extract commands, filter by tool name or pair a call with its result, so the structure is still your jq. Sessions deleted before you installed it stay deleted.
For phrase search instead of tool calls, see searching past Claude Code conversations. The guide index is at /guides/.
FAQ
Does Claude Code keep a log of the commands it ran?
Inside each session transcript, yes: Bash commands appear as tool_use entries with input.command. The docs mention no separate command log.
Why can't I find a command a subagent ran?
Subagent transcripts are separate files under <session-id>/subagents/, not in the main session file.
Will these jq filters keep working after an update?
Not guaranteed. If one returns nothing after an upgrade, print a line with head -1 "$f" | jq . and check the field names.