Modified

Claude Code: the complete guide

Claude Code is a coding agent from Anthropic: a program that reads your project, changes files and runs commands for you. You describe the task in plain language, and the agent makes a plan, makes the change and checks the result. The tool runs in the terminal, in VS Code and JetBrains, in the Claude desktop app and on the web. You need a paid Claude plan or a Claude Console account, and you must be at least 18, according to Anthropic's terms. This guide is part 2 of 3 and starts from zero. If AI is new to you, begin with Start here.

  1. Readgathers context from files and git
  2. Planpicks the next step from what it learned
  3. Changeedits files and runs commands
  4. Checkruns tests and reads the result
Claude Code works in a loop until the task is done, and you can interrupt with Esc at any time.

Choose your path

Get started

What do you need to run Claude Code?

Claude Code needs a little preparation. Tick off the list before you install. The requirements are on Anthropic's setup page at the time of writing.

  • A computer with macOS 13, Windows 10 version 1809, Ubuntu 20.04, Debian 10 or Alpine Linux 3.19 or later, and at least 4 GB of working memory (RAM), according to Anthropic's setup page.
  • A paid Claude plan (Pro, Max, Ultra, Team or Enterprise) or a Claude Console account, Anthropic's developer site where you pay for usage. The Free plan does not include Claude Code, according to the setup page.
  • At least 18 years of age. Anthropic's consumer terms require it for a Claude account, as part 1 on Claude describes.
  • An internet connection and a country where Anthropic offers its services. Sweden is on Anthropic's list of supported countries.
  • No experience with the terminal. The section What is a terminal? further down explains what you need.
  • Git, if you want to save versions of your work. Claude Code works without git, according to the setup page. On Windows, download Git for Windows from git-scm.com/downloads/win and click Next on each screen, as Anthropic's terminal guide shows. On a Mac, install git with xcode-select --install, and on Ubuntu and Debian with sudo apt-get install git, according to git-scm.com.

What is Claude Code?

Claude Code is a program that lets Claude work directly in your files. Anthropic calls the program an agentic coding tool, meaning a tool that works on its own over several steps. The tool reads the code in your project, edits files, runs commands and connects to your development tools.

The chat in Claude, described in part 1, suggests code that you copy yourself. Claude Code does the work: it opens the files, writes the change, runs the tests and reads the error messages. Tests are small programs that check that the code works.

Claude Code runs a language model from the Claude family and gives the model tools. With those tools the model reads and writes files, searches the code, runs commands and searches the web. Calls like these are called tool calling. Each result goes back to the model, which picks the next step. What is an AI agent? explains programs like this.

Who is Claude Code for?

Claude Code is for anyone who wants an AI to do the work in the files, not just suggest it.

Developers use Claude Code to build features, fix bugs, write tests and resolve conflicts in git. A bug is a mistake in the code. Git is the program that keeps versions of the code, and a conflict happens when two changes clash.

You do not need to know how to code, according to Anthropic's terminal guide for new users. You describe what you want, and Claude writes the code.

If you do not program, you can ask the agent to build a simple web page, rename pictures after what they show or plan a project. Read what Claude wants to do before you approve it.

What is a terminal?

Claude Code runs in a terminal, a window where you type commands instead of clicking. A program you control that way is called a CLI. You start Claude Code by typing claude and pressing Enter. The list Words you meet in the terminal, in this section, explains the rest of the words.

You open the terminal from the keyboard, according to Anthropic's terminal guide. On a Mac, press Cmd and Space, type Terminal and press Enter. On Windows, press Win and X and choose Windows PowerShell or Terminal. On Linux, press Ctrl, Alt and T.

The terminal ignores mouse clicks. You move the cursor with the arrow keys.

You copy the commands in this guide and paste them in. Anthropic's terminal guide gives Cmd and V on a Mac, Ctrl and V or a right-click in PowerShell, and Ctrl, Shift and V on Linux.

Claude Code works in the folder where you start it and in the folders below it. So always start in your project folder. Your first session shows how to create a folder.

How to read a terminal line

Mac (zsh)anna@macbookmysite%claude
Windows (PowerShell)PSC:\Users\Anna\mysite>claude
WSL 2 and Linux (bash)anna@pc:~/mysite$claude
  • Your user name and the computer name
  • PS means you are in PowerShell
  • The folder you are in
  • The sign: the computer is waiting for you
  • The command you type and run with Enter
Three systems, the same parts. You only type the command after the sign.

Words you meet in the terminal

Terminal
A window where you type commands instead of clicking. On a Mac the app is called Terminal; on Windows, Terminal or PowerShell.
Command
A line of text that tells the computer what to do, for example cd mysite. You type the line and press Enter.
CLI
Command-line interface: a program you use by typing commands in the terminal. Claude Code, Codex and Antigravity CLI are CLI programs.
Folder and path
The terminal is always in a folder. The path is the folder's address, for example ~/Documents/mysite, where ~ means your home folder. cd changes folder and ls (on Windows dir) lists what is in it.
Bash and zsh
The shell, the program inside the terminal that reads your commands on Mac and Linux. Macs use zsh, most Linux computers bash. The commands are almost always the same.
PowerShell
The modern Windows shell. The line starts with PS, for example PS C:\Users\Anna>. Choose PowerShell when a guide gives a Windows command.
CMD
Command Prompt, the older Windows shell. The line starts without PS, for example C:\Users\Anna>. PowerShell commands often do not work in CMD.
WSL 2
Windows Subsystem for Linux: Linux running inside Windows. Many developers on Windows work in WSL 2, because the commands are then the same as on Mac and Linux. You install it with wsl --install in PowerShell and restart the computer.
IDE and VS Code
An IDE is a program for writing code, with your files on the left and a terminal at the bottom. VS Code is a free IDE from Microsoft. Claude Code and Codex come as VS Code extensions, so you can work there instead of in a separate terminal window.
Package manager
A program that installs other programs for you: Homebrew (brew) on Mac, WinGet (winget) on Windows, and npm (npm) for programs that need Node.js.
Environment variable
A named value the terminal remembers, for example an API key. Programs read the value without it being written in the code.

