Get a demo — 30 minutes →
← Back to blog
Anomity robot illustrating Claude Code Session Efficiency: What Cost Optimization Does to Your Audit Trail
Research

Claude Code Session Efficiency: What Cost Optimization Does to Your Audit Trail

TL;DR
  • Anthropic published "Maximizing the value of your Claude Code sessions" on August 14, 2026, by Lydia Hallie. It is cost guidance: no CVE, no vulnerability, no incident, no security claim.
  • The advice is sound. Run /clear between tasks, set model and effort before you start, @-mention files, add quiet flags to noisy commands or run them in a subagent, run /context in a fresh session, /compact before a break.
  • Every one of those practices narrows what is inside the session at the moment work happens - which is the point, because per Anthropic "nothing gets sent just once" and cost scales with what is in the buffer.
  • None of it deletes anything. Per Claude Code documentation, sessions are saved continuously to local JSONL transcripts under ~/.claude/projects/ and survive /clear; /resume brings one back. What /clear resets is the model's in-context working buffer.
  • That transcript is still a poor chain of custody: Anthropic warns the format "is internal to Claude Code and changes between versions", and CLAUDE_CONFIG_DIR, cleanupPeriodDays (30-day default) and CLAUDE_CODE_SKIP_PROMPT_HISTORY all sit in the operator's own settings.
  • A vendor-side record exists - Compliance API coverage for Claude Code CLI and desktop, generally available August 26, 2026 - but it is Claude Enterprise only, and the beta announcement excluded Claude Code on the web, the Claude Platform, Bedrock, Vertex AI and Microsoft Foundry. Session-local context is a working buffer, not a record of custody.

Anthropic published a guide to Claude Code session efficiency on August 14, 2026: "Maximizing the value of your Claude Code sessions", by Lydia Hallie. It is cost guidance: no CVE, no vulnerability, no incident, no security claim - and on the engineering merits it is right.

Claude Code session efficiency and session forensics pull on the same rope. Every practice in the guide changes what sits in the model's context while work happens: /clear and /compact reset or rewrite the working buffer, a subagent does the noisy work elsewhere and returns only its answer, MAX_THINKING_TOKENS=0 drops the reasoning trace, and CLAUDE.md carries a team's daily commands with the repository. The mechanism is in how Claude Code works for security teams.

None of that is a flaw in the advice. It is the reason an audit trail cannot live inside the session.

What Anthropic actually published on August 14, 2026

The framing is not a request to use Claude Code less:

Being efficient with tokens doesn't mean using fewer of them overall. It means making sure the ones you do use go towards the thing you actually asked for.Anthropic, "Maximizing the value of your Claude Code sessions", August 14, 2026

The TL;DR is six bullets, every one a habit worth having:

  • Run /clear between tasks.
  • Set model and effort level before you start.
  • @-mention files instead of naming them.
  • Add quiet flags to noisy commands, or run them in a subagent.
  • Run /context once in a fresh session.
  • /compact before you take a break from your keyboard.

Our Claude Code commands cheat sheet covers /clear, /compact, /rewind, /context, /model, /effort and /mcp. Caching, compaction, rewind and subagents are all longstanding behavior, so this consolidates cost guidance rather than announcing a feature. The per-developer spend figures that circulate alongside it are Anthropic's own and live in the Claude Code cost documentation, not in this post: around $13 per developer per active day, $150-250 per developer per month, and below $30 per active day for 90% of users.

Why Claude Code session efficiency is really context management

Three things decide the price of a token: which model runs, whether it is input (prefill) or output (decode), and whether it was cached. Output costs roughly 5x input; cache reads cost 0.1x input and writes up to 2x, but a write happens once while the cheap reads happen every turn after. The line that matters for forensics is about accumulation: "nothing gets sent just once. Everything that ends up in the conversation, a file Claude read or the output of a command it ran, gets sent again on every turn after it, for the rest of the session."

So cost scales with what is in the buffer, and every efficiency lever is a lever on the buffer. The cache matches an exact prefix - tool definitions, system prompt, then the conversation with CLAUDE.md at its front - so /model, /effort, fast mode, /compact and elapsed time all throw it away. Expiry is an hour on a subscription and five minutes on an API key, and per the documentation five minutes for subagents, forks and compaction even on a subscription.

