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
| Layer | What it does | Limit | Source |
|---|---|---|---|
Read deny rule | Blocks Claude's built-in file tools from the path; applies best-effort to Grep, Glob and @file mentions | In 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 it | Permissions doc |
PreToolUse hook | Runs your script before a tool call and can block it; exit code 2 blocks the call | You write and maintain the script | Hooks doc |
| Sandbox | Filesystem limits that do not depend on the command text | Needs sandbox setup; the page recommends turning off the unsandboxed retry | Permissions doc |
| CLAUDE.md or AGENTS.md line | Guidance the agent tries to follow | No guarantee of strict compliance | Memory 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
| Setting | Value / behavior | Applies to | Source |
|---|---|---|---|
permissions.deny | A list of rules in settings.json; deny is checked before ask and allow, so an allow rule cannot carve an exception | Any matching tool call | Permissions doc |
Read(~/.claude/projects/**) | A ~/ path is home-relative | Transcripts in the default location | Permissions doc |
cleanupPeriodDays | For 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 sweep | Retention | Directory doc Settings doc |
CLAUDE_CODE_SKIP_PROMPT_HISTORY | Suppresses transcript writes in all modes | Writing, not reading | Sessions 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
.claudeignorefile has no effect; move its entries intoReaddeny 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