Tutorial · 2026-05-25 · 12 min read
Claude Sonnet 4.6 Agent Tutorial: Build a Real PTY Agent
A practical guide to configuring Claude Sonnet 4.6, setting approval gates, and running it inside a native terminal.
Claude Sonnet 4.6 is Anthropic's fastest reasoning model, but a raw API key gives you nothing but text. This tutorial walks through configuring Sonnet 4.6 as a real agent — with a PTY terminal, per-hunk diffs, and approval rules — using the AZMX AI desktop app. No account, no telemetry, just a config file and a model picker.
Claude Sonnet 4.6 is a strong model for interactive agent work. It reasons quickly, supports tool use natively, and stays on track across long conversations. But hooking it up to a real terminal — with file editing, command execution, and safety checks — takes more than a curl call.
This tutorial shows exactly how to configure Sonnet 4.6 as an agent in AZMX AI, set approval gates for dangerous commands, and iterate on code. You will need an Anthropic API key with access to Sonnet 4.6 and a copy of AZMX AI running on macOS, Windows, or Linux.
Prerequisites
- AZMX AI installed (7 MB native app, no Docker, no runtime dependencies)
- Anthropic API key with Claude Sonnet 4.6 enabled. Set it in Settings > Providers > Anthropic, or via
AZMX_ANTHROPIC_KEYenvironment variable - Basic terminal familiarity — you will be approving or denying shell commands
Step 1: Add Claude Sonnet 4.6 to AZMX
Open AZMX AI, go to the model picker (top-left), and click "Add model". Select provider Anthropic, model ID claude-sonnet-4-6. Give it a label like "Sonnet 46 Agent". The app auto-discovers the model's context window (200K tokens) and tool support.
If you prefer config files, edit ~/.azmx/models.json:
{
"provider": "anthropic",
"model": "claude-sonnet-4-6",
"label": "Sonnet 46 Agent",
"context": 200000,
"tools": true
}AZMX respects your AZMX_ANTHROPIC_KEY environment variable. To use a different key per model, set it in the UI under Settings > Providers > Anthropic.
Step 2: Configure the Agent Profile
Every agent in AZMX has a profile — a JSON block that defines personality, guardrails, and tool permissions. Profiles live in ~/.azmx/profiles/. Create sonnet-agent.json:
{
"model": "claude-sonnet-4-6",
"system_prompt": "You are a senior software engineer. You use the terminal for everything. Before writing code, read the project's AZMX.md. Never access .env, .ssh, or credential files. Never run commands that modify system-wide packages without asking.",
"tools": {
"terminal": true,
"edit": true,
"mcp": ["fs", "shell"]
},
"approval": {
"auto_approve": ["ls", "cat", "grep", "find", "npm test", "git status", "git diff"],
"always_deny": ["rm -rf /", "chmod -R 777 /", "curl.*pipe.*bash"],
"prompt_prefix": "Sonnet wants to run:"
}
}The approval block is critical. Commands in auto_approve run silently. Dangerous patterns in always_deny get rejected outright. Everything else shows a dialog requiring explicit approval per invocation.
Step 3: Start a Session and Approve a Command
Select the Sonnet 4.6 agent profile from the dropdown (top-left). Type your first prompt:
List the files in this project and show the 10 most recent git commits.
AZMX spawns a real PTY terminal via xterm.js and portable-pty. You will see ls -la and git log --oneline -10 flash with a small approval toolbar. Click the green checkmark (or press Enter) to approve. Sonnet sees the output and continues.
This is where Sonnet 4.6 shines: its fast reasoning means the tool-call loop feels near-instant. The PTY shows output as it streams, including ANSI color codes — exactly like a real terminal emulator.
Step 4: Edit Code with Per-Hunk Diffs
Ask Sonnet to make a change:
Add a missing null check to the getUser function in src/auth.js
Sonnet 4.6 plans the edit, then AZMX presents a unified diff with each hunk highlighted. You can approve a single hunk, all hunks, or reject the whole edit. This granularity is unique among agent UIs — Cursor and Windsurf offer per-file staging, but not per-hunk.
Click "Approve all" to accept. AZMX writes the file and records the change in the conversation history. You can revert any edit by clicking the undo button next to the assistant message.
Step 5: Use Project Memory (AZMX.md)
AZMX reads a file called AZMX.md from the project root. This is your project's persistent memory — style conventions, architecture decisions, API keys (never write secrets here), and known bugs. Sonnet reads it at the start of every session.
Example AZMX.md:
# Project: feed-parser ## Style - Use ES modules, not CommonJS - Prefer async/await over .then() - All public functions have JSDoc ## Architecture - /src: source - /tests: Vitest ## Known issues - Memory leak in XML parser when feeds >10 MB - Null author crashes card component
Sonnet 4.6 will adhere to these rules automatically. Update AZMX.md as the project evolves. This replaces the need for elaborate system prompts per session.
Step 6: Deny-List Enforcement
By default, AZMX refuses access to .env, .ssh, credential files, and commands that expose secrets. This is hardcoded — you cannot override it in the profile. Even if Sonnet 4.6 asks to read .env, AZMX intercepts the tool call and returns a rejection message: "Access denied: file is in deny list."
This is a safety feature, not a limit. If you need access to those files for legitimate development, use the --no-deny flag on launch, but you should understand the risk.
Comparing Sonnet 4.6 with Other Models in AZMX
AZMX supports 14 providers, including OpenAI, Google, Groq, xAI, DeepSeek, and local models via Ollama or LM Studio. Sonnet 4.6 is ideal for agent work because of its speed and tool-use accuracy. It outperforms GPT-4.1 on multi-step shell tasks and is marginally slower but more reliable than DeepSeek R2 on edits.
If you want full offline, Ollama with qwen2.5-coder:7b works but loses reasoning quality. For heavy refactors, Sonnet 4.6 with per-hunk approval is the sweet spot.
Alternatives and Honest Tradeoffs
Other agent tools exist. Claude Code is Anthropic's own terminal agent — it is good, but requires Node.js, sends telemetry by default, and lacks a GUI diff view. Cline is a VS Code extension with similar features, but uses a browser-based terminal emulation. Aider is purely terminal-based and excellent for pair programming, but you must manage git commits manually. Continue is a chat overlay with limited agent capabilities. Cursor and Windsurf are IDEs with integrated agents — they are powerful but heavy and proprietary. GitHub Copilot is chat-only; Tabnine and Codeium focus on completions. Sourcegraph Cody is a chat agent with some terminal commands. Tabby is an on-prem completion server — not an agent.
AZMX occupies a specific niche: a native, minimal, offline-capable agent with real terminal, per-hunk diffs, and approval gates. It does not aim to replace your editor — it lives alongside it.
Next Steps
Once Sonnet 4.6 is running, try MCP tools. AZMX supports MCP over stdio and HTTP. Add a filesystem MCP server for structured file reads, or a shell MCP server for constrained command execution. Profile settings let you enable or disable MCP tools per agent.
Explore the AZMX docs for sub-agent orchestration — you can have Sonnet 4.6 delegate subtasks to smaller models like DeepSeek Coder V3 or Llama 4 Scout locally.
Download AZMX from azmx.ai/download. No account, no signup, no telemetry. The only network call it makes on its own is the signed updater check.
One window. The whole loop.
Native. ~7 MB. BYOK or fully offline. No account. No telemetry.