The post ends with "Where to look first", published as a graphic rather than body text. Its four labels, in Anthropic's order, and what each one does to the session:

  • 1. Long sessions - "every turn re-sends everything before it". Pressure toward shorter sessions: more resets, more boundaries to stitch across.
  • 2. Too much in the context - noisy command output and "leftovers from the previous task" get re-sent every turn. That output is what a forensic record wants most.
  • 3. A bigger model or higher effort level than the task needs - "both settings stick between sessions", and effort is part of the cache key, not the prompt text.
  • 4. Breaking the prompt cache - changing model, effort or fast mode mid-conversation "prefills the whole conversation again at full price".

Read as an architecture document rather than a cost one, that list says spend is minimized by keeping the working buffer small, fresh and stable. Correct engineering, and exactly why the buffer is a poor place to keep evidence. The broader version is in the Claude Code harness as an attack surface: the session belongs to the tool, not to your governance program.

What /clear and /compact actually reset

The intuitive reading of /clear - that it wipes the session - is wrong. Per Claude Code documentation, sessions "are saved continuously to local transcript files as you work, so you can return to one after exiting or running /clear", and /clear "saves the previous conversation; resume it with /resume". It resets the in-context working buffer, not the file on disk.

/compact rewrites rather than resets, and does not preserve a session evenly. Per the documentation, project-root CLAUDE.md, unscoped rules, auto memory and the plan-mode plan are re-injected from disk; files Claude read or edited come back as "up to five, most recently modified first"; skill bodies are capped at 5,000 tokens each and 25,000 in total; and "Context that hooks added earlier" is summarized away. Those priorities exist to make the next turn work. /rewind is the better small rollback: cheaper, and a truncation to a known prefix.

So if your record is the conversation, compaction is a retention policy written by a summarizer. That is why tool calls alone are not an audit trail, and why our CISO guide to auditing AI agent activity starts from an out-of-band event stream keyed to real actions instead.

Subagents move the noisiest work out of the main transcript

The advice for noisy jobs is to run them in a subagent, and the boundary is described precisely:

A subagent gets its own context window, with its own system prompt, the tools, and your CLAUDE.md, but not your conversation. It runs its own turns, and the only thing that comes back to the main session is its answer. Everything else is thrown away once it's done.Anthropic, August 14, 2026

The post adds its own caveat: "the main session only gets back what the subagent chose to report." That is not a claim that subagent activity is invisible. Per Claude Code documentation the subagent's call and its returned result append to the parent conversation; what does not come back are its own intermediate turns - tool calls, file reads, command output. Subagents are also where high-privilege work lands, because that is the work that is noisy.

So the investigator's sentence is: a subagent was asked to do X and reported Y. Whether it read six files or sixty is a question for something outside the conversation - the fleet-side artifacts in auditing Claude Code across a fleet, which persist on the endpoint whatever a session kept. Systima's controlled benchmark "The Subagent Tax", July 22, 2026, measured fan-outs at 2.6x to 5.9x the input tokens of the same task run sequentially. That is a cost result rather than a security one, and it cuts the same way here: a fan-out multiplies exactly the turns the main transcript never keeps.

The settings that persist, and the reasoning trace that does not

Two levers change what a session is without appearing inside it. /model and /effort both persist into the next session - "the level you pick with /effort sticks around as your default" - and neither is part of the prompt text, so a session that ran on a different model than anyone assumes does not say so in the conversation. A third, MAX_THINKING_TOKENS=0, is scoped by Anthropic to one session of "grunt work" and does not apply on Fable 5. Take it as a reminder rather than a warning: a reasoning trace is a model output an environment variable removes, so an incident process that depends on reading an agent's stated reasoning was never resting on a control. The pattern is not confined to Anthropic's guide: the settings that decide how an agent behaves keep moving out of the conversation and into the environment around it, and new Claude Code features in 2026 and their security implications tracks the ones a security team has to know about.

CLAUDE.md is a config surface that travels with the repository

The context advice pushes work into files: put the two or three commands you run every day into CLAUDE.md with the quiet flags in them (npx vitest run <file> --reporter=dot is the worked example), use the documented hook that rewrites noisy commands before they run, and keep "CLAUDE.md to specific instructions and move workflow-specific ones into skills, which only get loaded when they're used".

Be precise about the mechanism. CLAUDE.md is not executed and does not run commands; it is instruction text the model may act on, and hooks are the executable surface. But it is committed to a repository, so the commands a team's agents habitually run arrive with a clone or a pull request - and it is read once at session start, so a mid-session edit does not apply until the next /clear, /compact or restart. That surface is already attacked: the Shai-Hulud "here we go again" npm worm planted Claude Code hooks across at least 868 packages by Aikido's count, with OX Security reporting 440+ and SafeDep 1,684 poisoned versions across 420 package names - every published figure is a floor - and AWS Kiro rewrote its own mcp.json from hidden text on a web page. What we find scanning AI agent configs is the base rate.

