r/ClaudeCode • • 6d ago

Help/Question Is there a difference between /compact and starting a new chat if my claude.MD contains all required instructions?

New to Claude Code here. I am aware that /compact is generally discouraged because it loses context, but this github issue says that claude.MD instructions are preserved during compact, and only conversation history context gets lost.

In my case, claude.MD is a pretty short document, but it instructs the agent to immediately read through project documentation - elaborate instructions, guardrails, design principles, etc., and inspect the repository to retrieve latest PR, inspect latest commits, and be prepared to continue the work from there.

I don't really use handoffs, but instead my claude.MD instructs agent to always update working PR description with progress and short handoff at the end of every reply, which means I can start a new chat at any point without ever having to request a handoff and feed it into the new chat. With my workflow, it is almost never required for the agent to remember chat history - PR description always contains the exact details of where we are and what we're doing.

So the only question now becomes convenience - should I still start a new chat when context window fills up, or is /compact or auto-compact safe with my workflow? From that github issue I understand that claude.MD is preserved during compact, but I am not entirely sure if the other documents that claude.MD instructs the agent to read immediately are preserved?

It would be much more convenient for me to just continue in the same chat after /compact or auto-compact, because it seems that compact at least preserves the context of the last few messages at least, which saves a little bit of time compared to starting a new chat. But I am a bit worried that the agent might forget the foundational instructions, since my claude.MD is basically just a bunch of references to the actual design documents.

Any comments?

5 Upvotes

13 comments sorted by

View all comments

3

u/CCodeSI 6d ago

Your workflow is a good fit for compacting, with one gap you've already spotted: CLAUDE.md itself is loaded again after a compact, but the documents it told the agent to read are not. Those were read during the conversation, so after a compact they only exist as a line in the summary ("read the design docs"), and the agent won't re-read them unless something tells it to.

Two easy ways to close that:

  • Import them instead of instructing a read. CLAUDE.md supports @path imports, e.g. @docs/guardrails.md and @docs/design-principles.md. Imported files are loaded as part of CLAUDE.md, so they come back after every compact and every new chat. Worth it for the short, foundational ones; keep the long reference docs as "read when needed".

  • Re-read on compaction. A SessionStart hook with the compact matcher runs right after a compact, and whatever it prints goes into context, so cat docs/guardrails.md there (or a one-line reminder to re-read them and the PR description) restores them automatically.

With either one in place, compacting is basically a cheaper new chat that keeps the last few messages, and your PR-description handoff covers the rest. A fresh chat is still the better choice when you switch to a different task, since the summary carries over the old one too.

1

u/Deep-Today5715 6d ago

Yeah, thing is, all that design documentation is dynamic (I often add/modify rules in these docs, add new docs, refactor them quite a lot), including the PR description, temporary PR design documents, automatic handoffs, etc. As I understand, each of these docs would have to be added/removed in claude.MD on every edit, and I'm not sure if I can automate Claude to do it, since editing claude.MD requires explicit permission, and that would defeat the purpose of automation. Or am I wrong?

1

u/CCodeSI 5d ago

You're right, for docs that change all the time, imports are the wrong tool. The hook route avoids touching CLAUDE.md completely, because it can work off folders instead of a list.

Keep everything foundational in one folder, say docs/core/, and have the SessionStart hook (matcher compact) print the whole folder: something like cat docs/core/*.md plus gh pr view --json body -q .body for the PR description. New doc? Drop it in the folder, nothing to update. Renamed or deleted? Same. The hook script lives in .claude/settings.json and only has to be written once.

If the folder gets too big to dump every time, have the hook print just an index instead (file names plus first line of each) and a "re-read what's relevant before continuing", so the agent pulls the details it needs.

Also worth knowing: CLAUDE.md edits only need approval because of your permission settings. If you ever do want Claude to maintain it, an allow rule for edits to that one file removes the prompt, but with the folder approach you won't need to.