02 - Claude Code: Agentic Development from the Terminal
Claude Code is, in the words of its documentation, an agentic coding tool that reads your codebase, edits files, runs commands and integrates with your development tools; you use it from the terminal, from an IDE, from the desktop app and from the browser. The word that matters is runs: an assistant that proposes code leaves it to you, while an agent applies it and then launches the tests. This shifts the developer's problem from the quality of the suggestion to control over what the agent can do when nobody is watching.
This article follows that control and does not tour the commands. It separates what you ask of the agent, that is,
the CLAUDE.md file and prompts, from what you prevent it from doing, that is, permissions and hooks, because the
documentation itself says the two are not equivalent. By the end you have a check you can run
on your own computer without calling any model. Every feature mentioned is verified against the official documentation
read on 12 November 2026; where I could not try something, I say so.
What the agent does when you give it a task
The documentation describes a loop in three phases that blend into one another, and the order shows where you can step in:
- Gathers context: it searches and reads files to understand the project and the task.
- Acts: it edits files, runs commands, uses the tools you have granted it.
- Verifies: it runs the tests or rereads the result and decides whether to continue.
The three phases are not equal from a risk standpoint. Gathering context is almost always read-only, and that is why the documentation indicates that reads inside the working folder do not ask for approval. Acting is the point where a mistake costs something: that is why shell commands and file edits require approval by default, apart from a set of read-only commands. Verifying is where your intervention pays off most, because an agent that runs the tests and reads the outcome fixes obvious errors on its own, but not those that no test covers, as you will see in the example in the first article of the series, Vibe coding: the paradigm that changed 2025.
The context the agent uses fills up as it goes. When it nears the limit, Claude Code compacts it into a
summary that keeps your requests and the important code snippets, but instructions given early in the
conversation can be lost. The documentation draws from this a practical rule worth adopting: rules
that must always hold are not stated in chat, they are written in CLAUDE.md, which is
reread at every session.
Installing it without surprises
For macOS, Linux and WSL the installation the documentation recommends is the native installer,
curl -fsSL https://claude.ai/install.sh | bash; for Windows there are PowerShell and CMD, and Homebrew and WinGet are documented as well.
Anyone who prefers npm will find the package @anthropic-ai/claude-code, which requires Node.js 22 or
later and downloads the same native binary. After installing, open a new terminal and run
claude --version: if it prints a version number, the installation works; if the shell says
the command does not exist, the installation folder is missing from your PATH.
I did not run the installation or start Claude Code, because it requires an account and a model: everything
that follows about configuration concerns files you can read and verify without a session. A caution about the
command with curl and bash: it downloads and runs a script, so read it first, or
use your platform's package manager.
CLAUDE.md: instructions the agent reads, not rules it is subject to
CLAUDE.md is a Markdown file that Claude Code reads at the start of every session. It can live in
different places, and the place decides who sees it:
- Project (
./CLAUDE.mdor./.claude/CLAUDE.md): shared with the team through version control. - Personal, for all projects (
~/.claude/CLAUDE.md): your preferences, visible only to you. - Personal, for one project (
./CLAUDE.local.md): to be put in.gitignore. - Organization: in a system folder, managed by whoever administers the machines.
The distinction you draw from this is between shared instructions and your own preferences: if you write a habit of yours in the
project file, you impose it on the whole team. If the repository already has an AGENTS.md for other
agents, the documentation says that Claude Code can read it in place of a CLAUDE.md, and with the
/init command you can have a starting one generated.
How you write it matters as much as where. The official guide asks for instructions concrete enough to be verified ("use 2-space indentation", not "format code properly") and a file under 200 lines, because a long file consumes context and reduces adherence. The file below is an example of mine, written for an imaginary Python project: every line can be checked by looking at the repository, and the "Do not" section states the things the agent cannot discover on its own.
# CLAUDE.md
## Commands
- Tests: `python3 -m unittest discover -s tests`
- Run: `python3 -m app`
## Conventions
- Functions under 40 lines; one module per responsibility
- Dates are always UTC; conversion to the time zone lives only in `app/view.py`
## Do not
- Do not add dependencies without asking
- Do not edit `migrations/` by hand: generate it with `python3 -m app.migrate`
The limit you must have clear is written on the same documentation page: Claude treats
CLAUDE.md as context, not as enforced configuration, and if you want to block an action
whatever the agent decides, you must use a PreToolUse hook. The line "Do not add dependencies without
asking" steers behavior, and usually works, but does not guarantee it. Alongside CLAUDE.md there is
also an automatic memory: notes that Claude writes on its own about your corrections, in
~/.claude/projects/<project>/memory/, with an index MEMORY.md. They are different things: you write the first, the second is written by Claude,
so reread it now and then, as you would any note you did not write yourself.
Permissions: what the program enforces
Permissions live in settings.json, under the permissions key, in three lists:
allow (run without asking), ask (ask) and deny (refuse). Rules are
evaluated in the order deny, ask, allow and the first one that matches decides: a broad deny rule
blocks even what a more specific allow would admit, so you cannot open an exception inside a prohibition. The same page
states that the rules are enforced by Claude Code and not by the model: instructions in the prompt or in
CLAUDE.md change what the agent tries to do, not what it is allowed to do.
In rules for Bash the asterisk is a wildcard. Bash(npm run test *) admits
npm run test --watch, while Bash(npm run test) admits only the exact command. That is why
in the example that follows the allow rules have a trailing asterisk. In the file I also put a
deny on git push and on .env files, and a hooks block that we will see
shortly. I validated the file with a JSON parser, but I did not load it into Claude Code: inside a session you check it with
/status for the files read and with /permissions for the active rules.
{
"permissions": {
"allow": ["Bash(npm run test *)", "Bash(git commit *)"],
"deny": ["Bash(git push *)", "Read(./.env)", "Read(./.env.*)"]
},
"hooks": {
"PreToolUse": [
{
"matcher": "Bash|Edit|Write",
"hooks": [
{
"type": "command",
"command": "python3 \"$CLAUDE_PROJECT_DIR\"/.claude/hooks/protect.py"
}
]
}
]
}
}
Here is the trap that the code in the next paragraph addresses. The documentation warns that
Bash(git push *) rejects commands that start with git push, but a form such as
git -C . push does not match: shell commands have too many ways of saying the same thing for a text
comparison to cover them all. A permission rule remains useful as a first line, as long as you do not
treat it as a guarantee.
On precedence, two facts correct a common idea. Lists such as permissions.allow are
merged across files instead of overwritten, so a project file adds rules to the
personal ones, it does not replace them. For single values, on the other hand, the most specific level wins: the
shared project configuration overrides the personal one, the project's local file
(settings.local.json, outside git) overrides the shared one, and the settings managed
by the organization override everything.
Hooks: a check that does not depend on the model
A hook is a shell command that Claude Code runs at a point in its loop. The type needed here is
PreToolUse, run before every use of a tool. Claude Code passes it the event as JSON
on standard input, with fields such as tool_name and tool_input; the command answers with its exit code.
With 0 it has no objection and the request goes on through the normal permission flow (0 approves
nothing); with 2 it blocks the action, and what it writes to standard error reaches Claude as the reason, so that it can change
course. With any other code and without valid JSON the action goes ahead, for most events.
The structure in the file has three levels: the event name, a matcher that says for which
tools it fires (Bash|Edit|Write means any one of the three) and the list of
commands, each with type and command. The format with the fields tool,
description and variables such as $CLAUDE_FILE_PATH that circulates in many tutorials does not
match the current documentation, and a hook written that way would not fire. The script that follows reads the event,
splits the command into sub-commands, skips git's global options and blocks git push, and it also blocks
edits to files whose path contains .env, package-lock.json or .git/.
import json
import re
import shlex
import sys
PROTECTED_FILES = (".env", "package-lock.json", ".git/")
def has_push(command):
"""True if one of the sub-commands is a 'git push', even with 'git -C dir push'."""
for part in re.split(r"&&|\|\||;|\|", command):
try:
words = shlex.split(part)
except ValueError:
continue
if not words or words[0] != "git":
continue
rest, i = words[1:], 0
while i < len(rest) and rest[i].startswith("-"):
i += 2 if rest[i] in ("-C", "-c") else 1 # global git options
if i < len(rest) and rest[i] == "push":
return True
return False
def block_reason(event):
data = event.get("tool_input", {})
if "command" in data and has_push(data["command"]):
return "git push is not allowed: a person does it"
path = data.get("file_path", "")
for pattern in PROTECTED_FILES:
if pattern in path:
return f"{path} contains '{pattern}': protected file"
return None
if __name__ == "__main__":
reason = block_reason(json.load(sys.stdin))
if reason:
print(f"Blocked: {reason}", file=sys.stderr) # stderr reaches Claude
sys.exit(2) # 2 = block the action
sys.exit(0) # 0 = no objection
In the script, re.split separates commands joined by &&, ||, ;
and |, so cd app && git push is seen as two commands. The
while loop skips the options that precede the subcommand; -C and -c consume two
words because they take an argument, and that is exactly what unmasks git -C . push. The
.claude/hooks/ directory has no special meaning: the documentation uses it for its examples, but the script
can live wherever you like, as long as the command field reaches it. The reason I wrote it in
Python is that I can run it here; the official examples use jq and Bash.
To try it without starting Claude Code, the program below builds the events as the documentation describes them
and passes them to the script on standard input, printing the exit code and the message. You run it with
python3 try_hook.py in the folder holding the two files.
import json
import subprocess
CASES = [
("Bash", {"command": "npm run test -- --watch"}),
("Bash", {"command": "git push origin main"}),
("Bash", {"command": "git -C . push"}),
("Bash", {"command": "cd app && git push --force"}),
("Bash", {"command": "git status"}),
("Bash", {"command": "bash -c 'git push'"}),
("Edit", {"file_path": "src/app.py"}),
("Edit", {"file_path": "config/.env"}),
]
for tool, data in CASES:
event = {"hook_event_name": "PreToolUse", "tool_name": tool, "tool_input": data}
r = subprocess.run(["python3", "protect.py"], input=json.dumps(event),
capture_output=True, text=True)
what = data.get("command") or data.get("file_path")
print(f"exit {r.returncode} {tool:4} {what:28} {r.stderr.strip()}")
# Output (python3 try_hook.py, two identical runs):
# exit 0 Bash npm run test -- --watch
# exit 2 Bash git push origin main Blocked: git push is not allowed: a person does it
# exit 2 Bash git -C . push Blocked: git push is not allowed: a person does it
# exit 2 Bash cd app && git push --force Blocked: git push is not allowed: a person does it
# exit 0 Bash git status
# exit 0 Bash bash -c 'git push'
# exit 0 Edit src/app.py
# exit 2 Edit config/.env Blocked: config/.env contains '.env': protected file
The output says two things. The three ways of writing a push (plain, with -C, after a cd) are
blocked with code 2, while git status and the test pass with 0. And there is an honest limit:
bash -c 'git push' gets through, because the script sees a bash command with a string as
its argument and does not open it. A model that wants to get around the check, or does so by accident, finds paths I did not anticipate:
the hook is a seat belt, not a cage. The check on paths is also a substring comparison, so it
blocks even a file called .envrc: an acceptable false positive, because it errs on the cautious side.
If the possible damage is serious, the real protection lies outside the agent, in the credentials you give it (the GitHub token
without push permission) and in the environments it can reach.
Subagents, skills and MCP servers
The rest of the extensibility is found in the .claude/ directory, and it helps to distinguish what
changes behavior from what adds capabilities. A subagent is a Markdown file with
a YAML header (name, description, tools, model) in
.claude/agents/: it has its own prompt and its own list of tools, and works in a separate context, so a long
search does not fill your conversation. The tool with which the main agent launches them is today called
Agent; since version 2.1.63 the old name Task remains as an alias. Giving a subagent only
Read, Grep, Glob makes it a reviewer that cannot modify anything, and that is the use in which a subagent is worth
more than the main agent.
Skills are procedures the agent loads when needed: a folder
.claude/skills/<name>/ with a SKILL.md file. The body is loaded only when the skill is used, so a long
procedure costs little context until it is needed, unlike CLAUDE.md, which is always loaded. Custom
commands in .claude/commands/ have been merged into skills: a file commands/deploy.md and
a skill skills/deploy/SKILL.md both create /deploy. A wrong example you find
elsewhere, .claude/skills/name.md as a single file, is not the documented structure.
MCP servers connect external tools, and those shared with the team live in a
.mcp.json file at the project root, not in settings.json; they are also added with
claude mcp add. The documentation warns that servers that fetch external content expose you to the risk of
prompt injection, that is, text written by third parties that the agent mistakes for an instruction, and asks you to
trust only servers you trust. The trade-off is the same as for permissions: every server adds capability and
adds surface, so connect the minimum and prefer read-only credentials.
When not to delegate to a terminal agent
An agent with a shell is the right choice when the task verifies itself: there is a test suite, a
build, a linter, a command that says whether it is done. It is the wrong choice when the result is judged only by eye and the damage
is hard to undo, for example a migration on real data or a change to payment code without tests. In
those cases use plan mode, in which Claude reads and explores without modifying the sources, or have
the agent work in a separate worktree with the -w option, which creates an isolated copy under
.claude/worktrees/.
One cost remains that no configuration removes: reading what the agent did. Every approval you grant "forever" shifts work from now to the day something goes wrong, and when permissions are broad your control is the final diff. That is why the order matters: first tight permissions and tests, then, only if they hold, widening. How to break a task into verifiable steps is the subject of Agentic workflows: decomposing problems for AI, and which risks remain anyway is covered in Security in vibe coding.
Frequently asked questions
Is writing "do not do X" in CLAUDE.md enough to prevent X?
No. According to the documentation, Claude treats CLAUDE.md as context and not as enforced configuration. To really prevent
an action you need a deny rule in the permissions or a PreToolUse hook that answers with code 2.
Where does the MCP server configuration go?
In a .mcp.json file at the project root if you share it with the team, or in the personal
configuration if it is only yours; not in .claude/settings.json, which holds permissions, hooks and environment variables.
Do the project's permission rules replace the personal ones?
For lists such as allow and deny, no: lists from several files are merged. For single
values the most specific level wins, and the settings managed by the organization override everything.
What you can do now
You can say what a terminal agent does in each phase of the loop and where you can step in, and you can tell apart
what you ask (CLAUDE.md, prompts) from what the program enforces (permissions, hooks). You have a
settings.json with the correct structure of permissions and hooks and a check script that you tried on eight events,
including the case it does not intercept. You can place subagents, skills and MCP servers in the right directory and you know when a
task should not be given to an agent. The next step is breaking work into steps the agent can verify
and then coordinating several agents.
To write prompts and instruction files that tell the agent what the repository does not, see Prompt Engineering for IDEs and Code Generation; for the habits that stay valid when the tools change, The future of agentic software development.
Sources
- Claude Code Docs: How Claude Code works - the three-phase loop (context, action, verification) and context compaction, accessed 2026-11-12
- Claude Code Docs: Advanced setup - recommended native installer, npm package with Node.js 22 or later, verification with
claude --version, accessed 2026-11-12 - Claude Code Docs: How Claude remembers your project - locations of CLAUDE.md, the 200-line limit, difference between instructions and enforced configuration, automatic memory with MEMORY.md, accessed 2026-11-12
- Claude Code Docs: Configure permissions - allow, ask and deny lists, evaluation order, wildcards in Bash, the limit of
git -C . push, accessed 2026-11-12 - Claude Code Docs: Settings - merging of lists across files and precedence of levels, accessed 2026-11-12
- Claude Code Docs: Automate actions with hooks - format with matcher and hooks, JSON event on stdin, exit codes 0 and 2, accessed 2026-11-12
- Claude Code Docs: Create custom subagents, Skills, MCP and Explore the .claude directory - subagent format, renaming of Task to Agent, merged skills and commands,
.mcp.json, the prompt injection warning, accessed 2026-11-12
The two Python files were run with Python 3.14, twice with identical output (cmp); settings.json was validated with a JSON parser. The installation, Claude Code and any model were not run: whether the hook is loaded by your installation is checked with /hooks.

Commenti
Caricamento commenti...
Sign in to comment