Skip to main content

Gptcmd-anthropic

Gptcmd-anthropic adds support for Anthropic's Claude models to Gptcmd.

Python 3.8.6 or later, Gptcmd 2.2.0 or later, and an Anthropic API key are required to use this package. Gptcmd-anthropic is available on PyPI, and can, for instance, be installed with pip install gptcmd-anthropic at a command line shell.

Configuration

To use Gptcmd-anthropic, you'll need to add a new account to your Gptcmd configuration or modify your default account. If no api_key is specified in your configuration, Gptcmd-anthropic uses the API key in the ANTHROPIC_API_KEY environment variable. An example configuration follows:

[accounts.claude]
provider = "anthropic"
api_key = "sk-ant-xxxxx"  # Replace with your API key
# Though not required, specifying a model in your configuration, similar to
# openai and azure accounts, will use that model by default
model = "claude-3-5-sonnet-latest"
# Optional: choose "auto" (default), "explicit", or "manual" prompt caching.
prompt_caching_strategy = "auto"
# Any additional options are passed directly to the Python Anthropic client's
# constructor for this account.

Usage

If you've configured multiple accounts, the account command in Gptcmd can be used to switch between them:

(gpt-4o) account claude
Switched to account 'claude'
(claude-3-5-sonnet-latest) account default
Switched to account 'default'
(gpt-4o)

Consult Gptcmd's readme for additional usage instructions.

Prompt caching

To save costs, Gptcmd-anthropic uses Anthropic's automatic cache breakpoint for the moving final turn of a conversation and uses any remaining explicit cache breakpoints on the system message (if present), large individual messages, and stable context portions. Anthropic cache lookups examine up to 20 earlier cacheable blocks per breakpoint, so explicit breakpoints balance large messages (based on number of blocks and content length) with block position rather than only using message size.

You may override this dynamic strategy on a per-message basis by setting the anthropic_cache_breakpoint metadata field:

  • If set to True, the message will always be cached.
  • If set to False, the message will never be cached.
  • If a span of consecutive messages of the same role contains conflicting breakpoint metadata (one message set to always cache, the next set to never cache), the entire span will be cached.

For instance:

(claude-opus-4-20250514) user Cache me!
'Cache me!' added as user
(claude-opus-4-20250514) meta anthropic_cache_breakpoint True
anthropic_cache_breakpoint set to True on 'Cache me!'

You may also override any field in the cache-control object passed to Anthropic with the cache_control API parameter. For example, this changes cache breakpoints (implicit and explicit) to a one-hour TTL:

(claude-opus-4-20250514) set cache_control {"ttl": "1h"}
cache_control set to {'ttl': '1h'}

The prompt_caching_strategy configuration option controls how breakpoints are selected:

  • auto is the default behaviour described above, which is recommended for most situations.
  • explicit disables the implicit request-level breakpoint and uses all available slots on explicit message or system breakpoints. This is useful for Anthropic-like providers that do not support the automatic breakpoint.
  • manual disables automatic breakpoint selection entirely. Only messages with an anthropic_cache_breakpoint metadata field set to True are set as cache breakpoints.

Extended thinking

You may enable extended thinking with a command like set thinking {"type": "enabled", "budget_tokens": 1024}. When extended thinking mode is enabled, a summary of the thinking process can be found at the anthropic_thinking_text metadata field on the generated assistant message.

(claude-opus-4-20250514) set thinking {"type": "enabled", "budget_tokens": 1024}
thinking set to {'type': 'enabled', 'budget_tokens': 1024}
(claude-opus-4-20250514) say The quick brown fox jumps over the lazy dog.
...
That's the famous pangram! It's a sentence that contains every letter of the English alphabet at least once. It's commonly used for:

- Testing typewriters and keyboards
- Displaying font samples
- Practicing typing
- Testing telecommunication equipment

It uses exactly 35 letters total and has been popular since at least the late 1800s. Is there something specific you'd like to know about this sentence, or were you perhaps testing something?
(claude-opus-4-20250514) meta anthropic_thinking_text
'The user has sent me the famous pangram "The quick brown fox jumps over the lazy dog." This sentence contains all 26 letters of the English alphabet at least once. They haven\'t asked me to do anything specific with it, so I should acknowledge it and perhaps share something interesting about it.'

Newer models support an "adaptive" thinking mode with graduated levels rather than a strict thinking budget. This feature requires version 0.77.0 or later of the Anthropic Python library:

(claude-opus-4-6) set thinking {"type": "adaptive"}
thinking set to {'type': 'adaptive'}
(claude-opus-4-6) set output_config {"effort": "max"}
output_config set to {'effort': 'max'}

If you use this feature frequently, you might find a macro like this to be helpful (add it to the [macros] section of your Gptcmd configuration, adding the section if it doesn't exist). Replace claude below with the name of your Gptcmd-anthropic account:

[macros]
ct = """
account claude
set thinking {{"type": "adaptive"}}
set output_config {{"effort": "{1?max}"}}
"""

Then, the ct command will enable thinking with the "max" reasoning level (by default, or specify the level to use as an argument to the macro).

Server-side tools

Tools provided by Anthropic, such as web search, may be used. However, tool responses (such as search citations) are not currently stored, displayed, or passed back to the model.

To search the web with Claude, you might wish to add a macro like this (the first argument specifies the maximum number of searches allowed, default 5) to the [macros] section of your Gptcmd configuration (if you also added the thinking macro, you might replace account claude in this macro to an invocation of that one, or add this set line to that macro):

[macros]
cw="""
account claude
set tools [{{"type": "web_search_20250305", "name": "web_search", "max_uses": {1?5}}}]
"""

Metadata

Release files for gptcmd-anthropic 2.9.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for gptcmd-anthropic 2.9.0
File Size Uploaded
gptcmd_anthropic-2.9.0.tar.gz 33.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for gptcmd-anthropic 2.9.0
File Interpreter ABI Platform
gptcmd_anthropic-2.9.0-py3-none-any.whl Python 3 none any Details

Total release size: 63.6 kB

Release files / gptcmd_anthropic-2.9.0.tar.gz

Download URL gptcmd_anthropic-2.9.0.tar.gz
Size 33.0 kB
Tags Source
SHA-256 checksum
How to use checksums
e6ead5e77d4344c4720c6c6e39a1a0aa4a189aff6fbe0a1270ac09f514fd6c7d
BLAKE2b-256 checksum
How to use checksums
bb8a74e928cd08eb57dcdeebb9770ecc2e2a8872f7c099b3a640b532541f51c1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.15

Release files / gptcmd_anthropic-2.9.0-py3-none-any.whl

Download URL gptcmd_anthropic-2.9.0-py3-none-any.whl
Size 30.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9ccdd515777e3391c342cabe7eba53bbe90cf56d60f0954d09afb8a9336ed2a9
BLAKE2b-256 checksum
How to use checksums
bdd6e9aae01fff0c00381221987d07c561557065e97706d492e4205a3242872a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.15

Release history Release notifications | RSS feed

This release

2.9.0 This release

2 release files

2.8.0

2 release files

2.7.0

2 release files

2.6.0

2 release files

2.5.0

2 release files

2.4.0

2 release files

2.3.0

2 release files

2.2.0

2 release files

2.1.0

2 release files

2.0.0

2 release files

1.2.1

2 release files

1.2.0

2 release files

1.1.0

2 release files

1.0.1

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page