How do you install Claude Code?

You install Claude Code with one command in the terminal. The command differs between systems, so pick the heading for your computer.

The installation is done when the terminal prints Claude Code successfully installed!, according to Anthropic's terminal guide. The command shows nothing while the files download, so leave the window open and wait.

Install Claude Code on a Mac

Open Terminal, paste the command and press Enter. Claude Code needs macOS 13 or later, according to Anthropic's setup page.

Terminal
curl -fsSL https://claude.ai/install.sh | bash

Install Claude Code on Linux

Open the terminal and run the same command as on a Mac. Anthropic's setup page lists Ubuntu, Debian and Alpine among the supported systems. Alpine needs a few extra packages, which the setup page lists.

Terminal
curl -fsSL https://claude.ai/install.sh | bash

Install Claude Code on Windows

Open PowerShell, paste the command with Ctrl and V and press Enter. You do not need to run as administrator, according to Anthropic's setup page. The line in PowerShell starts with PS. Without PS you are in CMD, the older Windows shell, and then you use the CMD command. Git for Windows gives Claude Code the Bash shell, and without it Claude Code uses PowerShell. Anthropic recommends Git for Windows but does not require it.

irm https://claude.ai/install.ps1 | iex

Install Claude Code in WSL 2 on Windows

WSL 2 is Linux running inside Windows. Choose WSL 2 if you want the sandbox, which plain Windows does not have, according to Anthropic's setup page. Install WSL with wsl --install in PowerShell as administrator and restart the computer, according to Microsoft's guide. Then open the Linux terminal and run the Linux command there. You also start Claude Code inside WSL, not from PowerShell.

Install WSL
Terminal
wsl --install
Install Claude Code in WSL
Terminal
curl -fsSL https://claude.ai/install.sh | bash

Check the installation

Open a new terminal window and type claude --version. A version number means the installation worked.

Terminal
claude --version

Install with Homebrew or WinGet

Homebrew on a Mac and WinGet on Windows are package managers, programs that install other programs. With them, Claude Code does not update automatically, according to Anthropic's setup page. The standard installation updates itself in the background.

brew install --cask claude-code

Your first Claude Code session, step by step

Your first session takes a few minutes. The steps follow Anthropic's quickstart and terminal guide.

1. Create a folder and start

The mkdir command creates a folder, and cd goes into it. Run the three lines one at a time and press Enter after each. The folder mysite ends up in your user folder, where the terminal starts, for example C:\Users\YourName on Windows. If you already have a project, type cd and the path to it instead, and then claude.

Create a folder and start Claude Code
Terminal
mkdir mysite
cd mysite
claude

2. Sign in

The first time, Claude Code opens your browser and you sign in with your Claude account. If no browser opens, press c to copy the sign-in address. The terminal prints Login successful when you are done, according to Anthropic's page on signing in. Use /login to switch accounts later.

3. Trust the folder

Claude Code asks whether you trust the files in a folder where you have not run it before. Say yes only for your own projects and for code whose origin you know.

Accessing workspace:

~/mysite

Quick safety check: Is this a project you created or one you trust? (Like your own code, a well-known open source project, or work from your team). If not, take a moment to review what's in this folder first.

Claude Code'll be able to read, edit, and execute files here.

  1. 1. Yes, I trust this folder
  2. 2. No, exit
  1. Your own project or code you know. Claude can read, change and run files in the folder.
  2. Claude Code exits. Choose this for code you downloaded and have not read.
Choose with the arrow keys and press Enter. A drawing based on Claude Code 2.1 at the time of writing. The words and the layout can change between versions.

4. Ask for something small

Type what you want in plain language and press Enter, for example "make a simple web page that says hello". In the starting mode, Auto, Claude Code mostly works without asking. If a permission question appears, press Enter to choose Yes, as Anthropic's terminal guide shows. Read what Claude wants to do first.

Bash command

git init

Do you want to proceed?

  1. 1. Yes
  2. 2. Yes, and don't ask again for git init commands in ~/mysite
  3. 3. No, and tell Claude what to do differently (esc)
  1. Allow the command this time. Enter chooses this answer.
  2. Allow the same kind of command in the folder from now on.
  3. Stop and type what Claude should do instead. Esc does the same.
Read the command before you answer. A drawing based on Claude Code 2.1 at the time of writing. The words and the layout can change between versions.

5. Open the page

Claude creates an HTML file, the file that holds the web page, in the mysite folder. Open the folder in Finder on a Mac or File Explorer on Windows and double-click the file, and the page opens in your browser. If you do not know where the folder is, ask Claude "where is the file?", and Claude answers with the full path.

