AI News / 2026-06-26

Claude Code CLI Tutorial: From Setup to Agentic Workflows

XycAi
Claude Code CLI Tutorial: From Setup to Agentic Workflows

Why Claude Code Over the Other AI CLIs

Three serious AI coding CLIs are competing for terminal real estate right now: OpenAI's Codex, Google's Gemini CLI, and Anthropic's Claude Code. They each sit on top of different model families — Codex on GPT-4.5/5, Gemini CLI on Gemini 2.5, Claude Code on Claude Sonnet 4.6 and Opus 4.8 — but the model underneath is only part of the story.

The bigger difference is philosophy. Claude Code is built like an agentic editor, not a chat wrapper. It reads your entire project directory, writes files, runs shell commands, and calls external tools, all from the terminal, no GUI involved. If you live in the terminal, this fits how you already work.

There's also a practical argument around context length. Sonnet 4.6 runs a 200K-token context window, which covers most mid-sized codebases — think 50,000 lines or less — without manual pruning. Anyone who used earlier versions and got into the habit of typing /clear every few minutes will notice the difference immediately.


Installation and Initial Configuration

Requirements: Node.js 18+ is the straightforward path. Install Claude Code globally via npm:

npm install -g @anthropic-ai/claude-code

Verify the installation:

claude --version
# claude-code 1.x.x

API key setup: Claude Code reads from the ANTHROPIC_API_KEY environment variable. Write it into your shell config so it's always available:

echo 'export ANTHROPIC_API_KEY="sk-ant-..."' >> ~/.zshrc
source ~/.zshrc

If you're routing through a third-party compatible layer like XycAi, add the base URL as well:

export ANTHROPIC_BASE_URL="https://api.xyc.ai/v1"

Default model: Use claude config to set your baseline. For everyday coding, Sonnet 4.6 hits the right balance of speed and quality. Switch to Opus 4.8 when the task demands it:

claude config set model claude-sonnet-4-6

Three Ways to Use Claude Code

Complexity scales across three distinct usage patterns.

1. One-Shot Mode (Non-interactive)

claude -p "explain the time complexity of this function" < utils.py

Good for scripts, automated code review in CI pipelines, or anywhere you need a structured answer without starting a conversation.

2. Interactive Mode (Your Daily Driver)

Run claude from your project root. It scans the directory structure and loads context automatically. The commands you'll use most:

Command What it does
/add <file> Manually load a specific file into context
/clear Reset the conversation, keep your config
/model opus Temporarily switch to Opus 4.8
/cost Check token usage and cost for the current session

3. Agentic Mode

This is where Claude Code pulls ahead. Add --dangerously-accept-edits and Claude Code writes files directly without prompting for confirmation at each step. Use this on projects with solid git coverage:

claude --dangerously-accept-edits

A concrete example: filling in missing JSDoc comments across an Express.js codebase.

Scan all .js files under src/, find every exported function without a JSDoc comment,
and add them. Use src/auth/login.js as the formatting reference.

Claude Code outlines its plan first, then executes after you confirm. In practice, 40+ functions get documented in about two minutes. Doing that by hand takes an hour or two. The difference is real.


Custom Tools and Project-Level Context

This is where Claude Code separates itself from a standard chat completion endpoint.

CLAUDE.md for Project Conventions

Create a CLAUDE.md file at your project root. Its contents are injected automatically at the start of every session:

# Project conventions
- Package manager: pnpm — do not use npm install
- Test framework: Vitest, test files go in __tests__/
- Commit format: Conventional Commits — feat/fix/chore/docs only
- Database: PostgreSQL 16, ORM is Drizzle — no raw SQL

With this in place, Claude Code respects these rules throughout the project. It won't suddenly reach for npm or swap Drizzle for Prisma.

MCP Tool Integration

MCP (Model Context Protocol) lets Claude Code call external functions you define. Config lives at ~/.claude/mcp.json:

{
  "tools": [
    {
      "name": "run_tests",
      "description": "Run the project test suite",
      "command": "pnpm test --reporter=json",
      "parse": "json"
    },
    {
      "name": "query_db",
      "description": "Execute a read-only SQL query and return results",
      "command": "psql $DATABASE_URL -c '{query}' --csv"
    }
  ]
}

Once that's wired up, you can say "run the tests, find what's failing, and fix it." Claude Code calls run_tests, parses the JSON output, locates the failing cases, edits the code, and runs tests again to verify. That feedback loop makes bug-hunting noticeably faster on larger projects.


Real-World Tips Worth Keeping

Cost management: Opus 4.8 runs about five times the price of Sonnet 4.6. There's no reason to use the flagship model for routine coding tasks. A sustainable split is Sonnet 4.6 for roughly 80% of work, Opus 4.8 reserved for architecture decisions and genuinely complex algorithmic problems. Use /cost to track usage session by session — staying in the $20–$40/month range is very achievable with this approach.

Protect yourself before agentic runs: Before enabling --dangerously-accept-edits, make sure your working tree is clean (git status should show nothing uncommitted), and create a new branch for any significant task. Claude Code won't commit anything on your behalf, but it will overwrite files. A branch is your only safety net here.

Be deliberate with context: 200K tokens sounds like unlimited room, but in a large monorepo it still matters. Use /add to load exactly the files that are relevant rather than letting Claude Code scan everything. It's faster, cheaper, and the responses are more targeted.

CI integration: Dropping Claude Code into a GitHub Actions workflow for automated PR review is one of the highest-value, lowest-effort integrations available. Non-interactive mode with the -p flag outputs structured JSON you can post directly as a PR comment. It adds two or three minutes to your pipeline and catches things that slip through manual review.


If you want to run Claude Code — or benchmark it against Codex and Gemini CLI — without juggling separate API accounts, I'd point you to XycAi. It's a single OpenAI-compatible endpoint that covers 200+ models, with official Claude and GPT models available from 14% of list price. Setup for Claude Code, Codex, or Gemini CLI is one environment variable change, which is hard to argue with.

One API for 200+ global AI models

GPT · Claude · Gemini official models from 14% of list price. Licensed LLM filing, CN2 direct connect at ~5ms, compliant global invoicing.

Try XycAi →