Claude Code basics. This short tutorial explains how to initialize a project with the/initcommand, how to clear or edit the input line, and how auto mode cuts down permission prompts. It also shows how to choose between Claude Opus 5.5 and Claude Fable 5.2. It lists the current best practices and explains how to audit your prompts with/doctor prompt-audit. Finally, it shows how to delegate tasks to other agent CLIs, how to merge trivial changes automatically, how to use an API key and when to use the CLI or the Claude app.
1. Using Claude Code
Claude Code is a command line tool from Anthropic that lets you delegate coding tasks to the Claude AI model directly from your terminal.
You start it by running the claude command in your project directory.
1.1. Initializing a project with /init
Run the /init command in the Claude Code prompt to let Claude analyze your codebase and generate a CLAUDE.md file.
This file contains project documentation, for example, build commands and code conventions, and is loaded automatically at the start of every session.
Review the generated file and remove everything Claude can work out from the code itself.
Commit CLAUDE.md to your repository so that the whole team benefits from it.
/init
1.2. Clearing and editing the input line
While you are typing at the prompt, pressing Esc once clears the entire current input line. A single press of Ctrl+C does the same. For example, if you pasted 20 words into the prompt by mistake, Esc is the fastest way to start fresh. While Claude is working on a request, Esc interrupts the current action instead.
If you only want to delete part of the input, the usual readline-style shortcuts also work in the Claude Code prompt:
-
Ctrl+U deletes everything from the cursor back to the start of the line.
-
Ctrl+K deletes from the cursor to the end of the line.
-
Ctrl+W deletes the word before the cursor, which is handy to nibble away a few words.
1.3. Switching permission modes with Shift+Tab
Claude Code runs in one of several permission modes, which control how much Claude is allowed to do without asking you. Press Shift+Tab to cycle through them:
- Manual mode
-
Its value in the configuration files is
default. Claude reads files without asking, but asks for your permission before editing files or running commands. - Accept edits mode
-
Claude applies file edits and common file system commands such as
mkdir,mv,cp,rmandsedinside your working directory without asking for confirmation each time. Other shell commands still need your approval, and so do writes to protected paths such as.gitand removals of critical paths. - Plan mode
-
Claude only reads the codebase and presents a plan, without making any changes. This is useful to review the intended approach for a larger task before any file is touched.
- Auto mode
-
Claude runs edits and commands without asking you. A separate classifier model reviews actions such as shell commands and network requests before they run. Reads and file edits in your working directory skip this review, except writes to protected paths such as the
.gitfolder or Claude’s own configuration. It blocks actions that go beyond your request, target infrastructure it does not recognize, or appear to be driven by hostile content Claude has read, for example on a web page. If the classifier blocks an action 3 times in a row or 20 times in total, auto mode pauses and Claude Code asks you again. Auto mode is the last entry in the cycle and only shows up if it is available for your model and provider and not disabled by your organization.
The currently active mode is shown at the bottom of the Claude Code interface.
You can also start directly in a mode, for example with claude --permission-mode auto.
Auto mode is the best default for most work, because it removes nearly all permission prompts but still keeps a safety net. It reduces risk, but does not guarantee safety, so keep reviewing what Claude does.
2. Configuring auto mode in settings.json
With Claude Code 2.1.283 or later, interactive terminal and VS Code sessions start in auto mode by default.
To make this explicit, or to use it with older versions, set the default mode in your user settings file ~/.claude/settings.json.
{
"permissions": {
"defaultMode": "auto",
"ask": ["Bash(git push *)"]
},
"autoMode": {
"environment": [
"$defaults",
"Source control: github.example.com/acme-corp and all repositories under it"
]
}
}
The ask rules still prompt you in auto mode, and deny rules are checked before the classifier.
In this example, Claude asks before running a command that starts with git push.
The rule matches the command text, so a variant such as git -C dir push is not covered.
Use a PreToolUse hook if you need a check on the full command.
The autoMode block tells the classifier which infrastructure you trust.
Besides environment, it accepts the allow, soft_deny and hard_deny lists, each containing rules written in plain English.
Always keep the $defaults entry, as it adds the built-in rules.
Without it, the built-in rules for this list are dropped.
Claude Code does not accept defaultMode: auto or the autoMode block from the project files .claude/settings.json and .claude/settings.local.json.
Put both settings only into ~/.claude/settings.json or the managed settings of your organization.
|
Run claude auto-mode defaults in your terminal to inspect the built-in rules.
Administrators can turn auto mode off with "permissions": { "disableAutoMode": "disable" } in the managed settings.
3. Choosing the model and effort
For demanding coding work, Claude Code offers two top models:
- Claude Opus 5.5 (
claude-opus-5-5) -
Built for long-running agentic coding. It is a strong default for most coding tasks. It requires Claude Code 2.1.280 or later.
- Claude Fable 5.2 (
claude-fable-5-2) -
Built for demanding reasoning and long-horizon agentic work. On the API, it costs twice as much per token as Opus 5.5. Use it for hard design problems, tricky bugs and large refactorings. It requires Claude Code 2.1.321 or later. Depending on your plan, Fable usage can bill to usage credits instead of your plan’s included limits.
For routine daily coding tasks, Claude Sonnet 5.5 costs less and is selected with the sonnet alias.
It requires Claude Code 2.1.284 or later.
Switch the model with the /model command or start Claude Code with the --model option.
On the Anthropic API, the aliases opus, sonnet and haiku select the newest version, while cloud providers may map them to older models.
The fable alias selects Fable 5.2, but no Fable model is a default, so you always choose it explicitly.
Use the full model ID to pin a specific one.
In Claude apps gateway sessions, the fable alias resolves to the older Fable 5, so select Fable 5.2 there with /model claude-fable-5-2 if your gateway serves it.
In the Claude Code prompt, type:
/model fable
In your shell, use:
claude --model claude-opus-5-5
The effort level controls how much the model thinks before it answers.
Opus 5.5 and Fable 5.2 both start at medium.
Set it with /effort <level>, where the level is low, medium, high, xhigh or max.
Without an argument, /effort opens a slider.
Raise the effort for work where verification matters, such as a bug fix in an existing codebase, and lower it if you want faster answers.
Reserve xhigh and max for tasks where you have seen a real quality gain.
To get deeper reasoning for a single request, add the keyword ultrathink to your prompt.
4. Best practices
With current models, a plain prompt in a fresh session usually does the right thing. Your job is to give Claude what it cannot see in the code:
-
Write a specific prompt. Name the file, describe the symptom and say what "fixed" looks like. For example, instead of "fix the login bug", write "login fails after the session times out, look at the token refresh in src/auth/, write a failing test that reproduces it, then fix it".
-
Give Claude a check to run. A test, a build or a linter which comes back with pass or fail lets Claude verify and fix its own work instead of stopping when the result only looks done.
-
Say "be ambitious" if you want more. Claude reads a request conservatively and builds the smallest thing that satisfies it.
-
Let Claude interview you. If you have not thought a feature through, ask Claude to interview you until it could write the spec, then build from that spec in a fresh session.
-
Keep
CLAUDE.mdshort. Only write down what Claude cannot work out from the code, such as test commands, misleading code and team decisions. -
Use hooks for rules without exceptions.
CLAUDE.mdholds guidelines and Claude may decide one does not apply. A step that must happen every time belongs in a hook, and an action that must never happen belongs in a deny rule. -
Run
/clearbetween unrelated tasks. After two failed corrections, run/clearand write a better prompt instead of a third correction.
4.1. What you can stop doing
Several older tips are no longer needed with current models:
-
Writing IMPORTANT or ALL CAPS into your instructions. Current models follow a plainly worded line, and extra emphasis makes Claude over-apply the rule.
-
Writing "think hard" or "be thorough" into the prompt. Use the effort level instead, or
ultrathinkfor a single turn. -
Using subagents to protect your context window. Most current models have a 1M token window and compaction happens automatically. Subagents are still useful for parallel work and independent reviews.
-
Telling Claude to keep going or not to be lazy. Give it a check to pass instead.
-
Describing your architecture and file layout in
CLAUDE.md. Claude reads the repository itself.
4.2. Auditing your prompts with /doctor prompt-audit
Instructions written for older models often hurt newer ones.
The /doctor prompt-audit command checks your CLAUDE.md, CLAUDE.local.md and AGENTS.md files as well as the rules, skills, commands, subagents and output styles in .claude/ and ~/.claude/.
/doctor prompt-audit
/doctor prompt-audit .claude/skills/deploy
It reports instructions written for older models, references to files or commands which do not exist and conflicting instructions.
For each finding, it proposes an edit and changes nothing until you confirm.
Pass a path to audit only a single file or directory.
The command requires Claude Code 2.1.283 or later and runs through the bundled /claude-api skill, so it is unavailable if you have turned that skill off.
Run /doctor prompt-audit after every model upgrade.
|
5. Tips and tricks for efficient usage
The following commands and shortcuts save time and tokens in daily work.
5.1. Steer a running session
-
Press Esc to stop Claude mid-action. Everything up to that point is kept, so you can redirect it without losing work.
-
Press Esc twice on an empty prompt, or run
/rewind, to roll the code, the conversation or both back to an earlier prompt. This makes it cheap to try the bolder approach first. Checkpoints only cover files Claude changed with its own edit tools, so keep using Git as well. -
Type a message while Claude works. Claude Code queues it and Claude reads it after the current turn.
-
Use
/btwfor a quick side question which should not end up in the conversation history.
5.2. Give Claude context quickly
-
Type
@followed by a path to add a file to your message. -
Start a line with
!to run a shell command yourself, for example!git status. Claude sees the command and its output. -
Paste a screenshot or an error message instead of describing it.
5.3. Keep the context small
-
Run
/contextto see what fills the context window, for example largeCLAUDE.mdfiles or MCP servers you do not use. -
Run
/compactwith a focus, for example/compact keep the API changes and the test commands, to summarize a long session. -
Run
/usageto see what your session and your plan usage cost. -
Turn off MCP servers you do not need with
/mcp, because their tool descriptions are sent with every request. -
Set
model: haikuin the definition of a subagent which only does simple jobs, such as collecting files or checking links.
5.4. Work across sessions
-
Run
/rename oauth-migrationto name a session, and continue it later withclaude --resume oauth-migration. -
Run
claude --continueto resume the most recent session in the current directory. -
Run
/branchto try a different direction in a copy of the conversation, and return to the original with/resume. -
Use
/goalwith a condition, for example/goal all tests in the auth module pass, to let Claude keep working across turns until the condition holds.
5.5. Turn repetition into tools
-
If you type the same instructions more than twice, put them into a skill in
.claude/skills/<name>/SKILL.mdand start it with/<name>. A skill only loads its full text when it is used, so it costs less context than the same text inCLAUDE.md. -
Ask Claude to write a hook for you, for example
write a hook that blocks edits to the migrations folder, and check the result with/hooks. -
Run
/terminal-setuponce so that Shift+Enter inserts a new line in your terminal.
6. Running agents non-interactively
6.1. Running Claude Code with claude -p
The -p option runs a single prompt without the interactive interface and prints the result.
This makes Claude Code usable from scripts, Git hooks and CI pipelines.
claude -p "Find and fix the bug in auth.py" --allowedTools "Read,Edit,Bash(npm test *)"
cat build-error.txt | claude -p "Explain the root cause of this build error"
claude -p "Summarize this project" --output-format json
--allowedTools approves the listed tools without asking.
A -p run usually has nobody to ask, so list every tool the run needs.
For locked-down CI runs, add --permission-mode dontAsk, which denies every call that is not allowed.
With --output-format json, the result also contains the session ID and the cost of the run.
For scripts and CI, add --bare.
It skips the discovery of hooks, skills, plugins, MCP servers and CLAUDE.md, so the run starts faster and does not execute hooks from a repository you have not reviewed.
Bare mode does not read your subscription login, so authenticate with an API key, see Using an API key instead of a subscription.
6.2. Delegating tasks to other agent CLIs
Claude Code can call other coding agents as ordinary shell commands. This is useful to get a second opinion from a different model or to use a subscription you already pay for. Each of these tools has a non-interactive mode:
- Google Antigravity CLI (
agy) -
agy -p "Review the changes in src/ and list possible bugs" --output-format jsonSelect the model with
--model, and runagy modelsto list the available ones.agyuses the credentials of your last interactive login, so runagyonce interactively before you call it from a script. - GitHub Copilot CLI (
copilot) -
copilot -p "Write unit tests for src/parser.ts" --allow-tool='write, shell(npm:*)' --no-ask-user -s--allow-tooland--deny-toolapprove or block single tools.-sprints only the answer, and--no-ask-userkeeps the agent from waiting for input. - OpenCode (
opencode) -
opencode run --model anthropic/claude-sonnet-5-5 "Fix the failing test"--format jsonprints newline-delimited JSON,--agentselects an agent and--autoapproves permissions that are not explicitly denied.
To let Claude delegate, ask for it in your prompt, for example "ask Copilot for a second review of this diff with copilot -p and compare its findings with yours".
If you do this regularly, describe the exact command in a skill, so Claude uses the same flags every time.
Follow these best practices for delegation:
-
Give the other agent one self-contained task with a clear result, such as a review, a test file or a list of findings.
-
Approve only the tools the task needs. Avoid
--allow-all-tools,--yoloor--dangerously-skip-permissionsoutside of a sandbox or container. -
Request JSON output, so Claude can parse the result reliably.
-
Let only one agent edit the same files at a time. Use a separate Git branch or worktree if several agents change code.
-
Treat the output of another agent like a pull request from a colleague and let Claude or a person review it.
7. Merging trivial changes automatically
GitHub auto-merge merges a pull request as soon as all required reviews and status checks pass. Combined with Claude, a small change such as a typo fix or a dependency bump goes from prompt to merged commit without you waiting for the build.
7.1. Setting up auto-merge on GitHub
-
In your repository, open and select Allow auto-merge in the Pull Requests section.
-
Add a branch protection rule for your main branch and enable Require status checks to pass before merging with your build and test jobs. For changes that need a human look, also enable Require pull request reviews before merging.
-
Enable auto-merge on a pull request with the Enable auto-merge button or with the GitHub CLI.
gh pr merge --auto --squash
Auto-merge waits for the requirements of the branch. If a pull request can already be merged, GitHub does not show the auto-merge option.
7.2. Letting Claude drive the pull request
Ask Claude to open the pull request and enable auto-merge in the same prompt, for example "fix the typo in README.md, open a pull request and enable auto-merge with gh pr merge --auto --squash`".
If you use this regularly, add the rule to your `CLAUDE.md, for example "for documentation-only changes, enable auto-merge after opening the pull request".
To get the pull request green without you, turn on auto-fix.
With auto-fix, Claude watches the pull request and pushes a fix when a CI check fails or a reviewer leaves a comment with a clear request.
Run /autofix-pr in the terminal while you are on the branch of the pull request, or tell Claude in a cloud session to auto-fix it.
Auto-fix requires the Claude GitHub App on your repository.
Together, Claude fixes the failing checks, GitHub merges the pull request once everything passes, and you only look at the changes which need a review.
Keep these limits in mind:
-
Use auto-merge only for changes where passing checks are enough proof, and keep a required review for everything else.
-
Auto-fix cannot react to merge conflicts, because GitHub sends no event for them. Ask Claude to rebase the branch in that case.
-
GitHub disables auto-merge if someone without write access pushes to the branch.
8. Using an API key instead of a subscription
By default, Claude Code uses the subscription of your claude.ai account. To bill usage against prepaid credits of the Claude Console instead, create an API key on platform.claude.com and export it before you start Claude Code.
export ANTHROPIC_API_KEY=sk-ant-...
claude
In an interactive session, Claude Code asks once whether to use the key and remembers your choice.
You can change it later with the Use custom API key toggle in /config.
In claude -p runs, the key is always used when it is set.
An approved API key takes precedence over your subscription login, so run unset ANTHROPIC_API_KEY to switch back.
Use /status to see which credential is active.
As an alternative to an API key, choose the Anthropic Console account at the /login prompt and sign in with your Console account.
For CI pipelines that should use your subscription, generate a long-lived token with claude setup-token and pass it as CLAUDE_CODE_OAUTH_TOKEN.
This token does not work together with --bare.
9. CLI or desktop app
Claude Code runs the same engine in the terminal, the Claude desktop app, IDEs, the web and on mobile. Configuration, project memory and MCP servers are shared between the local surfaces, so you can mix them on the same project.
| Task | Better in the CLI | Better in the Claude app |
|---|---|---|
Scripting and automation |
Scripting with |
Scheduled tasks work in both. |
Reviewing changes |
Fine for small diffs in the terminal. |
The visual diff viewer and the app preview make larger changes easier to review. |
Parallel work |
Possible with several terminals and Git worktrees. |
Parallel sessions with Git isolation are built in. |
Remote servers and containers |
Runs directly on the server or inside a container. |
Connects to a remote machine over SSH, with fewer features than a local session. |
Working away from your computer |
Steer a running session from your phone with Remote Control. |
Cloud sessions keep running after you disconnect, and Dispatch sends tasks from the mobile app to your desktop. |
Model providers |
Supports Amazon Bedrock, Google Cloud’s Agent Platform and Microsoft Foundry. |
Supports Google Cloud’s Agent Platform in Enterprise deployments and LLM gateways, while Amazon Bedrock and Microsoft Foundry need the separate Claude Desktop on 3P setup. |
Use the CLI if you live in the terminal or want to automate. Use the app if you prefer visual review, run many sessions in parallel or want to start tasks from your phone.
10. Links and literature
If you need more assistance we offer Online Training and Onsite training as well as consulting