6. Ask about an existing project

In a project that already exists, start with a question instead of a change. Ask, for example, "what does this project do?" or "explain the folder structure". Claude reads the files it needs by itself, so you do not have to paste anything.

7. Save versions with git

Git saves versions of your files, so you can always go back. Install git first, as the list of things you need shows. The first time, give git your name and email, because git writes them into every saved version, according to git-scm.com. Replace the name and address in the commands with your own. Then ask Claude: "make this folder a git repo and save the files in a commit with a clear message". A repo is a folder git keeps track of, and a commit is a saved version.

Set your name and email for git once
Terminal
git config --global user.name "John Doe"
git config --global user.email johndoe@example.com

8. Exit

Press Ctrl and C twice, or type /exit, to end the session. If Claude is still working, the first press stops the work. Ctrl and D twice also exits, according to Anthropic's page on interactive mode.

How you work

How does Claude Code work?

Claude Code works in an agent loop. Anthropic splits the loop into three phases: gather context, take action and check the result. The picture in this guide shows taking action as two steps, plan and change, so it has four steps. Say "fix the failing tests", and the agent runs the tests, reads the errors, changes the right files and runs the tests again.

You can step in at any time. Esc stops Claude at once, and Claude keeps the work done so far. You can also type a correction and press Enter while Claude works. A person being able to step in like this is called human-in-the-loop.

Claude Code saves a snapshot of every file before it edits that file. Press Esc twice with an empty input line, or type /rewind, to go back. Snapshots only cover files. A database, a call to another service or a published site cannot be rewound, so save often with git.

Everything Claude Code reads, writes and runs ends up in the context window, the model's working memory. When the window starts to fill up, the agent summarises the conversation automatically, and details from the start may get lost. Start over with /clear when you switch tasks, because old context costs you and confuses Claude.

What is Claude Code allowed to do? Permissions and modes

Claude Code has modes that decide what it may do without asking you first. The modes control the tools' permissions. In the terminal you switch mode with Shift and Tab, or with Alt and M in some Windows terminals, according to Anthropic's page on interactive mode. You can also pick a mode at startup with the --permission-mode flag. A flag is an addition to a command and starts with a hyphen.

A sixth mode, dontAsk, runs only tools you approved in advance and denies the rest. Anthropic suggests it for scripts and automated pipelines.

Anthropic's documentation names the modes like this, from most careful to most free:

  • Plan (plan): Claude Code reads and explores but does not edit the files in your project. Claude presents a plan, and nothing changes until you approve it.
  • Manual (default): Claude Code reads freely but asks before it changes files, runs commands or goes online. Choose Manual when you want to review every step.
  • Accept edits (acceptEdits): Claude Code changes files and runs common file commands without asking, such as mkdir, which creates folders, and mv, which moves files. For other commands it asks first.
  • Auto (auto): a second model reviews each action in the background instead of you and blocks the risky ones. Auto is the starting mode in the terminal and in VS Code at the time of writing, according to Anthropic's page on the modes. If the session cannot use Auto, it starts in Manual.
  • Bypass permissions (bypassPermissions): Claude Code runs everything without asking.

The modes from careful to free

  1. Reads and planschanges nothing
    • Plan
  2. Asks firstyou approve each change
    • Manual
  3. Does more alonewithin limits you set
    • Accept edits
    • Auto
  4. Never asksonly in an isolated environment
    • Bypass permissions

How do you write good instructions for Claude Code?

A good instruction says what to do, which rules apply and how Claude will know it worked.

Specific instructions get targeted changes. "Fix the bug" sends Claude on a broad search. "Fix the login bug where users see a blank screen after a wrong password" points straight at the problem.

Anthropic also advises you to split large tasks into numbered steps and to let Claude explore the code before anything changes.

Start in Plan mode for larger tasks. Let Claude read and propose a plan, correct the plan and then approve it. According to Anthropic, this saves expensive rework when the first direction turns out wrong.

Give Claude a way to check its own work, for example a test that should pass, an expected result or a screenshot of how the page should look. Correct it in the same conversation instead of starting over. The prompt guide covers the basics of good instructions to an AI.

Add a contact form to the home page with name, email and message. Use the same buttons as the rest of the site and run the tests before you say you are done.

  • Task
  • What it should contain
  • Rules to follow
  • How you know it works
Claude Code works best when you say what, which rules apply and how it should check the result.

What is CLAUDE.md?

CLAUDE.md is a text file with instructions that Claude Code reads at the start of every session. You use it for what Claude cannot guess: how the project is built and tested, which naming rules apply and what Claude must never touch.

Otherwise every session starts with an empty context window. CLAUDE.md is therefore the project's memory. Rules that should apply every time belong in the file, not in the chat.

The /init command creates a first CLAUDE.md for you. Type /init in a session, and Claude reads the project and writes the file.

You share the file in the project folder with your team through git. The file ~/.claude/CLAUDE.md applies to all your projects. Anthropic recommends keeping each file under 200 lines, because long files take up context and are followed less well.

AGENTS.md is the instruction file other coding agents read. Claude Code reads AGENTS.md when there is no CLAUDE.md in the folder or above it, according to Anthropic's memory page. If both exist, Claude reads only CLAUDE.md. Then add the line @AGENTS.md to CLAUDE.md, and both are included.

