
In the fast-evolving world of AI-assisted coding, Anthropic’s Claude Code stands out for one simple reason: it lives in your terminal and behaves like a real engineering partner.
Unlike traditional autocomplete tools, Claude Code is agentic. It doesn’t just suggest snippets — it understands your codebase, plans tasks, edits files, runs commands, and can even prepare pull requests autonomously.
If you’re tired of copy-pasting from chat UIs or being boxed into IDE-specific workflows, Claude Code gives you a low-level, flexible way to use Claude’s most powerful models (Sonnet and Opus) directly where you already work: the command line.
In this deep dive, we’ll go from first install to advanced workflows, with real examples and patterns that actually scale. If you’ve used Cursor or similar tools, you’ll see familiar ideas — but with more control and fewer guardrails.
Let’s get into it.
What Is Claude Code?
Claude Code is Anthropic’s open-source command-line AI coding agent. It runs locally, but gives Claude controlled access to your filesystem, shell, and tools like Git.
That access unlocks real work:
- Reading and modifying files
- Debugging issues end-to-end
- Running tests and build commands
- Refactoring across large codebases
Why Claude Code Feels Different
- Agentic by default:
Claude plans, executes, and iterates — you don’t have to micromanage steps. - Terminal-first:
No IDE lock-in. It works anywhere your shell works. - Permission-aware:
File writes, command execution, and sensitive actions are gated (and configurable). - Model flexibility:
Heavy reasoning with Opus, fast iteration with Sonnet.
If you’re coming from Cursor: think of Claude Code as a specialized agent you can embed into your editor rather than an editor that happens to have AI.
Getting Started
Installation
You’ll need an Anthropic API key (sign up at claude.ai if you don’t have one).
Install Claude Code using pip (Python 3.8+):
pip install claude-codeAuthenticate:
claude loginStart a session:
claudeYou’ll see:
Claude>That’s it — you’re live.
IDE Integration (Optional)
If you use VS Code or Cursor:
- Install the Claude Code extension
- It launches Claude Code in a terminal pane
- You can drag files directly into prompts
This gives you the best of both worlds: editor ergonomics plus agentic power.
First Example: Generating a Simple Function
Let’s start small.
Prompt in the Claude terminal:
Write a Python function called is_palindrome that checks if a string is a palindrome. Ignore case and spaces. Save it to palindrome.py.Claude’s internal reasoning (snippet):
Thinking... First, clean the string: lowercase and remove spaces.
Then, compare with its reverse.Editing palindrome.py...Generated file (palindrome.py):
def is_palindrome(text):
# Clean the string: remove spaces and convert to lowercase
cleaned = ''.join(char.lower() for char in text if char.isalnum())
# Check if it reads the same forwards and backwards
return cleaned == cleaned[::-1]# Example usage
print(is_palindrome("A man a plan a canal Panama")) # TrueTerminal output:
File written: palindrome.pyRun it:
python palindrome.pyOutput:
TrueThis is the baseline experience: natural language in, real files out.
CLAUDE.md: Persistent Project Rules
If you’ve used Cursor’s .cursorrules, this will feel familiar.
Claude Code uses CLAUDE.md — a Markdown file that’s automatically loaded into every prompt. It acts as a persistent “constitution” for your project.
Creating a CLAUDE.md
Place it in your project root (or ~/.claude/CLAUDE.md for global rules).
Example for a Python project:
# Project Rules
- Use Python 3.10+.
- Follow PEP 8 style: snake_case variables, 4-space indentation.
- Always add docstrings to functions.
- For errors, use logging instead of print.
- IMPORTANT: Test all code with pytest before committing.# Key Commands
- To run tests: pytest
- Build command: python setup.py build# Examples
For API calls, use requests library like: import requests; response = requests.get(url)Now try:
Add a docstring and test to the is_palindrome function.Claude will comply with the rules automatically.
Advanced Tip
You can use hierarchical CLAUDE.md files in subdirectories (great for monorepos). Claude merges them, with higher-level rules taking precedence.
# CLAUDE.md — Project Rules & Working Agreement
This file defines how Claude should work inside this repository.
Follow these rules unless explicitly told otherwise.
---
## 1. Engineering Principles (Non-Negotiable)
- Prefer **clarity over cleverness**
- Optimize for **maintainability**, not premature performance
- If something looks over-engineered, **call it out**
- Always explain *why* a change is made, not just *what* changed
- Don’t introduce new abstractions unless there is clear reuse
---
## 2. Language & Runtime
- Primary language: **Python 3.10+**
- Package manager: **pip**
- Virtual env assumed active
- OS target: Linux / macOS
---
## 3. Code Style Rules
- Follow **PEP 8**
- Use `snake_case` for variables and functions
- Use `PascalCase` for classes
- Max line length: 88 chars
- Always add **docstrings** for public functions
- Prefer explicit code over magic
Example:
```python
def calculate_total(price: float, tax_rate: float) -> float:
"""
Calculate total price including tax.
Args:
price: Base price
tax_rate: Tax rate as decimal
Returns:
Total price including tax
"""
return price * (1 + tax_rate)Commands and Slash Commands
Claude Code supports both free-form prompts and structured commands.
Built-In Commands
- /clear — reset context
- /undo — revert last edit
- /context — show token usage
- /tools — manage permissions
Example:
Debug why this code fails: print(is_palindrome("123 321"))Claude responds:
Analyzing... The function ignores non-alnum, so "123 321" cleans to "123321" which is palindrome.No bug — it should return True.Custom Slash Commands (Power Feature)
You can define your own commands in .claude/commands/.
Example: test.md
Generate pytest unit tests for the component $ARGUMENTS.
Include edge cases and mocks.
Place in tests/test_$ARGUMENTS.py.Usage:
/test palindromeGenerated output (tests/test_palindrome.py):
import pytest
from palindrome import is_palindromedef test_basic_palindrome():
assert is_palindrome("radar") == Truedef test_with_spaces():
assert is_palindrome("A man a plan a canal Panama") == Truedef test_non_palindrome():
assert is_palindrome("hello") == FalseRun:
pytestAll tests pass.
This is extremely powerful for teams — you can version-control workflows, not just code.
Hooks: Automating After Edits
Hooks let you run shell commands automatically after Claude takes actions.
Configured in .claude/settings.json.
Example: auto-format after edits:
{
"hooks": {
"PostToolUse": {
"Edit": "prettier --write \"$CLAUDE_FILE_PATHS\""
}
}
}More advanced example (TypeScript type-checking):
{
"hooks": {
"PostToolUse": {
"Edit": "if [[ \"$CLAUDE_FILE_PATHS\" =~ \\.(ts|tsx)$ ]]; then npx tsc --noEmit \"$CLAUDE_FILE_PATHS\"; fi"
}
}
}Hooks turn Claude Code into a lightweight automation engine.
Advanced Workflows
Test-Driven Development (TDD)
Prompt:
Use TDD: Write failing tests for a fizzbuzz function, then implement to pass.Claude will:
- Write failing tests
- Implement the function
- Run tests
- Iterate until green
End result: working code, tested properly.
Visual Iteration (UI Work)
You can paste screenshots directly into prompts.
Example:
Match this UI mock [pasted image]: Implement in React.Claude iterates visually and code-wise until the implementation matches.
Multi-Agent Workflows
For larger tasks:
- Run multiple claude sessions
- Use Git worktrees:
git worktree add ../feature-branch- One agent implements, another reviews
Review output example:
Reviewed fizzbuzz.py: No bugs, but add edge case for n=0.This mirrors real team workflows surprisingly well.
Using Claude Code with Cursor
If you’re a Cursor user, this combo is excellent.
- Use Cursor for fast inline edits
- Use Claude Code for multi-file, agentic work
Cursor’s .cursorrules and Claude’s CLAUDE.md complement each other nicely.
Example prompt via Cursor’s Claude Code pane:
Refactor this selected code [drag file] to use hooks.Claude edits the file directly.
Tips, Best Practices, and Gotchas
- Be specific in prompts — edge cases matter
- Clear context often to save tokens
- Document tools and commands in CLAUDE.md
- Use:
claude --dangerously-skip-permissionsonly in safe environments
- For CI/headless use:
claude -p "Fix lint errors" --output-format json
Final Thoughts
Claude Code turns your terminal into a serious coding collaborator. It combines Cursor-style rules with deeper autonomy and fewer constraints.
Start small: generate functions, fix bugs, write tests.
Then scale up: TDD, hooks, multi-agent workflows.
The real unlock is CLAUDE.md — once you invest in that, Claude starts working the way you do.
If you’re building something interesting with Claude Code, share it. This tool rewards experimentation.
📢 Have questions or feedback? Drop a comment below or connect with me on Twitter/X@spysood!
Originally published on Medium.