Skip to content

robcost/claude-features-cli

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Claude API Features CLI

An interactive command-line tool that demonstrates every major feature of the Claude API from Anthropic. Select a feature from the menu, enter a prompt, and see a real API response — formatted and readable right in your terminal.

Built for developers who want to learn the Claude API by running the calls themselves and reading clean, focused source code.

Companion project: claude-features-app covers the same 16 features as an interactive Next.js web app.


Why This Exists

The Claude API has a lot of surface area — streaming, extended thinking, tool use, code execution, citations, memory, and more. Reading the docs is a good start, but there's nothing like running the actual API calls and seeing what comes back.

Every feature in this CLI is:

  • Runnable — pick it from the menu, hit Enter, see a real response
  • Self-contained — each feature lives in one file under src/demos/, easy to copy into your own project
  • Readable — no framework magic, no abstractions, just straightforward TypeScript calling the SDK directly

Features

Model Capabilities

Feature What It Does Key API Concept
Text Generation Send a prompt, get a streamed response messages.stream() with content_block_delta events
Vision Describe a local image file Base64 image source in a content block
Extended Thinking See Claude's reasoning before the answer thinking: { type: "enabled", budget_tokens: N }
Structured Outputs Get JSON that matches your schema exactly Forced tool use via tool_choice: { type: "tool" }
Citations Responses grounded in source documents citations: { enabled: true } on document blocks
PDF Support Upload and analyze a local PDF file Base64 PDF document source
Effort Control Trade speed and cost for response quality output_config: { effort: "low" | "medium" | "high" }
Search Results (RAG) Feed search results, get cited answers search_result content blocks

Tools

Feature What It Does Key API Concept
Tool Use Claude calls your custom functions Client-side tools with agentic loop
Web Search Claude searches the web in real-time web_search_20250305 server tool
Web Fetch Claude fetches and reads a URL web_fetch_20250910 server tool
Code Execution Claude writes and runs code in a sandbox code_execution_20250825 server tool
Memory Claude stores and recalls info across turns memory_20250818 client tool with agentic loop

Context Management

Feature What It Does Key API Concept
Token Counting Count tokens before sending a request messages.countTokens() — no tokens consumed
Prompt Caching Cache system prompts to save cost cache_control: { type: "ephemeral" } on content blocks
Batch Processing Send multiple requests at 50% cost savings messages.batches.create(), retrieve(), results()

Getting Started

Prerequisites

Installation

git clone https://github.com/robcost/claude-features-cli.git
cd claude-features-cli
npm install

Running

export ANTHROPIC_API_KEY=sk-ant-...
npm run dev

If ANTHROPIC_API_KEY is not set, the CLI will prompt you to enter it at startup. The key is used directly in memory and never written to disk.

You'll see a menu like this:

╔═══════════════════════════════════════╗
║   Claude API Features Explorer CLI   ║
╚═══════════════════════════════════════╝

  16 hands-on demos of every Claude API feature

? Select a feature to demo:
  ─── Model Capabilities ───
  ❯ Text Generation  Basic Messages API with streaming
    Vision  Analyze images — provide a local file path
    Extended Thinking  See Claude's step-by-step reasoning
    ...
  ─── Tools ───
    Tool Use  Client-side tools with agentic loop
    ...

Pick a feature, choose a model, enter your prompt. That's it.

Models

Each demo lets you choose which model to use:

Model Best For
Sonnet 4.6 (default) Fast, capable, cost-effective
Haiku 4.5 Fastest responses, lowest cost
Opus 4.6 Most capable, best for complex reasoning

How It Works

Architecture

Unlike the companion web app — which routes requests through a Next.js server — this CLI calls the Anthropic SDK directly from the same Node.js process. There is no HTTP layer between you and the API.

Terminal Input
      │
      ▼
  src/index.ts          ← menu loop, model selection, API key
      │
      ▼
  src/demos/xyz.ts      ← one file per feature, handles prompts + output
      │
      ▼
  @anthropic-ai/sdk     ← direct SDK call, no intermediary
      │
      ▼
  Anthropic API
      │
      ▼
  chalk + renderMarkdown ← formatted terminal output

Streaming

