published fresh until

How do I stop my coding agent from reading past chat logs?

Summary When an agent should not read old session transcripts, add a Read deny rule for the transcript folder; instruction files alone are context, not enforcement.

Not for making CLAUDE.md rules load or obeyed in general (see Claude ignores my CLAUDE.md rules: what actually stops it?), or allow rules Claude Code ignores (see Claude Code still asks about commands I allowed: what to check?)

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp/login && claude mcp login whatworks

Connects your agent and signs you in (GitHub or Google). Read-only, no account: see /connect.md.

What this thread does

Do first: add a Read deny rule for the transcript folder in your Claude Code settings; an instruction in CLAUDE.md or AGENTS.md alone will not enforce it. Memory doc

Short answer

Claude Code stores each session as a JSONL transcript at ~/.claude/projects/<project>/<session-id>.jsonl. Sessions doc The transcript holds messages, tool calls and tool results, plus the system prompt and tool definitions of requests sent to the model. Directory doc To keep the agent out of those files, use a settings rule, not prose: the memory doc says CLAUDE.md files are context, not enforced configuration, and that settings rules are enforced by the client regardless of what Claude decides. Memory doc

Choose / don't choose

LayerWhat it doesLimitSource
Read deny ruleBlocks Claude's built-in file tools from the path; applies best-effort to Grep, Glob and @file mentionsIn Bash, only commands Claude Code can analyze, such as cat, head, tail, sed and tee, are covered; grep -r run inside the folder and a Python or Node script that opens files itself can still read itPermissions doc
PreToolUse hookRuns your script before a tool call and can block it; exit code 2 blocks the callYou write and maintain the scriptHooks doc
SandboxFilesystem limits that do not depend on the command textNeeds sandbox setup; the page recommends turning off the unsandboxed retryPermissions doc
CLAUDE.md or AGENTS.md lineGuidance the agent tries to followNo guarantee of strict complianceMemory doc

Choose the deny rule first; add a hook or the sandbox when shell reads must be stopped too. Not for hiding secrets inside your project: use the same rule type on those paths, as in Read(./.env). Codex and other agents are not covered here. Permissions doc

Settings that matter

SettingValue / behaviorApplies toSource
permissions.denyA list of rules in settings.json; deny is checked before ask and allow, so an allow rule cannot carve an exceptionAny matching tool callPermissions doc
Read(~/.claude/projects/**)A ~/ path is home-relativeTranscripts in the default locationPermissions doc
cleanupPeriodDaysFor transcripts covered by the retention sweep it sets the age cutoff, with a default of 30 days and a minimum of 1; deletion runs after session start when the retention period can be determined; Claude Desktop and Cowork sessions have retention exceptions, and bare-mode runs skip the sweepRetentionDirectory doc Settings doc
CLAUDE_CODE_SKIP_PROMPT_HISTORYSuppresses transcript writes in all modesWriting, not readingSessions doc

Order of operations

1. Add the rule to your user settings.json:

{
  "permissions": {
    "deny": ["Read(~/.claude/projects/**)"]
  }
}

2. Ask the agent to read a file in that folder and confirm it is refused. The doc says a Read deny rule also blocks Edit and Write on the same path. Permissions doc 3. If shell reads matter, enable the sandbox or add a PreToolUse hook that exits 2 when a command touches the folder. Hooks doc 4. To reduce future transcript storage, lower cleanupPeriodDays for covered sessions, or launch Claude Code with CLAUDE_CODE_SKIP_PROMPT_HISTORY=1 to suppress new transcript writes; neither setting guarantees deletion of all existing transcripts. Sessions doc Settings doc

Known failures and fixes

  • A rule written for a path in user settings with a bare leading slash is not a home path: Read(/secrets/**) in user settings blocks ~/.claude/secrets/**, so write ~/ or // paths. Permissions doc
  • A .claudeignore file has no effect; move its entries into Read deny rules. Permissions doc
  • If the agent still reads the folder through a script, the rule is not enough by design; add the sandbox. Permissions doc

Missing

  • The pages read do not show the exact refusal wording an agent sees when a rule blocks a read.
  • Where Codex, Cursor and other agents keep chat history, and how to block them, is not covered.

Evidence

Claude Code documentation pages on permissions, memory, sessions, hooks and the .claude directory. 0 trials in this draft; not tried by WhatWorks.

Checked

2026-12-03; all five pages were read as served on that date.

Started from a post by @Anthropic, packaged by the editor. Original post

Subjects

More in agents.md

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# How do I stop my coding agent from reading past chat logs?
Summary: When an agent should not read old session transcripts, add a `Read` deny rule for the transcript folder; instruction files alone are context, not enforcement.
Copy for agent
get the whatworks thread claude-code-block-agent-reading-chat-history-transcripts and help me try it

Follow this thread

Following adds this thread to What's new: ask your agent what's new and it lists new package versions, trial reports and replies. Feed reader? whatworks.dev/feed.xml lists updated threads.

Sign in to follow. Nothing is posted for you.

Sign in

Or ask your agent
follow the whatworks thread claude-code-block-agent-reading-chat-history-transcripts
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp/login and sign me in so I have an account. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp/login && claude mcp login whatworks
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp/login && codex mcp login whatworks