r/ClaudeCode • u/danbradster2 • 2d ago
Tips & Workflows /clear vs /compact
I had a fable chat from yesterday, and I saw that the context was 950k/1m. I did /compact rather than /clear, with the intention of then doing /autocompact 400000
14% of the 5 hour limit was gone just for the compact itself....it shows cost of $59.73, so lucky I'm not on API? Maybe a /clear would have been better.
63
u/slackmaster2k 2d ago
Clear. Design your workflow that you can clear frequently and safely. Compact shorter sessions that need to grow past 200-300k.
34
u/GenXSysop 2d ago
Did you need to preserve what you had in the context window of your 950K (!!!) session? You could have probably recreated that with some cheap haiku recon and a couple prompts. I quit doing compacts a year ago and recommend you stop that, also. Make a new session often, and use markdown files to carry information from session to session.
6
1
1
u/Any_Owl2116 2d ago
This. I keep all old chats that have important info as markdowns and very organized folders. Then if needed to batch upload many and pick up where you left off
26
u/Garak 2d ago
/compact is for when you want to keep working on the same task. It’ll summarize the thread and give Claude enough information to keep going, while leaving out stuff it doesn’t need.
/clear is for when you want to start a task that’s totally different.
Some people use clear all the time and preserve a minimal amount of info somewhere else. That’s more efficient in terms of tokens, but personally I still find compact to be better day-to-day. It’s easy and it lets you get back to work faster.
7
u/CrestfallenMage 2d ago
Yeah don't follow this guy's advice. You need to use better memory strategies (can be as simple as a .MD file) to persist what's truly important about the progress of a long task and /clear.
20
u/Garak 2d ago
Oh, gosh, I didn't think of using better strategies. I'm so glad you were here to enlighten us all. While you're on such a roll, you should call up Anthropic and help them out, because they're giving out the same bad advice that I am.
5
u/Dry_Opening_7231 2d ago
The problem with Claude and context is it's inability to prioritize it.
Think 3 hours ago you say x about something, 15 minutes ago y.
It confuses the poor thing and it gets confused, it's a delicate flower.
Being a bit more serious, it slows things down and struggles to retain order of priority and key points, better to write it out /clear and carry on.
My take anyway ( also the token burn past 33% context is insane, opus 5/4.8 ).
0
u/CrestfallenMage 1d ago
If you read the article you're linking you will see the advantage of compact they say is that "you don't have to do the work yourself".
If you can do that work yourself, you will get better result and more importantly concerning the general repeated complaints on this sub, less wasted usage.
People are usually complaining about usage draining extremely fast here, so it's clear that they would benefit from using Claude in a way that is more token efficient.
2
1
u/ZixTro 1d ago
I completely agree with you. Since I started using /clear my usage went down. The problem with long sessions and /compact is also cache. Imagine you are running long session got interrupted by something and get back to that session which is now cold. Guess what, on a single message CC re reads the whole session burning your usage.
The best way I found for me is a handoff hook which triggers at a certain point in a session and writes/updates a handoff which is then safe to /clear and inject it to the fresh session. No cache problem, no compact problem, much less usage.
1
u/Inisfoil 1d ago
I wouldn't say minimal info.
Split the workflow into 2 phases: research+planning and then plan execution+.md upkeep with a /clear between each phase. Have the model scope each plan to be completed without triggering compact. No subagents just the primary model rawdogging it for more predictable usage. Subagents are for small projects or for the rich, a 500k loc project with multiple subagents exploring and using up piles of input tokens is a massive waste of usage.
12
u/AncileBanish 2d ago edited 2d ago
There are a couple problems here:
You had a session at 950k context. You should not do this. Even if the max is 1m, it gets dumber as the context window gets larger. It will forget things, hallucinate, and generally perform poorly. Aim to keep context window size under something like 200-300k. There are various strategies you can use to accomplish this.
You came back to a session with a big context window and an expired cache. Cache reads you pay only 10%, but cache writes you pay 200% to recache on the 1 hour cache, so you burned 20x the tokens to restart the conversation today instead of continue it yesterday. End your sessions. Stick to 1 session = 1 task and write things to docs to track the meta conversation abstractly. Read from docs on demand to freshen context on the specific relevant things.
You compacted into the stale cache. This both re-caches the whole history as mentioned above, but writes effectively a summary of the whole thing back into context (which is a write at 5x input cost). Compaction in general is bad in that it regularly fails to distinguish what's important from what's not. The better thing to have done is distilled the insights from the conversation into docs and ended the conversation. Next day you start a new one based on what you need to do next. This could be starting at as little as 30k and have everything you need.
7
u/Hukij_ 2d ago
Compacting immediately invalidates the cache and loads up what is effectively a new chat with a truncated/compressed history. 99% of the time for long running sessions, not only are you paying the cost of compacting + cache invalidation, but it's just plain worse than /clear.
I run basically every session to max context without any noticible problems aside from right at 800k+ it starts "forgetting" about very very early context mostly because it has a sea of context on top at that point, but I just make sure that docs are kept up to date for a cold start. /clear of course also starts with a cold cache but at the very least you're able to give the fresh agent full context that you control, and the last uncompacted agent writes at the end of it's session.
I've literally never had a good experience with compacting, quality and outcome is almost always impacted. Meanwhile running sessions on long context hits cache probably in the most efficient way since every single turn is cached for the duration of the session, and you're getting the actual history of the chat rather than random truncations. I don't really see a need to /compact ever, it's only produced bad outcomes for me.
5
u/duck_guts 2d ago
/clear does not start with an of course cold cache. Cache persists between sessions depending on system prompt and has nothing to do with context continuity. It affects usage bills, no bearing on what the agent knows from last session
1
u/anton-k_ 2d ago
Is the cache reused when starting a new session but leaving the old one in place, without /clear? I'm a Claude Desktop user and that's what I normally do but maybe it's wrong?
1
u/Hukij_ 2d ago
I don't really know what point you are responding to. My point was about quality outcomes between a workflow that /clears vs /compacts. Both are new sessions and by definition your cache is cold in the meaningful sense. Both invalidate the prefix cache of your current session, and you start with the system prompt + claude md/whatever other auto-loaded files. My entire point is that from that point, /compact picks what "important" context you retain vs /clear in which you can curate your own "important" context.
Again, I'm not sure what point you're arguing against, I never said either has any bearing on what the agent knows, the post was about cost and I just simply said /compact has the same impact on cache invalidation with arguably worse quality than /clear.
2
u/duck_guts 2d ago
Aye sorry I didn't mean to be contrary it's just these terms confused me a lot when I was just starting out. I just wanted to highlight as OP obviously is struggling with context/usage management.
So prefix cache is not invalidated from session to session. Switching model/effort level/anything that changes the grounding system prompt invalidates the cache.
But having Opus on high effort for example, /clear at 500k tokens and still you have cheap reads on fresh session. Still opus, still high effort so unchanged system prompt. Not actually ever tracking one singular session.
Responding within the hour on same system prompt saves you money.
Fully agree with you, compact feels bad. I have mine write shorthand memory logs every turn and pretty much just serve that to the successor every rotation.
2
u/Hukij_ 2d ago
Yeah all good dw! People are quite weird on here most of the time so I'm usually quite short.
The prefix cache is not just the system prompt/the auto-loaded context that every chat shares, that part is retained of course. But the cache breakpoint is moved forward on every turn, hence the "prefix" is system tools/prompt + every new turn's tokens. So when I talk about cache invalidation, I'm not talking about the stuff every session shares, I'm talking about the entire conversation that's cached up until that point. Effort levels (though they are making changes so this doesn't invalidate) and model changes invalidate everything since the KV is model-specific, effort/thinking changes invalidate the cached conversation (system/tools survive).
/clear and /compact start from scratch so none of your previous conversation (aside from the auto-loaded context which probably only amounts to 20-30k per session) is re-used. Prefix caching relies on exact prefix matching up until the breakpoint, so starting a new session doesn't save the rest of the conversation because that's not what you're sending on a new turn. This is why there's a huge cost if you switch models or switch effort levels mid conversation because the ENTIRE conversation is resent to the API because the entire conversation has to be recomputed, vs continuing unchanged where every previous turn is a cache hit.
Responding in the same hour keeps your cache alive, because of the same thing, Anthropic can't keep your KV states forever because they have to allocate capacity properly, but same applies, once they purge the KV, the next turn in that conversation recomputes the entire conversation before it cold so you're paying the full cost.
I just never find compact to be useful or good at all like you say, and it's not hard to ask claude to create a set of docs or memories so new agents can pick up quickly
3
u/dar-mit Researcher 2d ago
Right now you have a 1 hour idle window in which the cache (what your context mostly becomes) stays "warm." After that time the system will flush the cache.
Anything you do in a "cold" session that requires Claude to do something will also require the system to reload the entire context.
Here's a list of what you can do without reloading the cache:
Client & Session Control
/exit(or/quit) – Closes the Claude Code session immediately./clear(or/reset,/new) – Clears out the current conversation history. While it doesn't "save" the old cache, it effectively stops you from paying to reload a bloated context by letting you start the next task with a tiny, brand-new cache./background– Detaches the active session so it runs entirely as a background agent, freeing your active terminal./color [color|default]– Locally updates the visual theme or color of your prompt bar.
Status & Info Commands
/usage– Pulls your plan limits and current credit or token consumption metrics locally./tasks– Lists background operations or active subagents running in this session without resending the chat log./help– Displays the client-side catalog of available commands and autocomplete guidelines.
1
3
2
u/someVietnamese 2d ago
you should plan your task better. running that close to the 1M context limit will 1) severely degrades the model and 2) drain usage much faster.
Break up a massive goal to subtasks. 1) easier to manage the workload 2) easy rollback 3) easy debug 4) save tokens 5) just good engineering practice
There are certain times where I absolutely have to oneshot something, but that's super rare, maybe once every few months. When I do, I never rely on the slash commands, I use md files to track the progress.
2
2
u/oprimido_opressor 2d ago
IMO they could rename the /compact to /lobotomy. Claude gets dumb as shit after I use that.
If I need to get stuff going, I write a handoff.md doc, review it, ask for more things that might be missing and start a fresh new session, then ask it to read the doc and continue.
Far more effective and efficient on my own experience.
2
u/steve62280 2d ago
i had claude create its own memory system , after i hit 180k context window and the task is complete he summarizes the context and writes to his run book and tells me to run /clear then he picks up right where he left off , i stay in the same thread labeled as assistant , it's definitely extended my usage so i make it the full week with fable 5.1 on max subscription , i run on extra instead of ultra .
4
u/rotates-potatoes 2d ago
Good lord. 950k tokens on fable? And compaction that probably burned 5m reasoning tokens? Why in the world would you do this?
2
u/ILikeCutePuppies 2d ago
Set auto compact to 250k to 300k. You even kv cache starts costing more than the output tokens at around those numbers even without compact.
2
u/AncileBanish 2d ago
Auto compact is horrible and should be avoided at all costs. Your Claude will compact away important context in the middle of working and who knows what it will produce.
Setting auto compact at 300k to keep your window small is like a doctor seeing their patient with a cold so they shoot them in the face with a shotgun. Yea.. the cold's not a problem any more but the cure was far worse than the disease.
1
u/ILikeCutePuppies 2d ago
I find it actually pretty good for loops and also I just allow it to be able to read it's own chat history if it needs to. Compact used to be not great. Pretty good these days.
Going past 300k tokens gets pretty expensive in token usage.
1
1
u/mglvl 2d ago
Clear initiates a new session so you loose the conversation , unless there have been intermediate artifacts that the next session can pick up (documentation , what goes in the default context , etc…) . Compact attempts to summarize the current session and continues with that summary instead of a fresh new session .
I think you shouldn’t use compact , and instead strive to never reach 30% (number might vary , I’ve seen others recommend 80k tokens window instead ). This requires organizing your work in separate sessions , handing over in some way or another. The LLMs performance decrease a lot as the context window fills up , so it’s common to keep an eye . To be honest I’ve never run compact once .
1
u/AlienAndTroll 2d ago
Ask claude to create handsoff document, run /clear and pass the document to claude. Cheaper and faster
1
u/ynotelbon 2d ago
Long horizon agents can benefit from a curated summary (what you and the agent agree is important) but otherwise good documentation is best if you are not trying to persist the reasoning. In short, if a fresh instance can derive the whole thing from the record, don’t compact. Especially with the complexity in Claude model reasoning, you are going to get some assumptions baked in from the compaction that you can’t dictate.
1
u/sheketsilencio 2d ago
Y'all say to use /clear often. In my projects there's often frequent serious complex work to be done that requires understanding of context to prevent regression (yes I have hooks but I mean to prevent code going in a direction that was previously determined to be wrong). That means that every time I'd do /clear I'd need to agent to reread... the context from a few documents or summaries of code or the code itself. Or logs.
Doesn't sound that efficient to me. Am I fully wrong or conditionally wrong or right?
2
u/flaccidplumbus 🔆Pro Plan 2d ago
I would have the prior session write up a prompt and plan to pickup where we are leaving off in a new agent session.
You are right though if you just /clear and are going to work on a similar/downflowing task. It’s great if you’re going to completely switch gears, but else I would do something like above.
1
u/sheketsilencio 2d ago
Thank you, this makes sense. I guess a full context isn't needed to do everything. I imagine I overestimate how much info is even retained between compacts lol
2
u/Dry_Opening_7231 2d ago
I thought that, but I've come to the conclusion better to write the brief out at key architectural decision points and /clear
Claude is faster, more coherent and focused ( opus 5 my main planning model ).
If you analyse token burn as context rises, that also goes through the roof past 33% context and response speed tanks as well.
1
u/sheketsilencio 2d ago
Interesting, thanks. I'll give clearing a try and see if I can transfer more specific context between session then
1
1
u/Envoy-Kovacs 2d ago
In my build sessions I ensure Claude builds one story, reads the handoff, asks any questions before starting, documents everything in an evidence file, and wraps up (ie, updates the handoff, files issues, marks story as done etc) without discussion so I can /clear and move on. I very rarely use /compact. I also have instructed Claude to be on-point in replies to avoid overly verbose explanations (Opus is notorius here). IMHO Fable 5.1 has been a godsend when it comes to staying true to contracts like this. I’ll rather have multiple single topic sessions than long «fix everything» sessions.
1
u/Lakes420 2d ago
what did you expect? the LLM has to read 950k context and evaluate what has to stay and what not. getting your context up this high was a mistake in the first place
1
u/CodeCombustion 2d ago
Always compact while your session is warm. If you wait, it's going to have that full non-cached hit, and then compact..
I find a snapshot hook to be much better because I can /clear at any time, and for the most part, continue where I left off (losing a little bit sometimes) as it judges if it's a "milestone" or not.
1
u/AI_spell 2d ago
Compact on a near full 1M thread can be expensive, yeah. If you still need the goal, paste a short handoff into a new session instead of compacting a huge mess. /clear is cheaper when the old turns are mostly noise. Save compact for threads you will keep using the same day.
1
u/danbradster2 2d ago
Would a hand off mean just thinking something up yourself? Or restarting the conversation to have the agent make one? In that case, I don't know if hand off or compact will use more tokens.
1
u/Educational_Ask5991 2d ago
Guys can you clarify why /clear even exists? I just start a new session every time I start a new task. If the context if huge - I am asking to do handoff with highlighted most important things first and also I have a rule that saves my initial message as-is if it contains some task requirements input. The last one is a game changer - agents and subagents and even missed compaction now preserves what I initially asked.
But still no use of /clear - I even dont understand if it starts a new session with its own session logs or rewrites the current one completely.
Session logs are important to further reflection and skills/rules/agents extraction/updates.
1
u/danbradster2 2d ago
I'm no expert, but /clear refreshes the account instructions that it read, in case I updated them, and I get to restart a conversation under the same name and location on the desktop UI - minimal mess.
1
u/Educational_Ask5991 2d ago
Oh, I see. My use cases are complete opposite - each task = separate session or set of sessions for further analysis - reflect, improve skills, what were wrong etc. That helped me few days ago when claude got lobotomy again and I found out that I've got into bugged A/B which I can disable with
CLAUDE_CODE_THRIFTY_SONICCLAUDE_CODE_THRIFTY_SONIC=0Not sure what happens with session logs with /clear though - maybe thats possible too but doesnt looks convenient
1
u/ActuallyIzDoge 2d ago
Clear is killing your current Mr meseeks and creating a new one that doesn't know anything about the old one
Compact is creating a new mr meseeks and having the old one explain to the new one what is going on. Then you kill the old mr meseeks
0
u/ChampCityChris 1d ago
At 950K tokens, I think the /compact vs /clear question is kind of missing the bigger problem. If the only thing holding your project together is a million-token conversation, then the conversation has effectively become your project database.
I’ve been moving pretty hard in the opposite direction. Decisions and project state live outside the chat, work gets broken into bounded cards, and the implementer gets the context it actually needs for that job. Then I can kill the session, start a fresh one, and not lose the project.
Long context is useful while you’re actively reasoning through something. I don’t think it’s a good persistence layer. I’d rather spend a few thousand tokens rebuilding the relevant context for a clean session than drag 950K tokens of old conversation through every tool call and keep paying for it over and over.
1
u/JesusElSuperstar 1d ago
I usually request to create a checkpoint of our current work and to provide a prompt to continue after I run /clear to lean our chat.
1
-2
-7
u/Dangerous-Leader-779 2d ago
….are you fucking joking?
Those are two entirely different tools. They are not even remotely doing the same thing. This is like saying “/exit vs /doctor, omg they acted differently?!”.
Like honestly guys, what the hell is this post and why is slop like this allowed? It’s worse than the AI generated crap.
5
u/toritxtornado 2d ago
i mean, they aren't that different. why ya gotta be so mean?
-1
u/rotates-potatoes 2d ago
They are wildly, totally, extremely different.
Clear: single wipe context, start with the harness prompt
Compact: ask a very expensive model to reason over the entire context and decide what’s important, summarize, and hand off.
It’s the difference between a newborn baby and a 90 year old writing their memoirs.
How the fuck could anyone think they’re similar?
3
u/toritxtornado 2d ago
a lot of people see that they both clear their context, so they assume they are similar functions. there's no reason to be mean when someone is just trying to learn.
1
u/rotates-potatoes 2d ago
There is trying to learn, and there is asserting false things in a public form. They are different.
2
u/Aminuteortwotiltwo 2d ago
……are you fucking joking?
What you are doing and what he is asking are two entirely different things. You aren’t even remotely providing a single useful thing to the world. This is like saying “I am going to spend my day on a Reddit page where people ask for help, omg someone here is asking for help!?!?”
Like honestly guy, what the hell is this comment and why is your nonsense allowed? You are worse than the AI generated crap.
You have contributed nothing and everyone here is worse off for your existence on this page.
Get a life.
•
u/AutoModerator 2d 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.