Moving instructions into skills relocates that surface onto the endpoint rather than removing it. The control that does not depend on operator discipline is managed settings - see deploying Claude Code across a fleet.

The transcript was never the audit trail

Which records of a Claude Code session exist, and who controls each:

RecordWhat it holdsWho controls it
Local JSONL transcript (~/.claude/projects/<project>/<session-id>.jsonl)One JSON object per message, tool use or metadata entry, written continuously and surviving /clearThe operator: CLAUDE_CONFIG_DIR, cleanupPeriodDays (30-day default), CLAUDE_CODE_SKIP_PROMPT_HISTORY
Anthropic Compliance APIPrompts, responses, tool call content, skills and artifacts as transcript text, plus verified user, session and message IDsClaude Enterprise with an existing Compliance Access Key
OpenTelemetry exporterCache read and creation tokens per user and sessionYour platform team. Counts, not artifacts
SessionEnd hook with transcript_pathWhatever you archive when a session endsYou, only if it ships as a managed setting
Endpoint artifact and decision recordArtifacts added, changed or removed, plus allow / deny / log decisions at the tool boundaryYour security team, independent of any session

Two things follow. The local transcript is a real record and a bad chain of custody: Anthropic warns its format "is internal to Claude Code and changes between versions", and all three sit in the operator's own settings - one sets retention, one moves the store, one suppresses the writes. The Compliance API is the genuine out-of-band answer for what it covers - announced August 11, 2026, generally available August 26 - but it needs Claude Enterprise, and the beta announcement scoped it out of Claude Code on the web, the Claude Platform, and Bedrock, Vertex AI or Microsoft Foundry sessions, which the GA note does not restate. Auditing AI chat and streaming interactions covers that record in depth.

The third route is documented and rarely deployed: hooks receive a transcript_path, and SessionEnd hooks run when a session ends, for cleanup and logging - enough to archive the transcript yourself, at a boundary the conversation does not own. It is worth something only when pushed as a managed setting, and it has to fit the 1.5-second default budget every SessionEnd hook shares. See how Claude Code hooks work and how permissions actually work.

What Claude Code session efficiency changes for an investigator

Four questions an incident lead asks, and where each answer now lives:

  • What did the agent run? Not reliably in the conversation. Output over 30,000 characters goes to a file with only a preview left inline (BASH_MAX_OUTPUT_LENGTH), quiet flags trim the rest by design, and a subagent returns its answer rather than its turns.
  • Which files did it touch? After a compaction, up to five, most recently modified first. @-mentioning changes nothing: it removes the Read call, and "the file itself takes up the same room in the context either way".
  • Under what settings? Model, effort and thinking budget are not in the prompt text, and model and effort persist across sessions as defaults.
  • What changed on the machine? With MCP tool definitions deferred by default on supported models, a server connecting or disconnecting only appends content and does not disturb what is cached. Where tools do load into the prefix instead, a mid-session connect or disconnect is the most common cause of an invalidation.

Every answer is endpoint state or an event at a boundary, which is why behavioral baselines built from observed endpoint activity hold where transcript reading does not, and why "we will read the session back" is not a plan. See the AI agent incident response playbook and securing AI coding agents and CLIs.

How Anomity keeps the record when the session does not

The workflow is deliberately independent of what any session kept:

  1. Inventory the artifacts, not the conversation. An unprivileged Endpoint Sensor for Windows, macOS and Linux inventories eight AI artifact types per endpoint: AI agents, MCP servers, extensions, plugins, skills, secrets, hooks, and CLIs. CLAUDE.md, hook definitions and MCP config are files on a machine, so /clear does nothing to them. See what Anomity covers.
  2. Decide at the hook. Where an agent exposes one - Claude Code's PreToolUse is the concrete case - Anomity returns allow, deny or log before the call runs, and records that decision whether the call came from the main session or a subagent.
  3. Keep a trail that outlives the session. A queryable 90-day audit trail of every AI artifact added, changed or removed, plus those hook decisions, routed to your SIEM, Slack, email or Jira. Queryable includes from inside the assistant: the Anomity MCP server exposes that trail read-only, so an investigator can ask what changed and when without the conversation being the record.

Two honest limits. Anomity is metadata only: no prompts, responses or reasoning captured, and secrets redacted on the endpoint, so it is not a substitute for the Compliance API when you need conversation content. And there is no enforcement where an agent exposes no hook, and no visibility inside a vendor's cloud. SOC 2 Type II, and it complements Network, EDR, DLP and GRC rather than replacing them.