Claude Code also has an automatic memory. When you correct Claude or say "remember that all text should be in Swedish", Claude saves a note for next time. The /memory command shows CLAUDE.md and the notes. There you can edit them and turn the automatic memory off.

Which commands does Claude Code have?

Commands in Claude Code start with a slash. Type / to see them all, or / and a few letters to filter the list.

The commands in the list have no section of their own in this guide. The descriptions follow Anthropic's command reference.

  • /clear starts a new conversation with an empty context.
  • /compact summarises the conversation and carries on.
  • /context shows what takes up space in the context window.
  • /model switches model.
  • /effort changes how much the model thinks.
  • /resume opens an earlier conversation.
  • /permissions shows and changes what Claude Code may do.
  • /usage shows your usage and the limits of your plan.
  • /help shows the help.
  • /doctor looks for problems in the installation.

Extend Claude Code

Skills, subagents, hooks, MCP and plugins: what is the difference?

Claude Code can be extended in five ways besides CLAUDE.md: skills, subagents, hooks, MCP and plugins. Anthropic's overview of the extensions tells them apart by what they are, what starts them and where they live.

Anthropic suggests starting with CLAUDE.md and adding the rest when a need comes up. If Claude makes the same mistake twice, write the rule in CLAUDE.md. If you keep pasting the same instructions, make a skill. If something should happen every time without you asking, write a hook.

Six ways to extend Claude Code

NameWhat it isWho starts itWhere it lives
CLAUDE.mdInstructions that apply in every sessionClaude Code reads the file at the start of every sessionCLAUDE.md in the project, ~/.claude/CLAUDE.md for all projects
SkillsInstructions and workflows loaded when neededClaude when the request fits, or you with /name.claude/skills/<name>/SKILL.md or ~/.claude/skills/
SubagentsHelper agents with their own context window that return a summaryClaude delegates, or you name the subagent.claude/agents/ or ~/.claude/agents/
HooksCommands that run at a set event, every timeClaude Code itself, on events such as PostToolUsesettings.json in .claude/ or ~/.claude/, or in a plugin
MCPConnections to services and data outside the projectClaude calls the server's tools when the task needs them.mcp.json in the project or ~/.claude.json
PluginsPackages of skills, subagents, hooks and MCP serversYou install with /plugin, then the parts start as usualMarketplaces; installed in ~/.claude/plugins/
The details follow Anthropic's Claude Code documentation at the time of writing.

What are skills in Claude Code?

A skill is a ready-made instruction that Claude Code loads when it is needed. The top of the skill says what it does and when to use it. Claude reads only that description at first and loads the rest when your request fits.

You write the skill in a file called SKILL.md, in its own folder. The folder goes under .claude/skills/ in the project, or under ~/.claude/skills/ if the skill should apply to all your projects.

You can also run a skill yourself with a slash and its name, for example /summarize-changes. Anthropic has merged custom slash commands into skills, so they are the same thing. Files in .claude/commands/ still work. Skills in Claude Code follow Agent Skills, an open standard for skills that several AI tools understand.

The example comes from Anthropic's documentation. The skill summarises the changes you have not saved in git and points out risks. The line that starts with an exclamation mark is special: Claude Code runs the command git diff HEAD and pastes in the result, a diff, meaning a list of what has changed, before Claude reads the skill.

You create the folder with the command for Mac, Linux and WSL, and then save the text as SKILL.md in the folder. On Windows, or if you would rather skip the terminal, ask Claude: "create the folder ~/.claude/skills/summarize-changes and save this text there as SKILL.md".

Create the folder for the skill
Terminal
mkdir -p ~/.claude/skills/summarize-changes
Example skill (SKILL.md)
Terminal
---
description: Summarizes uncommitted changes and flags anything risky. Use when the user asks what changed, wants a commit message, or asks to review their diff.
---

## Current changes

!`git diff HEAD`

## Instructions

Summarize the changes above in two or three bullet points, then list any risks you notice such as missing error handling, hardcoded values, or tests that need updating. If the diff is empty, say there are no uncommitted changes.

What are subagents?

A subagent is a helper agent that Claude Code sends off on a subtask. The subagent has its own context window, its own tools and its own permissions. The subagent returns only a summary, so your main conversation does not fill up with search results and logs. Several agents sharing the work are called a multi-agent system.

Claude Code has built-in subagents. Explore searches the code without changing anything. Plan gathers information in Plan mode. General-purpose handles tasks that need both searching and changes.

You write your own subagents as text files in .claude/agents/ or ~/.claude/agents/. The file sets the name, description, allowed tools and which model the subagent uses. The easiest way is to ask Claude to write the file, according to Anthropic's page on subagents. The section Example of a hook and a subagent shows a finished file.

Anthropic points out that subagents count against the same usage limits as the main conversation.

What are hooks?

Hooks are commands that Claude Code runs automatically at set moments, for example after every file edit or before a command runs.

Hooks differ from CLAUDE.md, according to Anthropic. Claude can choose whether to follow an instruction in CLAUDE.md, but a hook always runs. So use hooks for rules that must never be broken.

A common hook formats the code after every change, meaning it lays the code out the same way everywhere. The formatting hook starts on the PostToolUse event. A hook on PreToolUse can block changes to protected files, and a hook on Notification tells you when Claude is waiting for an answer.

