
Ultimate Guide: Anatomy of the .claude/ Folder, Explained
Ever opened a hidden .claude/ folder and felt like you’d wandered into someone’s garage toolshed — useful stuff everywhere, but no rhyme or reason? You're not alone. For anyone running claude locally or building agents on top of Anthropic tooling, that folder is where the magic and the mess both live.
In my view, understanding .claude/ is the difference between a reproducible agentic workflow and a brittle pile of scripts you'll be babysitting forever. Here's a pragmatic breakdown of what lives in there, why each piece matters, and how to structure it so your autonomous AI work actually scales. (Credit where due — Avi Chawla's primer on the folder was a great starting point for this walk-through.) [1]
Why this matters for builders and ops
- If you're building agentic workflows, the .claude/ folder is your control plane: commands, agents, permission rules, and local skills.
- If you care about autonomous AI behaving predictably, this folder needs clear structure, versioning, and security.
- Ignore it and you'll have a Frankenstein agent that breaks when you least expect. Ask me how I know.
Next, we'll unpack the key files and patterns. You'll get checklists, a table that maps files to purpose, and pragmatic tips for CI and security. Let's go.
Why claude's .claude/ folder matters
claude isn't just an API or a model — it's an ecosystem. The .claude/ folder is where you stitch together prompts, small programs, and permissioning that determine actual behavior.
Think of it like the cockpit of a plane. Models are the engines, but .claude/ are the instruments, checklists, and the safety switches. Mess up the cockpit and you're not getting off the ground. This is especially true for agentic workflows where one misaligned command can cascade into unsafe autonomous AI behavior.
The rest of this article treats the folder like a living system — you’ll want observability, version control, and a few guardrails.
Core files: CLAUDE.md, settings, and permissions
At the top of most .claude/ folders you'll see a handful of standard files.
- CLAUDE.md — the manifest and primary config. It describes agents, default prompts, and environment hooks. Treat this like your README + system prompt. Avi Chawla has a solid breakdown on how CLAUDE.md ties pieces together. [1]
- settings.json / settings.yaml — runtime toggles: model selection, timeouts, endpoints, API keys. Keep secrets out of this file; use envs.
- permissions.json — explicit allow/deny rules for agents and commands. If your autonomous AI can reach external systems, this file is your last line of defense.
Don't overload CLAUDE.md with secrets or dense business logic. Keep it declarative. Next I'll show how commands and skills slot into that manifest.
Custom commands, skills, and agents — how they interact
This is the meat: custom commands are the atomic actions; skills are collections of commands or helper code; agents are orchestration layers that choose and chain skills.
- Commands: small scripts (usually shell, Python, or node) exposed to the agent. They should be idempotent, have clear inputs/outputs, and a timeout.
- Skills: grouped utilities and helpers — think "git helper", "deploy helper", "data query". They sit in a skills/ directory and can be tested individually.
- Agents: higher-level orchestrators, defined in CLAUDE.md, that pick commands/skills based on context and policies.
Analogy: Commands are Lego bricks. Skills are pre-built sub-assemblies. Agents are the instructions that pick bricks and assemble a final model. Works well when pieces are small and well-tested.
Quick checklist for commands and skills:
- Keep commands single-responsibility.
- Validate inputs strictly (never trust model output).
- Log structured events (JSON) for observability.
- Add unit tests for skills; mock external calls.
That pattern keeps agentic workflows maintainable and reduces surprises when you let agents act with more autonomy.
Table: common .claude/ files and their purpose
| File / Folder | Purpose | Best practice |
|---|---|---|
| CLAUDE.md | Manifest + system prompts | Keep declarative; small; link to tests |
| commands/ | Atomic actions callable by agents | Validate inputs; add timeouts |
| skills/ | Reusable utilities and grouped commands | Unit test; version independently |
| agents/ | Agent definitions & routing logic | Minimal coupling; explicit policies |
| permissions.json | Allow/deny for external ops | Principle of least privilege |
| logs/ | Structured run logs | JSONL with request/response hashes |
| scripts/ | CI helpers and deployment hooks | Idempotent, safe by default |
If you keep these responsibilities clear, adding new autonomous AI behaviors becomes less scary. Next, security.
Security and permissions: what to lock down
Let me be blunt: the moment you let an agent call arbitrary shell commands or webhooks, you need rules. Permissions.json should be conservative.
- Principle of least privilege: grant the minimum access an agent needs.
- Deny by default: explicitly enumerate domains, file paths, and system calls.
- Secrets: never store API keys in repo files. Use secret managers or env injection at runtime.
For teams that care about LLM attack surfaces, I’ve written a minute-by-minute response to a Litellm malware incident that highlights what to watch for in practice — it's worth a read if you plan to expose agents externally. (Linking to our deeper post on LLM security helps you operationalize these ideas.) [link]
Also consider runtime sandboxing: containers, user namespaces, or platform-level restrictions to prevent lateral movement. Don't rely on "trustworthy prompts" — honest mistakes and prompt injection still happen.
Transition: permissions are necessary, but observability is what saves your day when things go wrong.
Debugging, versioning, and CI for .claude/
If it's not in version control it doesn't exist. But there's nuance.
- Repo layout: keep .claude/ at repo root or in a single config package if multiple projects share agents.
- Versioning: tag CLAUDE.md changes and skill releases. Use semantic versioning for skills.
- CI checks: lint CLAUDE.md, run command unit tests, and smoke-run agents in a dry mode that uses mocks.
A practical CI pipeline:
- Lint CLAUDE.md and permissions.json.
- Run unit tests for skills and commands.
- Execute an agent dry run with mocked external calls.
- Deploy artifacts if all checks pass.
Logging is equally crucial. Structured logs let you trace decisions back to a command or prompt. Save request/response hashes and the exact agent version used. This makes audits and root cause analysis tractable rather than guesswork.
One more note: if your agents touch sensitive data, treat runs like transactions. Have a rollback plan and an audit trail.
Best practices and folder layout (practical checklist)
Here's a practical layout I actually use in production:
- .claude/
- CLAUDE.md
- permissions.json
- settings.yaml (not secrets)
- commands/
- git_commit.sh
- fetch_data.py
- skills/
- deploy/
- deploy.sh
- tests/
- deploy/
- agents/
- code_review.agent.md
- logs/
- ci/
Practical checklist (copy-paste into your repo):
- CLAUDE.md includes a changelog entry for each change.
- Permissions.json denies everything by default.
- Commands have input schemas and timeouts.
- Skills have unit tests with >70% coverage.
- CI runs dry-agents with mocked network calls.
- Secrets are injected at runtime, not checked in.
Honestly, this checklist will save you countless headaches. If you ask me, teams that skip these basics just delay the disaster.
Real-world examples, links, and further reading
If you want concrete examples, Avi Chawla’s blog post gives a good primer on CLAUDE.md structure and file roles — I leaned on his taxonomy when building my own layouts. [1]
For adjacent topics you should read next:
- Our hands-on LLM security playbook — live incident response to a supply-chain malware incident. (https://www.aiagentsforce.io/blog/ultimate-llm-security-my-minute-by-minute-response-to-the-litellm-malware-attack)
- Privacy-first access patterns for mobile and constrained devices — useful if agents run on endpoints. (https://www.aiagentsforce.io/blog/essential-grapheneos-stands-firm-privacy-first-ai-access)
- How to structure code and open-source AI tooling for teams building automations. (https://www.aiagentsforce.io/blog/proven-ai-coding-power-unlocking-opencode-s-potential)
A question for you: are your agents doing real work, or are they glorified chatbots? If you want them to be reliable workers, treat .claude/ like ops infrastructure, not a research sandbox.
Closing thoughts and an opinion
Here's what I think: .claude/ is underrated. People focus on the model and forget the orchestration layer that makes outcomes reproducible and safe. Treating .claude/ as an afterthought is the fastest route to brittle agentic workflows and surprising autonomous AI behavior.
Build small, test often, lock down permissions, and log everything. If you do that, your agents will scale from clever demos to reliable infrastructure. If you don't, you'll be patching fires when things break — and you will have to explain those fires to someone who cares about uptime.
If you want a checklist or a starter repo I use internally, tell me what stack you're on (Python/Node/shell), and I’ll sketch a minimal .claude/ layout you can fork.
References
- Avi Chawla, "Anatomy of the .claude/ Folder" — foundation for CLAUDE.md and command/agent patterns. (https://blog.dailydoseofds.com/p/anatomy-of-the-claude-folder) [1]