Skip to main content

Claude Code

Claude Code is Anthropic's agentic coding CLI. HackAgent treats a locally installed Claude Code as a first-class attack target through the claude-code router provider.

HackAgent can launch the target in two ways:

  • directly through the Claude Code CLI, using claude -p
  • through Ollama, using ollama launch claude --

In both cases there is no HTTP endpoint or bridge to stand up. HackAgent shells out to a local binary and routes the exchange through the standard tracking pipeline like every other provider.

Prerequisites

  1. Install Claude Code and confirm it runs:

    claude --version
  2. Choose how to launch the target.

    For the default Claude Code CLI mode, make sure claude is on your PATH.

    For the Ollama-backed mode, install Ollama and confirm it runs:

    ollama --version
  3. Optional: configure an Anthropic key for the attacker/judge.

    The target authenticates through its own local CLI flow. HackAgent does not need an Anthropic key to launch the target itself.

    You only need ANTHROPIC_API_KEY if you route the attacker or judge models to the Anthropic API:

    export ANTHROPIC_API_KEY="sk-ant-..."

    If you want a fully local run, use an Ollama model instead.

Quick Start

The fastest way is the bundled hackagent claude preset, which pre-fills the target, model, attack strategy, and a starter set of red-team goals.

FlipAttack is the default because it does not require an external attacker model: each goal is transformed into a single obfuscated turn against the target, so a run is much faster than a search-based attack like TAP.

hackagent claude

Opens the interactive TUI with the Attacks tab pre-configured to target Claude Code. Edit the goals and hit execute.

Launch modes

Claude CLI mode

In the default mode, HackAgent launches Claude Code directly through the claude binary:

adapter_operational_config={
"name": "claude-opus-4-8",
"binary": "claude",
}

This shells out to the headless Claude Code CLI. The configured model name is passed to Claude Code.

The equivalent CLI invocation is:

hackagent claude --no-tui

Ollama launcher mode

In Ollama mode, HackAgent launches Claude Code through the ollama binary:

adapter_operational_config={
"name": "gemma4",
"binary": "ollama",
}

The equivalent CLI invocation is:

hackagent claude --no-tui --binary ollama --model gemma4

This is useful when you want to run Claude Code with a local Ollama-backed model instead of using the default Claude Code launcher.

Configuration

The target is configured through adapter_operational_config:

KeyDefaultDescription
namerequiredModel name passed to the selected launcher. With binary="claude", this is passed to Claude Code. With binary="ollama", this is passed to Ollama.
binaryclaudeLocal executable used to launch the target. Use claude for the Claude Code CLI or ollama for the Ollama launcher.
system_promptOverride the system prompt, when supported by the selected launcher.
append_system_promptExtend the system prompt, when supported by the selected launcher.
max_turnsCap the agentic loop iterations, when supported by the selected launcher.
cwdWorking directory to run the launcher in.
timeout300Per-turn timeout in seconds.
extra_args[]Additional raw launcher flags.
Prompt safety

The adversarial prompt is fed through stdin rather than argv, so text that begins with - is not misread as a CLI flag, and long prompts avoid argv length limits.

Tools & permissions

The target runs with Claude Code's default permission mode. In headless mode, permission-gated tools such as bash and file writes do not execute, so this exercises the model's safety behaviour without granting it actions on your machine. Pass extra CLI flags via extra_args if you intentionally want a different posture.

Troubleshooting

claude not found on PATH

ClaudeCodeConfigurationError: Claude Code executable 'claude' was not found on PATH.

The provider verifies the binary at construction, so a missing install fails fast.

Install Claude Code from code.claude.com, or pass the full path via --binary / adapter_operational_config["binary"].

ollama not found on PATH

If you run:

hackagent claude --no-tui --binary ollama --model gemma4

make sure Ollama is installed and available on your PATH:

ollama --version

You can also pass the full path to the Ollama executable via --binary or adapter_operational_config["binary"].

Attacker/judge errors about a missing API key

This means the attacker or judge is routed to the Anthropic API but ANTHROPIC_API_KEY is not set.

Either export the key:

export ANTHROPIC_API_KEY="sk-ant-..."

or use a local Ollama-backed configuration instead.

Remember: the target itself does not need an Anthropic key from HackAgent.

Further Reading