You write hooks in the settings file .claude/settings.json, or you ask Claude to write the hook for you, as Anthropic suggests. The /hooks command shows which ones are active. A hook runs with your permissions, so read it before you add one that someone else wrote. The section Example of a hook and a subagent shows a finished hook.

How do you connect Claude Code to other tools with MCP?

MCP, the Model Context Protocol, is an open standard for connecting AI tools to other systems. An MCP server is a program that gives Claude Code access to a service. With the right server, Claude reads documents in Google Drive, updates tickets in the Jira issue tracker or fetches data from your own tools.

Anthropic suggests a rule of thumb for when you need a server. Connect a server when you notice that you copy data from another tool into the chat.

You add a server with the claude mcp add command, as the Notion example shows. Inside the session you check the server with /mcp. Servers the whole team should have go in the .mcp.json file in the project.

Servers that fetch content from outside can expose you to prompt injection, text that tries to trick Claude, Anthropic warns. Only add servers you trust.

Add an MCP server (Notion as an example)
Terminal
claude mcp add --transport http notion https://mcp.notion.com/mcp

What are plugins in Claude Code?

A plugin is a package of skills, subagents, hooks and MCP servers that you install in one go. You get plugins from a marketplace, a catalogue of plugins. Claude Code adds Anthropic's official marketplace the first time you start a session in the terminal, according to Anthropic's page on plugins. With /plugin you browse the plugins.

An active plugin comes along in every session and runs everything with your permissions, no matter who made it. Turn off plugins you do not use with /plugin.

Editor, app and cloud

Claude Code in VS Code and JetBrains

Claude Code comes as an extension for the VS Code editor and also works in the Cursor editor. Open the Extensions view with Cmd, Shift and X on a Mac or Ctrl, Shift and X on Windows and Linux, search for Claude Code and click Install. Anthropic's VS Code page says the extension needs version 1.94 or later.

The extension gives you a graphical window. There you review plans, see changes side by side and point to files with @. Open a file and click the spark icon at the top right of the editor to begin.

JetBrains makes a family of code editors, among them IntelliJ IDEA, PyCharm, WebStorm and Android Studio. They have their own Claude Code plugin in the JetBrains Marketplace. The plugin needs Claude Code already installed in the terminal and shows changes as a diff in the program's own comparison view. If you run claude in another terminal, connect the two with /ide.

Where to open Claude Code in VS Code

  1. The spark in the editor: Top right. Opens Claude. Only shows when a file is open.
  2. The spark in the side bar: On the left. Shows your sessions. Always visible.
  3. ✻ Claude Code: Bottom right. Works even with no file open.
The spark means Claude Code everywhere in VS Code, according to Anthropic's VS Code page. A drawing based on Claude Code 2.1 at the time of writing. The words and the layout can change between versions.

Claude Code in the desktop app, on the web and on mobile

The Code tab in the Claude desktop app shows changes graphically and lets you run several sessions side by side. Claude Code in the app needs a paid plan.

Claude Code on the web, claude.ai/code, runs the session on a virtual computer at Anthropic instead of on your own computer. You connect your GitHub account and pick a repo. Then you hand over the task, and the work carries on even when your computer is off.

The Claude app for iPhone and Android shows the same sessions under the Code tab.

Cloud sessions are available on Pro, Max, Ultra and Team at the time of writing, according to Anthropic's page on Claude Code on the web. On Enterprise they need a premium seat or a Chat and Claude Code seat. A seat is one user's place in the company subscription. Cloud sessions share the usage limits with all other use of Claude.

The Code tab in the Claude desktop app

  1. Code: The tab where Claude Code lives in the app.
  2. Local: Where Claude works: Local on your computer, Cloud at Anthropic, SSH or WSL.
  3. mysite: The folder Claude works in.
  4. Manual: The mode, the same modes as in the terminal. You can change it during the session.
  5. Sonnet: The model that answers.
The controls under the box run from left to right, according to Anthropic's desktop app page. A drawing based on Claude Code 2.1 at the time of writing. The words and the layout can change between versions.

Can Claude Code run automatically? Scripts and GitHub Actions

Claude Code can work without you sitting there. The -p flag runs one request, prints the answer and exits. That lets you use Claude Code in scripts, small programs that run commands in sequence, and in CI/CD, automated pipelines that test and publish code. With --allowedTools you decide which tools may run without asking.

The same engine is available as the Agent SDK, a package for building your own programs in Python and TypeScript. Part 3 on the Claude API covers the package.

Claude Code GitHub Actions runs the agent in a repo on GitHub. Write @claude in a comment on an issue or on a pull request, a proposed set of changes. Claude then reads the code, makes the change and pushes commits.

The easiest way to install the GitHub connection is /install-github-app in a session. You need to be an admin of the repo.

An API key never belongs directly in the code. Store the key as the ANTHROPIC_API_KEY secret in the repo's settings on GitHub. Secret management explains why.

Run a task without a session
Terminal
claude -p "Find and fix the bug in auth.py" --allowedTools "Read,Edit,Bash"

Advanced

How do you control what Claude Code may do in settings.json?

You write permission rules in a settings file in JSON format. Anthropic's page on permissions describes three kinds of rules: allow runs without asking, ask always asks and deny blocks.

The rules are checked in the order deny, ask, allow, and the first match decides. So a narrower allow rule cannot open up a deny rule, according to Anthropic's page on permissions.

