r/ClaudeCode • • 5d ago

Tips & Workflows I diffed 43 Claude Code /compact summaries against the raw JSONL transcripts on disk

Claude Code keeps appending every raw tool call and result to ~/.claude/projects/*/*.jsonl. Running /compact only shrinks the API context window, not those logs on disk. Across 43 real compactions diffed against raw JSONL, 77% of prose decisions survived while only 0.2% of shell commands survived.

You can check every raw Bash command still sitting in your logs right now without installing anything:

jq -r '.message.content[]? | select(.type == "tool_use" and .name == "Bash") | .input.command // empty' ~/.claude/projects/*/*.jsonl | wc -l

Reading multi-GB JSONL files by hand across Claude Code, Codex, Cursor, and opencode got slow, so I wired PreCompact (4 KB), SessionStart (2 KB), and UserPromptSubmit (1,536 bytes) hooks in an 18.6 MB MIT Go CLI called deja-vu. It runs in 107 ms on 19,195 sessions (13.6 s cold build), adds one 477-token MCP tool across 52 coding agents, and cut median task tokens 57.6% on a 329-file Go repo.

Caveat: pure BM25 drops to 43.3% hit@1 on keyword-free preference paraphrases (vs 88.9% overall on LongMemEval-S 470q), so optional deja embed covers vector fallback, and noisy recall hurt mean tokens in one control run.

For Claude Code plugin install: claude plugin marketplace add vshulcz/deja-vu (install script and Windows winget/scoop commands are in the README): https://github.com/vshulcz/deja-vu

0 Upvotes

15 comments sorted by

•

u/AutoModerator 5d ago

Hey! Thanks for posting to r/ClaudeCode

While participating in this thread, please follow our community rules. Keep discussions constructive. Attack the idea, not the person.

For help, project discussions, tips, and general chat, join the ClaudeCode Discord.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

1

u/Accomplished-Tea-822 5d ago

heads up, that jq glob skips subagent transcripts. They live in <session-id>/subagents/agent-*.jsonl next to each session file, so something like ~/.claude/projects/*/{*.jsonl,*/subagents/*.jsonl} gets both.

Also the logs aren't permanent. Claude Code deletes anything older than cleanupPeriodDays (30 by default), so whatever you build on them only sees about a month unless you raise that.

1

u/VShulcz 5d ago

yeah, the jq one-liner missed subagents. deja walks */subagents/*.jsonl and keeps the opening task plus the last 4 turns by default (DEJA_INCLUDE_SUBAGENTS=1 indexes the whole child stream, which is otherwise mostly noisy tool reads). on the 30-day sweep, anything already indexed stays searchable after Claude Code deletes the jsonl, and it warns 7 days ahead when files approach cleanupPeriodDays.

1

u/iFun4ik 5d ago

The commands are interesting, but I’d also check whether the summary kept the reason behind each decision. A command can be recovered from the log; knowing why an approach was rejected is harder to reconstruct after compaction.

1

u/VShulcz 5d ago

even in those 43 compactions, 23% of decisions still dropped, and rejected approaches are usually the first thing a summary smooths over. the PreCompact hook carries explicit rejected/refuted verdicts forward alongside conclusions while the raw turns stay indexed by file. implicit rejections buried across several turns are still the hardest case to extract without an LLM pass.

1

u/iFun4ik 3d ago

yeah the implicit ones are the worst. what helped me a bit: every time i reject something i make the agent write one line in a decisions file right then, like "tried X, dropped bc Y". way cheaper than digging it out of the transcript later

1

u/VShulcz 3d ago

writing it at the moment you reject it beats reconstructing it from logs later. main catch i hit with a flat decisions file is getting the agent to append without a nudge, and pruning stale lines once a constraint stops being true. do you keep one per repo or reset it per task?

1

u/iFun4ik 3d ago

one per repo, append-only, sits next to CLAUDE.md. per-task notes get wiped, but the rejected stuff is exactly what stops it retrying thone per repo, append-only, sits next to CLAUDE.md. per-task notes get wiped, but the rejected stuff is exactly what stops it retrying the same dead end next weeke same dead end next week

1

u/VShulcz 3d ago

keeping the rejected stuff per repo is the part that actually pays off. one git trick if you run parallel branches: put merge=union on that file in .gitattributes so two branches appending to the bottom stop colliding.

1

u/iFun4ik 2d ago

oh nice, didn't know merge=union. two agents on parallel branches clobbering that file is exactly what bit me last week, stealing this šŸ™

1

u/AgentYurt 2d ago

That split matches what I've seen too — the narrative survives, but the exact commands and the reasons behind a rejection are the first things to go.

What helped me was writing the rejection down at the moment it happens, not reconstructing it later: one line in a per-repo decisions file, in the form 'Tried X, dropped it because Y, revisit if Z.' The 'revisit if' part is what stopped me treating old rejections as permanent and re-arguing them a month later.

I also do a short pre-compact checkpoint in the same file — current goal, what's done, what's next, open questions, rejected approaches — then after /compact I ask the agent to restate that checkpoint in its own words. If it can't, I know the summary lost something important before I keep going.

Are the decisions you're losing mostly implicit ones buried across turns, or explicit rejections that the summary just smooths over?

1

u/VShulcz 1d ago

Both, in different ways. Explicit conclusions usually survive (132 decision sentences in that corpus), just without the command or error behind them. What vanishes outright is a one-off rule from turn 1: on a 16-turn test with "run tests only through ./check.sh", the agent ran go test right after /compact. Your "revisit if Z" line fixes something raw logs miss too, since transcripts only show why you dropped something, never when it's safe to retry.

1

u/AgentYurt 1d ago

That one-off rule example is the one that stings — a rule from turn 1 is exactly the kind of thing I'd assume survived because the decision did.

What I've started doing is keeping those rules in a separate short list at the top of the same file, apart from the decisions: just the rule and the command it maps to, like 'tests only through ./check.sh'. Then the pre-compact checkpoint is the agent restating those rules back before it runs anything, not just the goal. If it can't name the rule, I stop there instead of finding out after it ran the wrong command.

Do the lost rules tend to be ones stated once early on, or do they also drop when they're repeated later in the session?

1

u/VShulcz 1d ago

Didn't measure once-stated vs repeated rules head-to-head. Turn-1 rules dropped first in our runs, especially past a second compaction once the opening prompt is buried. Later items still slip though: across 189 real compactions, summaries dropped 75 #N items that were still open on GitHub. Splitting rules out from the task list fixed it here too, and restating them catches stale ones.

1

u/AgentYurt 1d ago

That 75 dropped items still open on GitHub is the number that sticks with me — the summary wasn't just trimming, it was quietly closing work. And the second-compaction point matches what I've seen: the first summary keeps the shape, the second one starts dropping whatever nobody restated. I like treating the restatement as a check rather than a ritual — make the summary prove it still knows the rules. Were the dropped items mostly the ones listed later in the task list, or was it more scattered than that?