Skip to main content
Article
ai-codingcliagenticterminalautonomousanthropicpythondeveloper-tools

Agentic Coding in Your Terminal with Claude Code

Use Anthropic's Claude Code CLI to autonomously modify your codebase. This guide shows how to install the agent, index a project, request a new feature, and approve the AI-generated changes directly from your terminal.

intermediate30 min5 steps
The play
  1. Install and Configure Claude Code
    Install the tool using pip. Claude Code requires an Anthropic API key to function. Export it as an environment variable so the CLI can authenticate its requests to the Claude model.
  2. Index Your Codebase
    Navigate to your project's root directory and run the index command. This step is crucial as it allows Claude Code to build a searchable map of your entire codebase, enabling it to understand file relationships and context.
  3. Make an Agentic Request
    Prompt Claude Code with a high-level task in natural language. The agent will analyze your request, search the indexed codebase, and formulate a plan to achieve the goal.
  4. Review and Approve Changes
    Claude Code will present its plan, which may include file edits, creating new files, or running shell commands. It will pause and ask for your approval at each step. Type 'y' to proceed or 'n' to stop, ensuring you have full control.
  5. Ask for Tests and Verification
    Once a feature is added, you can ask Claude Code to verify its own work. Request that it add a unit test for the new functionality and then run the project's entire test suite to check for regressions.
Starter code
#!/bin/bash
# This script sets up a simple Python project and uses Claude Code to add a new feature.

# 1. Ensure your API key is set
if [ -z "$ANTHROPIC_API_KEY" ]; then
  echo "Error: ANTHROPIC_API_KEY environment variable is not set."
  echo "Please set it with: export ANTHROPIC_API_KEY='your-key'"
  exit 1
fi

# 2. Set up a dummy project directory
PROJECT_NAME="claude_code_starter"
mkdir -p "$PROJECT_NAME"
cd "$PROJECT_NAME" || exit

# 3. Create a simple Flask application
cat <<EOF > app.py
from flask import Flask, jsonify

app = Flask(__name__)

@app.route('/')
def home():
    return jsonify({"message": "Welcome to the API"})

if __name__ == '__main__':
    app.run(port=5001, debug=True)
EOF

cat <<EOF > requirements.txt
flask
EOF

# 4. Install dependencies (including Claude Code if not already installed)
echo "Installing dependencies..."
pip install -q -r requirements.txt
pip install -q claude-code

# 5. Index the new project for Claude Code
echo "\nIndexing project..."
claude-code index

# 6. Give Claude Code a task
# It will formulate a plan and ask for your approval (y/n) in the terminal.
TASK="Add a new GET endpoint at /status that returns a JSON with 'status': 'ok'"
echo "\nGiving Claude Code the following task: $TASK"
echo "Please follow the interactive prompts in your terminal to approve changes."

claude-code "$TASK"

# After the task is complete, you can optionally ask it to run the app:
# claude-code "run the flask app"
Agentic Coding in Your Terminal with Claude Code — Action Pack