You share the file .claude/settings.json in the project with your team through git. The file ~/.claude/settings.json applies to all your projects, and .claude/settings.local.json applies only to you in one project, according to Anthropic's page on settings.

The example comes from Anthropic's documentation. With these rules, Claude Code runs npm scripts and git commits without asking but refuses commands that start with git push. The star stands for any text.

The rules control the tools, not the model. An instruction in CLAUDE.md shapes what Claude tries to do, but only the rules decide what Claude Code allows, Anthropic writes. The /permissions command shows every rule and the file it comes from.

Allow and deny rules
Terminal
{
  "permissions": {
    "allow": [
      "Bash(npm run *)",
      "Bash(git commit *)"
    ],
    "deny": [
      "Bash(git push *)"
    ]
  }
}

How do you continue an earlier Claude Code session?

Claude Code saves your sessions, so you can pick up where you left off. claude --continue opens the most recent session in the folder you are in. claude --resume shows a list where you pick a session, and with a name after the flag you open that session directly, according to Anthropic's page on sessions.

Inside a session, /resume does the same. Give a session a name when you start it, with the -n flag, for example claude -n "my-feature-work", and it is easy to find.

Sessions are kept on your computer for 30 days by default, according to Anthropic's page on data usage.

Continue the most recent session
Terminal
claude --continue
Pick an earlier session
Terminal
claude --resume

How do you run several Claude Code sessions at once?

Several sessions in the same folder can overwrite each other's changes. The answer is a git worktree: a separate working folder with its own files and its own branch, sharing history with the main folder, according to Anthropic's page on worktrees. A branch is a parallel version of the code in git.

The --worktree flag starts Claude Code in its own worktree. Run the command with another name in another terminal, and you get a second session that does not clash with the first.

Claude Code creates the folder under .claude/worktrees/ in the repo, on a new branch called worktree- followed by the name. Anthropic suggests adding .claude/worktrees/ to the .gitignore file, so git does not show the folders as new files.

Worktrees need a git repo. The desktop app can also run each session in its own worktree.

Start a session in its own worktree
Terminal
claude --worktree feature-auth

How do you use claude -p in scripts?

The -p flag runs a request without a session and prints the answer. With --output-format you choose what the answer looks like, according to Anthropic's page on running Claude Code from scripts.

In -p mode, Claude Code starts in Manual, and actions that need approval are denied. Approve tools in advance with --allowedTools, or start in Auto with --permission-mode auto, according to Anthropic's page on the modes.

With JSON output, a script can pick out the answer, for example with the jq program. The answer also holds the estimated cost in the total_cost_usd field.

The formats for --output-format are three:

  • text is plain text and the default.
  • json returns the answer as JSON with the result, the session's id and metadata.
  • stream-json sends one JSON line for each event while Claude works.
Answer as JSON
Terminal
claude -p "Summarize this project" --output-format json
Pick out the answer with jq
Terminal
claude -p "Summarize this project" --output-format json | jq -r '.result'

Which keyboard shortcuts does Claude Code have?

The shortcuts in the list cover most of your work in the terminal. The descriptions follow Anthropic's page on interactive mode.

  • Esc stops Claude in the middle of an answer. Claude keeps the work done so far, so you can redirect it.
  • Esc twice clears the input line. If the line is empty, it opens the rewind menu instead, the same as /rewind.
  • Shift and Tab switch mode. In some Windows terminals, Alt and M do it instead.
  • @ followed by the start of a file name suggests files, so you can point Claude to a file.
  • Ctrl and C interrupt what is running. With nothing running, the first press clears the line and the second press exits Claude Code.
  • Ctrl and D twice on an empty line end the session.

Example of a hook and a subagent in Claude Code

The examples come word for word from Anthropic's documentation. The hook runs the Prettier formatter on every file Claude edits. The hook starts on the PostToolUse event, and Edit|Write makes it run only after the tools that edit files. Save it in .claude/settings.json at the root of the project.

The hook needs the jq program, which reads JSON. On a Mac you install jq with brew install jq, and on Debian and Ubuntu with apt-get install jq, according to Anthropic's guide to hooks.

The subagent file creates a reviewer that may only read, with the tools Read, Glob and Grep, and that uses a Sonnet model. The top lists the name, description, tools and model. The text below the dashes becomes the subagent's instruction. Save the file as .claude/agents/code-reviewer.md.

Hook that formats every edited file
Terminal
{
  "hooks": {
    "PostToolUse": [
      {
        "matcher": "Edit|Write",
        "hooks": [
          {
            "type": "command",
            "command": "jq -r '.tool_input.file_path' | xargs npx prettier --write"
          }
        ]
      }
    ]
  }
}
Subagent that reviews code
Terminal
---
name: code-reviewer
description: Reviews code for quality and best practices
tools: Read, Glob, Grep
model: sonnet
---

You are a code reviewer. When invoked, analyze the code and provide
specific, actionable feedback on quality, security, and best practices.

Teams and companies

How does a company use Claude Code?

Companies use Claude Code with Team or Enterprise, with Claude Console or through a cloud provider such as Amazon Bedrock, Google Cloud's Agent Platform or Microsoft Foundry. Anthropic recommends Team or Enterprise as the default choice, because Claude Code and Claude then come in one per-user subscription, according to Anthropic's guide for administrators.

