Code Story

Code Story: Code AI CLI

Claude Code, Gemini CLI, sessions, multi-step tasks, hooks

3.  Code AI CLI

A Code AI CLI runs in your terminal alongside your code. It can read your files, write changes, run commands, and navigate your repository — all without leaving the shell. This chapter covers Claude Code and Gemini CLI as terminal-based coding partners.
Why the CLI over the browser?
  1. The CLI has direct access to your filesystem — no pasting required.
  2. It can run shell commands and read their output, closing the loop between code and behavior.
  3. Multi-step tasks (read file, analyze, edit, run tests) happen in a single session without context loss.
  4. Hooks let you automate recurring actions: run linters before each edit, show a summary when the session ends.

3.1  Starting a Session

Run claude in the root of your project. On the first run in a new repository, use /init to generate a CLAUDE.md file describing the project structure. Subsequent sessions load that file automatically, giving the model context without you re-explaining it each time.

3.2  Making Changes

Describe what you want in plain language. The CLI reads relevant files, proposes a diff, and waits for your approval. You see every change before it lands. Use /diff to review pending edits at any point in the session.

3.3  Multi-Step Tasks

Compound tasks work well because the CLI maintains context across steps. Example session sequence:
  1. Read src/main.rs and summarize the data flow.
  2. Identify the three functions with the highest cyclomatic complexity.
  3. Refactor the most complex function into two smaller ones.
  4. Run cargo test and fix any failures.
Each step uses output from the previous one. The context window is the limit — for very large refactors, split into smaller tasks.

3.4  Hooks and Automation

Claude Code hooks run shell commands automatically on events such as tool calls, session start, and session end. Configure them in .claude/settings.json under the hooks key. Useful hooks:
  • Run cargo clippy after every file edit
  • Display a summary of changed files when the session closes
  • Block writes outside an allowed directory whitelist

3.5  References

ResourceDescription
Claude Code Anthropic’s CLI tool — install, docs, and keyboard reference.
Gemini CLI Google’s terminal AI tool, open source.
CodeBites: Code AI Track page with recorded CLI sessions and technique notes.