Commands

Command What it does?
/agents Opens the agent manager. Helps in:
- View all built-in
- Create your own custom agents
- Edit/Delete existing agents
- See currently running agents
- Configure models, tools, permissions, prompts, etc
/claude Start the Claude Code CLI
/clear Clear everything in the context window
/compact Compact the context window
/context Check state of the context
/init Claude will scan the codebase and draft a starting CLAUDE.md
/plan This is plan subagent
claude mcp add --transport http linear-server https://mcp.linear.app/app
claude mcp add --transport stdio dev-utils --python server.py
Add a MCP Server
- http: Remote services, connect over network
- stdio: Local services, connect via standard input/output(those run on your machine)
/mcp List all MCP Servers which are connected and disable which are not in use
shift tab Switch between autoapprove, require permission for command run
Plan Mode(good for complex tasks):
  Within (shift Tab) there is plan mode, which is READ ONLY and does research on code base.
  Then it returns detialed plan to work on.

Recommended Workflow for claude (Explore - Plan - Code - Commit)

1. Explore(/RO Mode): Use claude to explore the code base and understand the project. This helps claude to understand the project
2. Write Test Cases: Ask Claude to write test cases for the project.
3. Write Code: Use claude to write code based on the understanding gained from the Plan mode phase.
4. Review: Review the code written by claude and make any necessary changes.
5. Run Test Cases: Run the code and test its functionality.
6. Commit: Once the code is working as expected, commit the changes to the code base.

Context = Claude Memory

Every command/message we type, code it writes all gets stored in Context

Context Window

Amount of memory Claude can use to remember the project.
Compaction of Context Window: When all memory is occupied, Claude will compact the memory to make space for new memory. Remove unneccesary memory and keep important memory.

Saving Context Window

1. Less MCP Servers:
  MCP Server loads all of the tools into Context(by default), so if there are lot of MCP Servers or unrelated to project, trim them off.
2. Subagents:

Subagents

Usage:
Subagents have their own context window, so if some other task is needed(eg: How auth module work), you can use subagents which will return results to main agent saving the context window
This keeps main agent away from uneeccessary noise. When subagent finishes entire subagent conversation gets completely discarded.

Built in subagents

Claude Code currently includes several built-in subagents

Subagent Meaning
Explore Search codebase, grep files, understand architecture Read-only
Plan Research while in Plan Mode Read-only
General-purpose Multi-step coding, editing, implementation Full tools
statusline-setup Configure /statusline Limited
claude-code-guide Answers questions about Claude Code Read-only

Creating my own subagent

Suppose you repeatedly ask Claude: Review my C++ code for race conditions. Instead of repeating that prompt every day, create: race-condition-reviewer

~/.claude/agents/race-reviewer.md
name: race-condition-reviewer
You are a senior concurrency engineer. Look for

- data races
- deadlocks
- ABA problems
- lock inversion
- atomics misuse

Return fixes.
      

CLAUDE.md

This file is read automatically everytime a session is started
CLAUDE.md contains all the information(project context, build commands, and coding rules) about the project, which you want claude to remember at start of the project.
It is a good practice to keep this file updated with the latest information about the project.
Claude does not fully self-update this file on its own during normal use; it relies on you to maintain it or use initialization commands
Can We upload on git? Yes we should upload this file on git.


# Project 
This is a project to build a web application for managing tasks.

# Commands
- Build the project: `npm run build`
- Run the project: `npm run start`
- Run the tests: `npm run test`
- Run the tests in watch mode: `npm run test:watch`
- Run the tests in watch mode: `npm run test:watch`

# Code Style
Use the following code style:
- Use 2 spaces for indentation
- Use camelCase for variable names
- Use PascalCase for class names
- Use snake_case for function names
- Use kebab-case for file names
- Use double quotes for strings
- Use single quotes for comments

# Documentation to look
@docs/test.md

Places where CLAUDE.md can be present

Location Description
.claude/CLAUDE.md Project-level configuration file
~/.claude/CLAUDE.md User-level configuration file. User can put his personal preferences here.
- How you write code comments

Skills

These are instructions, scripts, examples etc for agents to do that task more accurately & efficiently.

SKILL.md

Define a skill for an agent.

review-pr.md
name: pr-review
description: Review a pull request for code quality, style, and best practices.
        

Now whenever you ask claude to review the PR Can you review this PR?, it will match skill name and use the skill to review the PR.
Claude will read description and match against all available skill descriptions and activates the 1 that match

Places where SKILL.md can be stored

Location Description
.claude/skills Project-level skill files
~/.claude/skills User-level skill files.

CLAUDE.md vs SKILL.md

CLAUDE.md SKILL.md
Loading Loads to every conversation Only load when a request is matched
Typing commands /command needed to be typed Donot need to be typed. Claude applies whenever a matching request is received

MCP (Model Context Protocol)

This is the open source protocol by which claude code connects to external tools and data sources

Scoping of MCP Servers

Scoping means where the MCP Server is stored and who can access it.
1. Local (./.claude.json): Only available in current project
2. User (~/.claude.json): Available to all projects of the user
3. Global (/project/.mcp.json): Checked into git and available to all users of the project

Hooks

Hooks are scripts that run automatically when specific events occur in the development workflow (eg: before editing a file or after git commit).
Common use cases
1. Pre-commit hooks: Run before a commit is made to check for code quality, style, or run tests.
2. Post-commit hooks: Run after a commit is made to perform actions like sending notifications or updating documentation.
3. Autocode formatting after editing a file
4. Blocking dangerous commands like rm -rf or git push

Tool-Level Lifecycle Hooks

1. PreToolUse: Fires right before a tool executes. Used as a safety gate to inspect actions, block dangerous shell commands, or enforce file-access rules.
2. PostToolUse: Fires immediately after a tool succeeds. Used as a quality gate to run linters, format files, log changes, or run tests.
3. PostToolUseFailure: Triggers when a tool execution fails, allowing error logging or recovery management

Configure hooks


.claude/settings.json
{
  "hooks": {
    "pre-commit": [
      "python -m unittest discover tests",
      "black ."
    ],
    "post-commit": [
      "echo 'Commit made!'"
    ],
    "PostToolUse": {
      "matcher": "edit|delete",
    }
  }
}