Where this leaves you

Follow Anthropic's advice: /clear between tasks, keep the context small, put the quiet flags in CLAUDE.md, push noisy jobs into a subagent. Then stop treating what is left inside the session as the record of what happened, because the logic of the guidance is that a cheap session is a small one. Decide where your out-of-band record lives - a SessionEnd archive as a managed setting, the Compliance API where it reaches, an endpoint-side artifact and hook-decision trail for the rest - before an investigator has to ask. Book a demo if you want that record on your fleet.

Frequently asked questions

Does /clear delete a Claude Code session?

No. Per Claude Code documentation, sessions "are saved continuously to local transcript files as you work, so you can return to one after exiting or running /clear", and /clear is described as "start fresh with an empty context. Claude Code saves the previous conversation; resume it with /resume". What /clear resets is the model's in-context working buffer, not the file on disk. The file lives at ~/.claude/projects/<project>/<session-id>.jsonl. Anthropic even suggests running /rename before /clear if you want to find that session again later.

What does /compact preserve, and what does it lose?

Compaction does not preserve a session evenly. Per Claude Code documentation, project-root CLAUDE.md, unscoped rules, auto memory and the plan-mode plan are re-injected from disk. Files Claude read or edited come back as up to five, most recently modified first. Invoked skill bodies are re-injected but capped at 5,000 tokens per skill and 25,000 tokens in total, oldest dropped first. Context that hooks added earlier is summarized away with the rest of the conversation. A compacted session is a summary written to make the next turn work, not to preserve what happened.

Can you reconstruct what a subagent did from the main session transcript?

Only partly. Per Claude Code documentation, from the parent's side the subagent's call and its returned result append to the parent conversation - so the fact that a subagent ran and what it reported are both there. What is not there are the subagent's own intermediate turns: the tool calls, file reads and command output it produced along the way. Anthropic's own wording is that "the main session only gets back what the subagent chose to report". Reconstructing the rest requires a record taken at the tool boundary rather than read out of the conversation.

Does Anthropic offer a vendor-side record of Claude Code sessions?

Yes, with real limits. Anthropic extended Compliance API coverage to Claude Code (CLI and desktop) and Claude Cowork, announced August 11, 2026 and generally available as of August 26, 2026. It returns session content - prompts and responses, tool call content for web and MCP, skills and artifacts captured as transcript text - plus metadata including verified user ID and email, organization ID, session and per-message IDs and timestamps. It requires Claude Enterprise with an existing Compliance Access Key. The beta announcement scoped it out of Claude Code on the web, Claude Code accessed through the Claude Platform, and sessions run on Amazon Bedrock, Google Cloud's Vertex AI or Microsoft Foundry, and the GA note does not restate coverage for those surfaces.

Is following Anthropic's Claude Code session efficiency advice a security risk?

No, and that is not the argument here. The post is cost guidance and every practice in it is sound engineering: shorter sessions, smaller contexts, quiet flags on noisy commands, the right model for the task. The observation is architectural. Spend is minimized by keeping the working buffer small, fresh and stable, which is precisely why the buffer is a bad place to keep evidence. Teams should follow the advice and stop treating what remains in a session as the record of what happened.

Where should the audit trail for Claude Code live, if not in the session?

Out of band, at a boundary the session does not own. Three places, in practice. Anthropic documents that hooks and status line commands receive a transcript_path, and that SessionEnd hooks run when a session ends, for cleanup and logging. That is enough to archive the transcript yourself, subject to the 1.5-second default budget SessionEnd hooks share, and it is worth something only if it ships as a managed setting rather than as operator discipline. The Compliance API covers the surfaces it covers. And an endpoint-side record of AI artifacts and of allow, deny or log decisions taken at the tool boundary covers what neither of those reaches, including subagent activity and configuration state.

Does MAX_THINKING_TOKENS=0 hide an agent's reasoning from security teams?

It is not a hiding mechanism and it is not blanket advice. Anthropic scopes it explicitly: "if you already know a session is going to be grunt work, MAX_THINKING_TOKENS=0 claude turns thinking off for that one session (except on Fable 5), which is the step below /effort low." One session, chosen deliberately, for routine work. The point worth taking from it is different: a reasoning trace is a model output that a setting can remove, so an incident process that depends on reading an agent's stated reasoning after the fact was never resting on a control.

Ask AI about Anomity
ChatGPT Claude Perplexity Google AI Grok