AI
How Claude Code Actually Works: Agentic Loop, Tooling Model, and Operational Guardrails
A practical breakdown of Claude Code’s agentic loop from official docs, including tools, permissions, checkpoints, session forking, and leak-risk lessons for real engineering teams.
🤔 Curiosity: Why does Claude Code feel different from chat-style coding?
Most AI coding tools start from suggestion-based chat. Claude Code is built around a different center of gravity: an agentic execution loop in the terminal.
That changes the user experience from “ask-answer” into “plan-act-verify” collaboration. The key question is no longer “Can it write code?” but “Can it complete real engineering tasks with context and checks?”
📚 Retrieve: What the official docs reveal
From Anthropic’s “How Claude Code works” page, the system behavior is best understood as an iterative loop:
- Interpret intent from natural language
- Inspect codebase and runtime context
- Select and run tools/actions
- Observe outputs/errors
- Iterate until completion criteria are met
Source:
- Official docs: https://code.claude.com/docs/en/how-claude-code-works
What the docs make unusually explicit
One reason Claude Code feels different from browser chat is that Anthropic is unusually clear about the execution surface.
According to the docs, Claude Code can work with:
- your project files,
- your terminal commands,
- your git state,
- your
CLAUDE.mdproject instructions, - auto-saved memory from
MEMORY.md, - and configured extensions like MCP servers, skills, subagents, and browser tooling.
That list matters because it changes the trust model.
Claude Code is not just a text generator with a coding style. It is a bounded operator with access to the same local engineering surfaces that a human developer uses to inspect, edit, verify, and recover.
Architecture-level implications
1) Terminal-native is a capability choice
Terminal execution gives direct access to project state:
- repo structure,
- build and test commands,
- local environment,
- git context.
This replaces brittle “paste snippets into chat” workflows with grounded actions.
2) Tool use is first-class
Claude Code’s value is not just generation quality. It is action sequencing quality: inspect → edit → validate → refine.
3) Loop quality determines production usefulness
Real usefulness depends on:
- context selection discipline,
- action correctness,
- and validation depth before finalizing changes.
Built-in operating surfaces that matter in practice
The official docs also expose several features that are easy to miss if you only think of Claude Code as “Claude in the terminal.”
1) Permission modes are part of the architecture
Claude Code supports different execution modes, including default confirmation, auto-accept edits, plan mode, and a more autonomous research-preview auto mode.
That is not a UX detail. It is a control boundary.
Teams should treat permission mode selection the same way they treat CI permissions or production credentials: as a policy decision tied to task risk.
2) Sessions and forks make experimentation safer
The docs expose session continuation and forking behavior through commands like:
1
2
3
claude --continue
claude --resume
claude --continue --fork-session
This is more important than it looks. Session forking means teams can preserve a useful context trail while branching execution paths instead of forcing one long conversation to carry every experiment.
That is a practical way to reduce context pollution.
3) Checkpoints are a real safety primitive
Anthropic explicitly documents checkpoints and undo flows, including the ability to back out changes from the session interface.
That matters because agentic coding without a clean rollback mechanism is just fast damage.
4) CLAUDE.md and memory are not decoration
The docs make it clear that Claude Code loads project-specific instructions and memory at session start.
That means teams can shape behavior structurally, not just prompt-by-prompt.
In practice, this is where high-performing teams encode:
- repo conventions,
- test commands,
- architectural boundaries,
- review expectations,
- and dangerous directories or workflows the agent should avoid.
Repo lens: where this shows up in practice
The original repo lens in nirholas/claude-code was useful because it framed Claude Code around:
- terminal-native operation,
- codebase understanding,
- routine task execution,
- and git workflow support.
Repository:
But there is an important caveat now: that repository is currently unavailable behind a DMCA takedown notice.
That changes how much weight it should carry as a live reference.
So the stronger foundation for understanding Claude Code today is the official docs themselves, with external analysis used only as supporting evidence. The repo still helps explain how the tool was being interpreted in practice, but it is no longer a stable primary source.
That is actually a useful lesson in itself.
When documenting fast-moving AI tooling, teams should separate:
- primary source: vendor docs and directly testable behavior,
- secondary source: community repos and wrappers,
- tertiary source: reverse engineering and postmortem-style analysis.
Mixing those layers too casually is how architectural write-ups drift from evidence into folklore.
💡 Innovation: How advanced teams should operate Claude Code
Treat Claude Code as a bounded software operator, not an autocomplete model.
Practical operating pattern
1) Define bounded tasks
Weak:
- “Improve this project.”
Strong:
- “Refactor module X, keep API stable, run tests Y, and report diff rationale.”
2) Enforce validation gates
Require execution checks before acceptance:
- tests,
- lint/type checks,
- and explicit behavior verification.
3) Keep git as your control surface
Use small, reviewable commits and isolated branches. Fast agent iteration is useful only when rollback/review is clean.
4) Separate exploration vs delivery mode
- Exploration: wider autonomy for discovery
- Delivery: strict constraints, reproducibility, and verification
5) Optimize loop convergence, not prose quality
The real KPI is fewer correction cycles per completed task.
6) Use docs-native control points deliberately
Claude Code already exposes several operational controls in the official surface area:
/modelfor model selection,/contextand/compactfor context management,/initfor project instruction bootstrapping,/agentsfor custom subagent configuration,- and branch/session workflows for controlled divergence.
Advanced teams should not treat these as convenience features. They are part of the harness.
Practical examples: from prompt to controlled execution
Example 1) Safe refactor task prompt
1
2
3
4
5
6
Refactor src/parser.ts to reduce duplication.
Constraints:
- Keep public API unchanged.
- Run `npm test` and `npm run lint` before final output.
- Show changed files and explain behavior impact.
- If tests fail, stop and report root cause first.
Why this works:
- It bounds scope (
src/parser.ts), - adds hard validation gates,
- and requires evidence (test/lint + impact summary).
Example 2) Git-guarded execution script
1
2
3
4
5
6
7
8
9
10
11
12
13
#!/usr/bin/env bash
set -euo pipefail
branch="agent/refactor-parser"
git checkout -b "$branch"
# (Agent performs edits)
npm test
npm run lint
git add -A
git commit -m "refactor(parser): remove duplication with no API changes"
This pattern makes rollback trivial and review clear.
Example 3) Delivery-mode checklist (CI gate)
1
2
3
4
5
6
7
8
9
10
11
12
# .github/workflows/agent-delivery-gate.yml
name: agent-delivery-gate
on: [pull_request]
jobs:
validate:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: npm ci
- run: npm test
- run: npm run lint
- run: npm run typecheck
The point is simple: if the loop cannot pass objective checks, it should not ship.
Leak section: why leakage evidence is critical
You asked about the Leak part being important — and you are right. In agentic coding, leakage is one of the highest-impact failure classes.
Source-map leak analysis (evidence-first, neutral framing)
A detailed external analysis post argues that a production package may have exposed source maps and internal architectural details.
Reference: https://bits-bytes-nn.github.io/insights/agentic-ai/2026/03/31/claude-code-source-map-leak-analysis.html
Important: treat secondary write-ups as claims until independently verified.
What can be treated as high-confidence engineering lessons regardless of vendor specifics:
- Source-map publication is a release-policy decision, not a default safe state.
- If
sourcesContentis embedded, disclosure risk is materially higher. - Build artifacts must be audited in CI/CD, not only application code.
- Agent systems need explicit leakage controls across prompts, tools, logs, and package outputs.
What remains claim-level unless you verify package artifacts directly:
- exact internal file counts,
- detailed internal module names,
- roadmap/feature-flag interpretations.
What “leak” means in practice
- Prompt/context leak
- Internal instructions or private notes appear in user-visible output.
- Credential leak
- API keys, tokens,
.envsecrets, or private URLs appear in diffs/logs.
- API keys, tokens,
- Data boundary leak
- Work intended for one scope (branch/repo/customer) leaks into another.
Why this is evidence-grade important
If leakage appears in run logs, commit diffs, or generated summaries, that is not a cosmetic bug. It is direct evidence that:
- context boundaries are weak,
- tool permissions are too broad,
- or output redaction is missing.
Minimal leak-prevention controls
1
2
3
4
5
6
# pre-commit secret scan (example)
PATTERN='(AKIA|BEGIN PRIVATE KEY|API_KEY=|SECRET=|TOKEN=)'
if git diff --cached | grep -E "$PATTERN" >/dev/null; then
echo "Potential secret leak detected. Abort commit."
exit 1
fi
1
2
3
4
Policy rule:
- Never print raw secrets in chat output.
- Never include `.env`, token values, or internal-only prompts in summaries.
- If sensitive strings are detected, redact and stop for confirmation.
Source-map evidence checks (release gate)
1
2
3
4
5
6
7
8
9
10
# 1) Find source maps in release artifacts
find dist build public -type f -name "*.map" 2>/dev/null
# 2) Check if original source payload is embedded
# (sourcesContent=true usually increases disclosure risk)
find dist build public -type f -name "*.map" -print0 \
| xargs -0 -I{} sh -c 'jq ".sourcesContent != null" "{}" 2>/dev/null | head -n 1'
# 3) Grep for obvious sensitive patterns in shipped assets
grep -R -nE "(API_KEY|SECRET|TOKEN|AKIA|BEGIN PRIVATE KEY|internal\\.|staging\\.)" dist build public 2>/dev/null
Why the source-map case matters even if some details remain disputed
The external write-up is valuable not because every claim should be accepted blindly, but because it spotlights a class of failure that AI teams consistently underestimate: artifact leakage.
Even if you ignore the more speculative parts, the engineering lesson is strong:
- release artifacts need security review,
- not just runtime application code,
- and agentic tools multiply the number of surfaces where sensitive internal structure can escape.
That includes:
- build outputs,
- tool transcripts,
- generated summaries,
- commit messages,
- source maps,
- and cached session state.
Leak-focused review checklist
- Does output include hidden/system instructions?
- Do diffs contain secrets or internal endpoints?
- Are logs safe to share externally?
- Is branch/repo scope isolation enforced?
- Is redaction applied before user-facing summary?
- Are production
*.mapfiles publicly reachable? - Do source maps include
sourcesContentfor original code? - Is source-map policy (off/hidden/authenticated) documented per environment?
If teams ignore leak evidence, they often overestimate agent quality while underestimating operational risk.
Final takeaway
Claude Code’s differentiator is not “better chat answers.” It is agentic execution over real project state.
Teams get the highest leverage when they combine:
- precise task framing,
- strict validation checkpoints,
- disciplined git workflow boundaries,
- and explicit leak-prevention controls.
That is what turns an AI coding assistant into a dependable engineering copilot.
The official docs reinforce a broader point that advanced teams should not ignore:
The performance ceiling of a coding agent is not set only by the model.
It is set by the loop around the model — permissions, checkpoints, context discipline, branch isolation, verification, and artifact hygiene.
References
- How Claude Code works: https://code.claude.com/docs/en/how-claude-code-works
- GitHub reference repo (currently DMCA-disabled): https://github.com/nirholas/claude-code
- Source-map leak analysis (external): https://bits-bytes-nn.github.io/insights/agentic-ai/2026/03/31/claude-code-source-map-leak-analysis.html
Working on something like this?
I take a small number of paid, scoped reviews: AI agent/RAG architecture diagnosis, Unity CI & build-automation audits, and multimodal QA design review. Each one ends in a written findings document.
Work with me