PRACTICE · 2 hours
How to wire Claude Code into your real terminal, editor, and CI workflow using genuine primitives that hold up in production
Think of Claude Code's integration surfaces like three different channels you tune to depending on what you're doing. Each channel reaches the same underlying model, but from a different vantage point with different affordances.
Terminal is the universal channel. It works anywhere there's a shell — SSH sessions, CI scripts, Docker containers, tmux splits. You pipe data in, Claude Code reasons about it, and you get output. Nothing fancy, but it composes with every Unix tool you already know.
Editor environment is the contextual channel. When Claude Code runs inside VS Code's integrated terminal, it detects the environment and gains awareness of what file you have open, what diagnostics exist, what diff you're reviewing. The same claude binary gains richer context without any extra configuration beyond one environment variable.
Hooks is the automation channel. Hooks are executable scripts that run at specific points in Claude Code's lifecycle — before a tool executes, after it completes, when a session ends. They let you add safety gates, logging, and notifications without modifying any workflow manually.
The layering insight: You're not choosing one integration surface. Terminal handles composability and automation. Editor integration handles active development sessions. Hooks handle policies you want enforced across every Claude Code session on every project.
This module covers the real primitives for each surface and then shows how to wire them together — the pattern I use across my agentic SDLC harness and day-to-day development.
The package is @anthropic-ai/claude-code — note the anthropic-ai scope, not anthropic:
Common mistake: Searching npm for @anthropic/claude-code (missing the -ai suffix) finds nothing. The correct scope is @anthropic-ai.
The most composable primitive is pipe mode with -p. You feed Claude Code a stream, it reasons about it, and output goes wherever you redirect it:
The -p flag keeps Claude Code non-interactive: read from stdin, print to stdout, exit. This is what makes it safe inside scripts and CI pipelines — it won't pause waiting for keyboard input.
Beyond pipe mode, Claude Code accepts natural-language prompts directly. The key patterns I reach for daily:
When you launch Claude Code from inside VS Code's integrated terminal, it detects the VSCODE_ environment variables and can surface proposed changes as diff views. One variable unlocks this:
With CLAUDE_EDITOR=code, Claude Code opens proposed edits directly in VS Code's diff viewer instead of printing them to the terminal.
Before wiring these together, reason through:
claude "question" and echo "data" | claude -p "question"?-p flag matter for CI pipelines specifically?CLAUDE_EDITOR is not set, how will Claude Code show proposed file changes?If you're confident on all three, the next section will click immediately.
Pipe mode composes naturally with shell scripts. Here's a script I use to triage an AI-generated PR before I review it manually:
Pattern: Gather context with shell primitives, feed it to Claude Code in one pipe, capture the exit code. This is the complete CI integration pattern.
Hooks are shell scripts or programs registered in ~/.claude/settings.yaml. They attach to six lifecycle events:
| Hook | When It Fires |
|---|---|
pre-prompt | Before your prompt is processed |
pre-tool-use | Before any tool executes |
post-tool-use | After a tool completes |
notification | When Claude Code needs user input |
stop | When the session ends |
pre-compact | Before context compaction |
Hooks receive event data as JSON on stdin. Exit 0 to allow; exit non-zero to block (for pre-tool-use).
This is the pre-tool-use hook I use in my SDLC harness to block runaway destructive commands:
Register and test it:
The stop hook fires when a session ends. I use it to write a JSON summary of every Claude Code session to a daily log — useful for auditing what the SDLC harness ran while I was away from the desk:
Why JSONL? Append-only JSON Lines means concurrent sessions don't corrupt the log. Stream the day's entries with cat ~/.claude/logs/$(date +%Y-%m-%d).jsonl | jq .
The pre-tool-use hook runs synchronously — every tool call blocks while the hook runs. A slow hook (say, one that calls an external API to validate a command) makes every Claude Code session sluggish.
Think through this trade-off before moving on: If you want both a safety gate and observability calls to a monitoring dashboard, how would you split the work between pre-tool-use and post-tool-use? What latency guarantee does that give you, and what observability gap does it create?
There's no single right answer, but reasoning through it before you build is how you avoid discovering the wrong answer in production.
1. You run: git diff --staged | claude -p 'write a commit message'. What does Claude Code do?
Correct Answer: B
The -p flag enables non-interactive pipe mode: Claude Code reads stdin, processes it with the model, writes output to stdout, and exits. No keyboard input is required, making it safe for scripts and CI pipelines.
2. A pre-tool-use hook exits with code 2. What does Claude Code do?
Correct Answer: C
Any non-zero exit code from a pre-tool-use hook blocks the tool from executing. Exit code 1, 2, or any other non-zero value all have the same effect: block.
3. You want Claude Code to open proposed file edits in VS Code's diff viewer. Which setup is correct?
Correct Answer: B
Setting CLAUDE_EDITOR=code in your shell environment tells Claude Code to open diffs in VS Code. Add it to your shell profile so it persists across sessions.
4. You installed @anthropic/claude-code via npm and it failed. What went wrong?
Correct Answer: B
The correct npm package is @anthropic-ai/claude-code (with -ai in the scope). @anthropic/claude-code does not exist on npm and will fail with 'package not found'.
5. Which hook fires when you want to append a summary to an audit log after Claude Code finishes a session?
Correct Answer: D
The stop hook fires when the Claude Code session ends, making it the right place for session-level summaries, cleanup tasks, and audit log writes.
6. A pre-tool-use hook calls an external API to validate every command. What is the most likely production consequence?
Correct Answer: B
Hooks run synchronously. A pre-tool-use hook that calls a slow external API delays every tool call for the duration of that API call. Keep pre-tool-use hooks fast — validate locally or use a sub-millisecond cache.
7. You want to add project context to every Claude Code prompt automatically. Which hook is correct?
Correct Answer: B
The pre-prompt hook fires before each prompt is processed, giving you a place to inject context like project README sections, current git branch, or team conventions that Claude Code should always have.