Over time a Claude CodeClaude CodeA coding tool from Anthropic that runs in the terminal and editor inside your repository: it reads files, runs the commands it is allowed, and writes changes. You steer it with CLAUDE.md, settings, agents, commands and skills. sessionSession (sign-in)The state that keeps you signed in from one request to the next, usually kept in a cookie holding a token. Expiring after a while and ending at sign-out limit the damage if it is stolen. grows: files read, test output, side discussions. Two toolsTool useA model asking to run a function the app describes to it, such as a search or reading a file, with structured arguments. The app runs it and returns the result; the model runs nothing itself. help. A subagentSubagentA specialised agent Claude Code calls for a given task, with its own description, tools and separate context, such as a code reviewer or a test writer. It is defined by a file in .claude/agents. takes a task into a separate context and returns a summary. A hookHookA command Claude Code runs automatically on a given event, such as before a tool call or after a file edit. It is used for formatting and checks, and needs care because it runs code on your machine. is a command that runs automatically on a given event, enforcing a rule that does not depend on the model remembering it.
Subagents
A subagent is a MarkdownMarkdownA way to format text with simple marks: # for a heading, * for a list item, backticks for code. README files, CLAUDE.md and skills are written in it, and models read it well. file in .claude/agents/ (or ~/.claude/agents/ for you only), starting with YAML frontmatter:
---
name: test-runner
description: Runs the tests and summarises what failed and its likely cause. Use it after every code change.
tools: Read, Grep, Glob, Bash
---
Run the tests related to the change. For each failing test give its name,
the line where it failed and a likely cause in one sentence. Edit no file.descriptiontells Claude Code when to hand the task to this agentAgentA model working in a loop: it decides the next step, calls a tool, reads the result, and decides again until the task is done. Its power and its risk come from the tools and permissions you give it..toolslimits the tools it may use. Leave it out and the agent inherits all the session's tools, so it is better to set it.- You can add
modelto pick a faster model for a simple task.
The subagent works in its own context windowContext windowThe largest number of tokens a model can look at in one request, counting the prompt, the earlier conversation, files and the answer itself. Whatever falls outside it, the model does not see., so long test output does not fill your main conversation; only the summary comes back. The /agents command lists available agents and helps you create one.
Hooks
A hook is a shellTerminalThe window where you type commands as text instead of clicking, such as running tests or installing packages. Claude Code runs in it, and many developer tools have no other interface. command Claude Code runs on an event. Hooks live in .claude/settings.json. Useful events:
PreToolUse: before a tool runs; it can block it.PostToolUse: after a tool runs, such as formatting a file after an edit.UserPromptSubmit: when you send a promptPromptThe text you give a model to work on, from a short question to long instructions with a role, context, examples and a required format. The quality of the output follows the clarity of the prompt more than its length., before the model reads it.Stop: when Claude Code finishes its reply.
Formatting after every edit:
{
"hooks": {
"PostToolUse": [
{
"matcher": "Edit|Write",
"hooks": [{ "type": "command", "command": "pnpm exec prettier --write ." }]
}
]
}
}matcher selects the tools the hook runs for. In PreToolUse, exit code 2 blocks the tool, and the hook's message reaches Claude Code so it knows why.
Security first
A hook runs on your machine with your permissionsPermissionsWhat a tool or agent may do without asking you: reading files, running commands or reaching the network. Claude Code asks before anything you have not allowed, so do not approve everything without reading., without asking. Read every hook before adding it, especially one that comes with a pluginPluginA Claude Code package that bundles commands, agents, skills, hooks and MCP servers into one unit installed from a marketplace. Read what is in it before installing, especially the hooks. or skillSkillA folder with a SKILL.md file saying when and how the skill is used, possibly with supporting files. The model loads it only when it needs it, so it does not take up context all the time. from a source you do not know; keep commands short and clear; avoid anything that downloads and runs code; and review the settings file in pull requestsPull requestA request on a platform such as GitHub to merge a branch into the main one, showing the diff and allowing review, comments and checks before merging. A small one gets reviewed well; a huge one gets approved unread. as you review code.