Team is a plan you start yourself, with administration, SSO and centrally managed settings. Enterprise adds, among other things, domain capture, roles with different permissions and a compliance API, according to Anthropic's page on signing in.

Every user's seat must include Claude Code. In Team, the standard seat already includes Claude Code, according to Anthropic's pricing page at the time of writing. If a developer sees the message "You haven't been added to your organization yet", the seat needs to be changed in the admin settings, Anthropic writes.

Sign-in and SSO for Claude Code

SSO, single sign-on, means that users sign in with the company's own account instead of a separate password. SSO, automatic user provisioning (SCIM) and seat assignment are set up for the whole Claude account, not in Claude Code, according to Anthropic's guide for administrators.

Users then sign in with /login in Claude Code, using the account the admin invited. With the settings forceLoginMethod and forceLoginOrgUUID you require the sign-in to belong to your organization, according to Anthropic's page on signing in.

Centrally managed settings in Claude Code (managed settings)

Managed settings are settings the organization decides and that take precedence over developers' own. Anthropic's guide for administrators describes four routes: from the Claude admin console, as a policy in macOS or the Windows registry, as a file on the computer or in the Windows user registry.

From the admin console, Claude Code fetches the settings at startup and then every hour, with no infrastructure of your own. Delivery from the console needs Team or Enterprise and the Owner or Primary Owner role, according to Anthropic's page on server-managed settings.

With managed settings you can, for example, lock permission rules, turn off Bypass permissions mode, limit which MCP servers and plugin marketplaces may be used and choose which models appear. Lists such as permissions.deny merge from all sources, so developers can add rules but not remove the organization's.

Check the result with /status in Claude Code. The Setting sources line then shows Enterprise managed settings and the source that applies, according to the guide for administrators.

What happens to your code and data in Claude Code?

Claude Code runs on your computer but sends your requests and the model's answers to Anthropic, encrypted with TLS, according to Anthropic's page on data usage. File contents Claude reads become part of the conversation and are sent along, because the model cannot answer otherwise.

Free, Pro, Max and Ultra run under the consumer terms. There you choose whether your data may be used to train models. If you allow it, the data is kept for five years, otherwise for 30 days, according to Anthropic's page on data usage.

Team, Enterprise and the API run under the commercial terms. Anthropic does not train models on code or prompts sent under those terms, and the data is kept for 30 days by default, according to Anthropic's page on data usage. Enterprise customers who qualify can get Zero Data Retention, where Anthropic keeps nothing after the request is answered.

Sessions are also stored locally, in plain text under ~/.claude/projects/, for 30 days by default, according to the same data usage page from Anthropic.

Anthropic is a US company. What that means for organizations in Sweden and the EU is explained in data sovereignty and CLOUD Act.

Is there a data processing agreement (DPA) for Claude Code?

A data processing agreement, or DPA, governs how a supplier handles personal data on your behalf under the GDPR. DPA in the glossary explains the term.

Anthropic's Data Processing Addendum is part of the commercial terms, which cover Team, Enterprise and the API. The agreement includes the EU standard contractual clauses for transfers of personal data, according to Anthropic's legal pages.

Free, Pro, Max and Ultra run under the consumer terms instead. If you process personal data in your code, start from the commercial plans.

Security reports such as SOC 2 Type 2 and an ISO 27001 certificate are in the Anthropic Trust Center, according to Anthropic's security page for Claude Code.

How do you roll out Claude Code in a team?

Anthropic advises starting with a small pilot group and measuring cost before you widen the rollout, according to the Claude Code costs page. Anthropic's guide for administrators walks through the decisions in this order:

  • Choose a provider: Team or Enterprise, Console or a cloud provider. The choice decides sign-in, billing and which features are available. Cloud sessions, for example, need a Claude account.
  • Decide how settings reach the computers: from the admin console or with device management tools (MDM).
  • Decide what to lock down: permission rules, the sandbox, MCP servers, plugins and hooks.
  • Track usage. Team and Enterprise have an overview on claude.ai, and usage can be exported with OpenTelemetry, an open standard for telemetry data.
  • Review data handling: retention, Zero Data Retention and Anthropic's security documents.
  • Have a developer check with /status and share Anthropic's quickstart. Anthropic also points to the free courses Claude Code 101 and Claude Code in Action on Claude Academy.

Price, security and comparison

How much does Claude Code cost?

Claude Code is included in Pro, Max, Ultra, Team and Enterprise. Pro costs 20 dollars a month at the time of writing, according to Anthropic's pricing page. Prices change. All plans and prices are in part 1 on Claude.

The plans have limits on how much you can use Claude, and the limits reset at regular intervals, Anthropic's pricing page shows. Claude Code shares the limits with the chat and with Cowork, Claude's agent for everyday tasks.

The /usage command shows how much you have left and what uses the most. When you reach the limit you can wait for it to reset or buy usage credits. You manage the credits with /usage-credits.

With a Console account you instead pay per token, a piece of text a few characters long, with one price for what you send and one for what Claude writes. Part 3 on the Claude API explains how the price is calculated. Among business customers, the average is around 13 dollars per developer per active day at the time of writing, Anthropic states on its Claude Code costs page.

You save the most by clearing with /clear between tasks, choosing Sonnet for everyday coding and writing specific instructions.

Is Claude Code safe?