Streaming demos (Text Generation, Vision, Extended Thinking, etc.) collect tokens internally while showing a live character count, then render the complete response as formatted markdown when the stream ends. This gives you clean, readable output while still making a real streaming API call under the hood.

Extended Thinking is the exception — the thinking content streams in real-time in dim gray so you can watch it reason, and only the final answer is buffered and formatted.

Markdown Rendering

All text responses are rendered with a built-in chalk-based markdown renderer (src/utils/display.ts → renderMarkdown). No external markdown library is used. It handles:

  • Headings (H1–H3)
  • Bold, italic, bold-italic
  • Inline code and fenced code blocks
  • Bullet and numbered lists
  • Blockquotes
  • Horizontal rules
  • Links (label shown, URL stripped)
  • Strikethrough

Structured Outputs

The Structured Outputs demo uses forced tool use — the correct, documented mechanism for schema-constrained JSON from Claude. A tool is defined with your JSON schema as its input_schema, and tool_choice: { type: "tool", name: "..." } forces Claude to always call it. Claude's tool inputs are always validated against the schema before the API returns.

Memory

The Memory demo keeps a Record<string, string> store in-process. It persists across multiple runs of the Memory feature within the same CLI session, so you can run it twice to see state accumulate.


Project Structure

claude-features-cli/
├── src/
│   ├── index.ts               # Entry point: API key resolution + main menu loop
│   ├── types.ts               # Feature list and model definitions
│   ├── client.ts              # Anthropic SDK client factory
│   ├── utils/
│   │   └── display.ts         # chalk helpers + renderMarkdown()
│   └── demos/
│       ├── text-generation.ts
│       ├── vision.ts
│       ├── extended-thinking.ts
│       ├── structured-outputs.ts
│       ├── citations.ts
│       ├── pdf-support.ts
│       ├── effort-control.ts
│       ├── search-results.ts
│       ├── tool-use.ts
│       ├── web-search.ts
│       ├── web-fetch.ts
│       ├── code-execution.ts
│       ├── memory.ts
│       ├── token-counting.ts
│       ├── prompt-caching.ts
│       └── batch-processing.ts
├── .env.example
├── package.json
└── tsconfig.json

Each demo file exports a single run(client, model) function. It handles its own input prompts, API call, and output — fully self-contained and easy to copy into another project.


Learning Path

If you're new to the Claude API, here's a suggested order:

  1. Text Generation — Start here. This is messages.stream() with an async iterator. Every other feature builds on this pattern.
  2. Token Counting — Count tokens before sending. Understand cost before you spend it.
  3. Structured Outputs — See how forced tool use constrains Claude to return valid JSON matching your schema.
  4. Extended Thinking — Watch Claude reason step-by-step. Set the budget_tokens high and ask a hard question.
  5. Tool Use — The most important advanced feature. See how the agentic loop works: Claude requests a tool call, you execute it, you return the result, Claude continues.
  6. Prompt Caching — Run it twice. Compare the cache_creation_input_tokens on the first call with the cache_read_input_tokens on the second.
  7. Code Execution — See a server-side tool in action. Claude writes Python, runs it in a sandbox, and streams the output.
  8. Batch Processing — Create a batch, watch it poll, read the results. Understand when async processing makes sense.
  9. Everything else — Citations, Vision, Memory, Web Search, Web Fetch, PDF Support, Effort Control, Search Results — explore in any order.

For each feature, read the source file first — it's short, focused, and has a comment at the top explaining the key API concept.


API Key Security

  • Your API key is read from the ANTHROPIC_API_KEY environment variable, or entered at the prompt
  • It is stored only in process memory for the duration of the session
  • It is never written to disk, logged, or sent anywhere except directly to the Anthropic API
  • For production applications, use server-side key management and never expose keys to clients

Tech Stack

Package Purpose
@anthropic-ai/sdk Official Anthropic SDK
@inquirer/prompts Interactive CLI menus and inputs
chalk Terminal colors and markdown rendering
ora Spinners for async operations
tsx Run TypeScript directly (dev)

License

MIT — see LICENSE

Acknowledgements

Built with Claude Code using the Anthropic API.

About

Interactive CLI demonstrating every Claude API feature — text generation, vision, thinking, tool use, code execution, RAG, memory, and more. 16 hands-on demos.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors