Thursday, April 2, 2026

How does claude code works?

 Based on the official documentation, here is a summary of how **Claude Code** works.


Claude Code is an agentic terminal assistant that operates in an **agentic loop** to complete tasks. It combines a reasoning model with a set of tools that allow it to act on your project.


### 🔄 The Agentic Loop: Core Operating Principle


When you give Claude a task, it works through three dynamic phases:


1.  **Gather Context:** It uses tools to search files, read code, explore your project structure, and understand the problem.

2.  **Take Action:** It uses tools to edit files, run shell commands (like tests or builds), or search the web.

3.  **Verify Results:** It runs tests, checks error outputs, or reviews changes to see if the goal was met.


Claude decides the sequence of steps based on what it learns from the previous one. It can chain dozens of actions together, course-correcting along the way. You can **interrupt at any point** to steer it in a different direction.


### 🛠️ What Makes Claude Code Agentic: Tools


The agentic loop is powered by two things: a **model** (Claude) that reasons, and **tools** that allow it to act. Without tools, Claude can only respond with text.


The built-in tools generally fall into five categories:


| Category | What Claude Can Do |

| :--- | :--- |

| **File operations** | Read files, edit code, create new files, rename and reorganize |

| **Search** | Find files by pattern, search content with regex, explore codebases |

| **Execution** | Run shell commands, start servers, run tests, use git |

| **Web** | Search the web, fetch documentation, look up error messages |

| **Code intelligence** | See type errors and warnings after edits, jump to definitions, find references (requires plugins) |


### 🗂️ What Claude Can Access


When you run `claude` in a directory, it can access:


-   **Your project files** (in the directory and subdirectories, with permission for files elsewhere).

-   **Your terminal** (any command you could run: build tools, git, package managers, scripts).

-   **Your git state** (current branch, uncommitted changes, recent commit history).

-   **`CLAUDE.md`** (a markdown file for project-specific instructions and conventions).

-   **Auto memory** (learnings Claude saves automatically between sessions, like project patterns).

-   **Extensions you configure** (MCP servers, skills, subagents).


### 🧠 Context Window Management


Claude Code manages the conversation's context window automatically:


-   **Filling up:** As you work, the context fills with conversation history, file contents, command outputs, etc.

-   **Compaction:** When the limit approaches, Claude clears older tool outputs first, then summarizes the conversation. Your requests and key code are preserved, but early detailed instructions may be lost.

    -   **Tip:** Put persistent rules in `CLAUDE.md` rather than relying on conversation history.

    -   Use `/context` to see what's using space.

-   **Skills and Subagents:** These help manage context. Skills load on demand (only name/description are always present). Subagents get their own fresh context, separate from your main conversation, and only return a summary.


### 🛡️ Safety: Checkpoints and Permissions


-   **Checkpoints:** Before editing any file, Claude Code snapshots the current contents. You can undo file changes by pressing `Esc` twice or asking Claude to undo.

-   **Permissions:** Press `Shift+Tab` to cycle through modes:

    -   **Default:** Claude asks before file edits and shell commands.

    -   **Auto-accept edits:** Edits files without asking, but still asks for commands.

    -   **Plan mode:** Uses **read-only tools only** to create a plan you approve before execution.

    -   **Auto mode:** Evaluates all actions with background safety checks (research preview).


### 💡 Tips for Effective Use


-   **It's a conversation:** Start with what you want, then refine. You don't need perfect prompts.

-   **Interrupt and steer:** If Claude goes down the wrong path, type your correction and press Enter.

-   **Be specific upfront:** Reference specific files, mention constraints, and point to example patterns for better first attempts.

-   **Give Claude something to verify against:** Include test cases or paste screenshots of expected UI so it can check its own work.

-   **Explore before implementing:** For complex problems, use **Plan mode** to analyze the codebase first, review the plan, then let Claude implement.

-   **Delegate, not dictate:** Give context and direction, then trust Claude to figure out the details (e.g., "The checkout flow is broken... the relevant code is in `src/payments/`. Can you investigate?").


### 📂 Sessions


-   Each session is tied to your current directory. Conversations are saved locally.

-   **Resume or fork:** Use `--continue` to resume a session. Use `--fork-session` to branch off a new session from a previous one without affecting the original.

-   **Switching branches:** Claude sees the new branch's files, but your conversation history stays the same.


In essence, Claude Code works as an agent that **autonomously navigates your project using a loop of gathering context, acting, and verifying**, while giving you full control to interrupt, steer, and manage its permissions. It's designed to be a conversational, flexible, and safe coding partner from your terminal.

No comments:

Post a Comment