Claude Code is as safe as the permissions you give it. In Manual mode, Claude Code asks before it changes files or runs commands.

The responsibility for reviewing proposed code and commands lies with you, Anthropic writes. At the very least, read commands that delete, install or send something before you approve them.

Anthropic singles out prompt injection. Prompt injection is text in a file, on a web page or in a ticket that tries to trick Claude into doing something other than what you asked.

Commands such as curl and wget, which fetch data from the internet, are not approved automatically, according to Anthropic's security page. When Claude fetches a web page, a separate model call usually reads the page, and Claude gets that call's answer instead of the whole page.

Anthropic gives three pieces of advice: review commands, do not pipe in content you do not trust, and use a virtual machine for risky tasks. A virtual machine is a separate computer running inside your computer.

The sandbox limits which files and internet addresses Claude's commands can reach. You turn it on with /sandbox, and the operating system then enforces the limits. The sandbox is off by default. Anthropic's sandbox page says it works on macOS, Linux and WSL 2, but not on plain Windows.

The glossary explains sandboxes in more detail. Is AI safe? covers AI and security in general.

Claude Code, Codex or Antigravity CLI?

Claude Code, Codex and Antigravity CLI are coding agents from Anthropic, OpenAI and Google. Claude Code runs the Claude models. Codex comes from OpenAI and is available in the terminal, as an editor extension and in the cloud, according to OpenAI's documentation. Antigravity CLI is Google's coding agent for free accounts and Google AI subscriptions. Google's older Gemini CLI is open source and now targets organizations with Gemini Code Assist, according to the project's page on GitHub.

The agents differ most in their models and in which plan they require. Claude Code needs a paid Claude plan or a Console account.

You bring settings from Codex, Gemini CLI or Cursor into Claude Code with /import. If /init finds settings from Codex or Gemini CLI, the command offers to move them itself, according to Anthropic's command reference.

Claude Code, Cursor or GitHub Copilot?

Cursor is a program for writing code, with an agent built into the editor and its own CLI, according to Cursor's documentation. Cursor runs models from several companies, among them OpenAI, Anthropic and Google, and has its own models. The Claude models are not part of Cursor's included usage: from the Premium plan up, you pay for them at API price from prepaid credit, according to Cursor's models and pricing page at the time of writing. The free plan gives limited use of the agent.

GitHub Copilot is GitHub's AI assistant. Copilot suggests code as you type, answers questions and can take on tasks in a repo and return a pull request for review, according to GitHub's documentation. Copilot is available on GitHub.com, in editors such as VS Code and as Copilot CLI in the terminal, and offers models from several companies, Claude among them. Copilot Free needs no paid plan, and Copilot Pro costs 10 dollars a month at the time of writing, according to GitHub's plans page.

Claude Code differs in three ways. The tool has no free plan. Claude Code is built around the Claude models and comes with Claude's regular subscription. The agent can also be used inside VS Code and Cursor as an extension, according to Anthropic's VS Code page.

Give the same task to two of the tools and compare the results in your own project.

Common questions about Claude Code

Is Claude Code free?

No, Claude Code is not part of the Free plan, according to Anthropic's setup page. Installing it costs nothing, but you need a paid plan, from Pro at 20 dollars a month at the time of writing according to Anthropic's pricing page, or a Console account where you pay for usage. New Console users get a small amount of free credits to test with, according to Anthropic's API pricing page.

Do you need WSL to run Claude Code on Windows?

No, Claude Code runs directly on Windows with PowerShell or CMD, according to Anthropic's setup page. You only need WSL 2 if you want the sandbox or work with Linux tools.

Does Claude Code work in Swedish?

Claude Code understands instructions in Swedish and answers in Swedish. The commands and menus are in English, but you can write to Claude in Swedish.

Which model does Claude Code use?

At the time of writing, Claude Code uses a model from the Opus family by default on the paid plans, according to Anthropic's documentation. You switch model with /model, for example to sonnet for everyday coding or haiku for simple tasks. fable is for the hardest tasks but costs more: on Pro you pay for Fable with usage credits, and on Max and Ultra Fable uses part of the weekly limit, according to Anthropic's help center. Part 1 describes the model families.

What is the difference between Claude Code and Cowork?

Claude Code and Cowork are built on the same agent technology, according to Anthropic's help page on Cowork. Claude Code is made for code and runs in the terminal, in the editor or under the Code tab. Cowork needs no terminal and suits everyday tasks in files and programs. Part 1 describes Cowork.

How do you update Claude Code?

Claude Code updates itself in the background if you installed it with Anthropic's command. To update right away, run claude update, according to Anthropic's setup page. With Homebrew, run brew upgrade claude-code, and with WinGet winget upgrade Anthropic.ClaudeCode.

How do you uninstall Claude Code?

If you installed Claude Code with the standard command, you remove it on Mac, Linux and WSL with two commands, according to Anthropic's setup page: rm -f ~/.local/bin/claude and rm -rf ~/.local/share/claude. On Windows, delete the file claude.exe in .local\bin and the folder .local\share\claude in your user folder. If you installed with Homebrew, WinGet or npm, uninstall with the same tool.

Next partClaude APIBuild your own programs with Claude

Sources: Claude Code: overview · Claude Code: setup · Claude Code: modes · Claude Code: memory · Claude Code: security · Claude Code: costs · Claude Code: organizations · Claude Code: data usage