The .claude Directory: Every Claude Code Config File Explained
Claude Code reads configuration from a small set of files in your project and in ~/.claude, and writes session data to ~/.claude as it works. Knowing which file does what answers most "why didn't that apply?" questions, keeps personal settings and secrets out of your repository, and tells you where transcripts of everything Claude read are sitting on disk.
This guide follows Anthropic's .claude directory reference. It covers the project files, the personal and global files, how to choose the right file for a change, the frontmatter each kind of file accepts, and the application data Claude Code stores, including what is cleaned up automatically and how to delete the rest. For the settings precedence that decides which value wins, see Claude Code Enterprise Setup; for CLAUDE.md in large repositories, see Claude Code in Monorepos.
Project files: what you commit
These files describe how Claude should work in this repository, so they belong in git. A minimal setup that most projects benefit from:
1your-project/2├── CLAUDE.md # commands, conventions, gotchas3├── .mcp.json # shared MCP servers, if any4└── .claude/5 ├── settings.json # permissions and hooks6 ├── rules/7 │ └── api.md # loaded for files under src/api/8 └── skills/9 └── release-notes/10 └── SKILL.md # invoked as /release-notesA path-gated rule loads only when Claude works on matching files, which keeps CLAUDE.md short:
1---2paths:3 - "src/api/**/*.ts"4---5- Every handler validates input with the shared zod schema.6- Return errors as { error: { code, message } }..claude/commands/*.md still works and uses the same mechanism as skills, but for new workflows Anthropic recommends skills, which can bundle supporting files.
| File | What it does | When it loads |
|---|---|---|
| CLAUDE.md (root or .claude/) | Instructions and conventions | Start of every session |
| .claude/rules/*.md | Topic-scoped instructions, optionally path-gated | Every session, or when matching files are read |
| .claude/settings.json | Permissions, hooks, env vars, model defaults | Session start; edits are picked up |
| .mcp.json (root) | Team-shared MCP servers | Session start |
| .claude/skills/<name>/SKILL.md | Reusable prompts, /name or auto-invoked | Description at start, body on use |
| .claude/agents/*.md | Subagents with their own prompt and tools | When Claude delegates or you @-mention |
| .claude/workflows/*.js | Dynamic workflow scripts, each a /name command | When run |
| .worktreeinclude (root) | Gitignored files to copy into new worktrees | When a worktree is created |
Quick reference
- An
AGENTS.mdwritten for other coding agents can be loaded in place of a CLAUDE.md. @pathimports inside CLAUDE.md pull other files in; keep imported files short for the same reason CLAUDE.md should be short.- Never put credentials in
.claude/settings.jsonor.mcp.json; both are committed. Use environment variables orsettings.local.json.
Remember this
Commit CLAUDE.md, settings.json, rules, skills, agents, and .mcp.json; they are the team's shared setup.
Personal and global files
Two files hold your personal preferences for one project and should not be committed:
.claude/settings.local.json: your overrides, such as an extra allow rule or a gateway credential. Claude Code adds it to.gitignorewhen it saves a setting there; if you create it by hand, add it yourself.CLAUDE.local.mdat the project root: private instructions loaded alongside CLAUDE.md. Create it manually and gitignore it.
In your home directory, ~/.claude/ applies to every project:
~/.claude/settings.json: your default settings; project and local files override any key you also set there.~/.claude/CLAUDE.md: personal preferences across all projects.~/.claude/skills/,agents/,rules/,output-styles/: your personal versions of the project-level folders.~/.claude/keybindings.jsonandthemes/*.json: shortcuts and colour themes.~/.claude/projects/<project>/memory/: auto memory, notes Claude writes for itself across sessions.
And one file outside the folder: ~/.claude.json holds app state, OAuth details, UI toggles, and MCP servers you added at user or local scope. You rarely edit it by hand.
Quick reference
- Above all of these sit managed settings from your organisation, and CLI flags such as
--settingsoverride settings files for one session. - User-level files do not reach cloud sessions; commit what a cloud session needs into the repository.
- Run
/contextto see which CLAUDE.md and rules files actually loaded, and/permissionsfor the rules in force.
Remember this
Personal overrides go in settings.local.json and CLAUDE.local.md; cross-project preferences go in ~/.claude.
Choose the right file for a change
The most useful table in the reference maps intent to file:
- Give Claude project context and conventions →
CLAUDE.md(project or global). - Allow or block specific tool calls →
permissionsorhooksinsettings.json. - Run a script before or after tool calls →
hooksinsettings.json. - Set environment variables for the session →
envinsettings.json. - Keep personal overrides out of git →
settings.local.json. - Add a prompt or capability invoked with
/name→skills/<name>/SKILL.md. - Define a specialised subagent with its own tools →
agents/*.md. - Orchestrate many subagents from a script →
workflows/*.js. - Connect external tools over MCP →
.mcp.json(project scope). - Change how Claude formats responses →
output-styles/*.md.
The underlying distinction is between guidance and enforcement. CLAUDE.md and rules are instructions Claude applies with judgment and can miss, especially in a long session. Permissions and hooks in settings are applied by Claude Code itself, every time. If something must never happen, or must always happen, it belongs in settings, not in CLAUDE.md.
Quick reference
- A long CLAUDE.md gets parts of it ignored. Move domain detail into path-gated rules or skills, which load only when relevant.
- Skills load only their name and description at start-up, so many skills cost little until one is used.
- If a setting seems ignored, check precedence: a local or managed value may be overriding it.
Remember this
Instructions in CLAUDE.md and rules; anything that must hold in settings.json permissions and hooks.
Frontmatter: what each file accepts
Skills, commands, subagents, output styles, and rules all read configuration from YAML frontmatter at the top of the file. A subagent that reviews code with read-only tools:
1---2name: security-reviewer3description: Reviews code for security vulnerabilities4tools: Read, Grep, Glob, Bash5model: opus6---7You are a senior security engineer. Review code for injection, auth flaws,8secrets in code, and insecure data handling. Give file and line references.And a skill with side effects that you want to trigger only by hand:
1---2name: deploy-staging3description: Deploy the current branch to staging4disable-model-invocation: true5---6Run the staging deploy script and report the URL.The description field matters most: it is how Claude decides when to use a skill or delegate to a subagent, so write it as a precise statement of when the file applies.
| File | Common fields | Notes |
|---|---|---|
| skills/<name>/SKILL.md | name, description, allowed-tools, disable-model-invocation, model, paths | Many more: arguments, context, agent, hooks, effort |
| commands/*.md | The skill fields except name and paths | Same mechanism as skills |
| agents/*.md | name, description, tools, model, permissionMode, isolation, maxTurns | Also memory, hooks, mcpServers, skills |
| output-styles/*.md | name, description, keep-coding-instructions | Changes how Claude works and replies |
| rules/*.md | paths | Without paths, the rule loads every session |
Quick reference
disable-model-invocation: truekeeps Claude from running a skill on its own; use it for anything with side effects.isolation: worktreeon a subagent gives each run its own git worktree.- Plugin agents honour only a subset of the subagent fields.
Remember this
Frontmatter configures each file; a precise description is what makes Claude pick the right skill or subagent.
What Claude Code stores, and for how long
Beyond the configuration you write, ~/.claude holds data Claude Code writes during sessions, and it is plaintext. Anything that passes through a tool is written to a transcript: file contents, command output, pasted text. If Claude reads a .env file or a command prints a token, that value is now in ~/.claude/projects/<project>/<session>.jsonl.
Swept automatically after cleanupPeriodDays (default 30, minimum 1): session transcripts, subagent transcripts, large tool outputs, file-history/ snapshots used for checkpoint restore, plans/, debug/ logs, paste-cache/, and others, plus orphaned worktrees.
Kept until you delete them: history.jsonl (every prompt you typed, for up-arrow recall), stats-cache.json, auto memory files, and state such as .credentials.json.
To reduce exposure: lower cleanupPeriodDays, deny reads of credential files with permission rules, and set CLAUDE_CODE_SKIP_PROMPT_HISTORY to skip writing transcripts and prompt history (or pass --no-session-persistence with -p). To delete one project's state, run claude purge; it shows the full plan and asks before removing transcripts, auto memory, per-session task and debug files, matching history lines, and the project's entry in ~/.claude.json.
Quick reference
- Each session also gets a scratchpad directory under the system temp directory (for example
/tmp/claude-<uid>/...on Linux), deleted with its transcript. claude purgedoes not touch the temp directory, so pasted images and scratchpads there remain until swept or cleared by the OS.- Keep
.credentials.json,agent-memory/, and thejobs/anddaemon/background-session state; caches and lock files are safe to delete.
Remember this
Transcripts are plaintext copies of what Claude saw; deny secret reads, shorten retention, and use claude purge when needed.
Hands-on: audit one project's configuration
In a project you use Claude Code with:
1. List what exists: ls -la CLAUDE.md CLAUDE.local.md .mcp.json .worktreeinclude .claude/ 2>/dev/null and ls ~/.claude/.
2. Run git check-ignore -v .claude/settings.local.json CLAUDE.local.md and fix .gitignore if either is not ignored.
3. Start claude, run /context and /permissions, and note which CLAUDE.md and rules files loaded.
4. Move one domain-specific section of CLAUDE.md into .claude/rules/<topic>.md with a paths: filter, and confirm with /context that it loads only when you open a matching file.
5. Add "deny": ["Read(./.env)", "Read(./.env.*)"] to .claude/settings.json.
6. Search last month's transcripts for secrets: grep -l "API_KEY\|SECRET" ~/.claude/projects/*/*.jsonl | head. If anything shows up, rotate the credential and consider claude purge.
Pass criterion: personal files are gitignored, CLAUDE.md is shorter with a path-gated rule doing part of its job, secret reads are denied, and you know whether any credential has already been written to a transcript.
Quick reference
- If step 6 finds matches, the deny rule came too late for those sessions; rotating the credential is the only real fix.
- Commit the CLAUDE.md, rules, and settings changes so the whole team gets them.
- Repeat step 3 after edits; settings changes are picked up automatically, but
/contextshows what actually loaded.
Remember this
An audit takes ten minutes: check what is committed, what loads, what is denied, and what has already been recorded.
Key takeaway
Claude Code's configuration is a short list of files. In the project: CLAUDE.md and .claude/rules/ for instructions, .claude/settings.json for permissions, hooks, and environment, skills/ and agents/ for reusable capabilities, and .mcp.json for shared tools, all committed. Personal overrides go in settings.local.json and CLAUDE.local.md, kept out of git, and cross-project preferences in ~/.claude. The rule of thumb: guidance in CLAUDE.md, anything that must hold in settings.
Claude Code also writes plaintext transcripts of everything its tools see to ~/.claude/projects, swept after 30 days by default, while prompt history and memory stay until you delete them. Deny reads of secrets, tune retention, and use claude purge when a project's data should go. For the permission rules referenced here, see Claude Code Permissions; for hooks, see Claude Code Hooks.
Practice (15 min): run the six-step audit above on your main project.
References
- Claude Code docs: Explore the .claude directory — checked Oct 17, 2026
- Claude Code docs: Memory and CLAUDE.md files — checked Oct 17, 2026
- Claude Code docs: Settings — checked Oct 17, 2026
Shoaib Hossain
Lead Author & Systems ArchitectSoftware engineer and distributed systems architect specializing in backend scalability, cloud-native infrastructure, databases, and AI engineering workflows. Author and maintainer of Core Concept Learning.
Related Articles
Explore this topic