# Chat Bot For Claude (WordPress Plugin)

![version](https://img.shields.io/badge/version-2.5.3-orange.svg)

![WordPress](https://img.shields.io/badge/WordPress-Compatible-blue.svg)

Integrate the Claude AI chat interface into your WordPress website using
a simple shortcode.

## Claude Models

When the Settings page is displayed, the Model list is read from the
Models API (<https://platform.claude.com/docs/en/api/models/list>),
newest to oldest, using the saved API Key. If there is no API Key, or
the API call fails, only the saved model is listed, with a note to enter
or check the API Key.

Currently (as of 2026) it looks like the Claude models are valid for at
least a year. If the chat bot stops working, visit the admin page to see
a refreshed list of models. You can look for deprecated models at:
[Model
Deprecations](https://platform.claude.com/docs/en/about-claude/model-deprecations).
Also you will want to look at the
[pricing](https://platform.claude.com/docs/en/about-claude/pricing) page
for the models.

## Features

-   Put the `[claude_chat]`{.verbatim} shortcode on any page or post and
    the chat box will be ready for user questions.

-   Choice of Claude model and max tokens.

-   A \"Prefix Prompt\" is sent as the system prompt on every request.
    This is where the \"personality,\" \"goals,\" and \"limits\" are
    specified. To save costs the system prompt is cached for an hour.

-   \"Follow Links\" checkbox. If checked, Claude is allowed to fetch
    external web links named in the prompt or in the visitor\'s
    question.

-   A list of pre-fetch URLs can be added to the system prompt (cached
    for one hour).

-   To keep costs down, there are limits to internal query times, and
    the number of external links followed. (See Code Customization,
    Constants.)

-   Per-IP rate limit of 10 requests per minute.

-   The \"log\" of questions and answers is stored outside the web root
    so only the admin interface can view the log. The \"View Log\" and
    \"Clear Logs\" buttons are on the settings page.

## Install Zip File

1.  Download the latest zip file from the \"release\" directory at:
    [WP-chat-bot-for-claude](https://moria.whyayh.com/rel/released/software/own/WP-chat-bot-for-claude/)
2.  With the WP plugin admin page, click on \"Add Plugin\", click on
    \"Upload Plugin\"
3.  Browse to the zip file and select it, open, click on \"Install Now\"
4.  Activate the plugin.
5.  Navigate to \'Settings\' \> \'Claude Chat\' to configure your API
    settings, and save.
6.  See the \"Admin Configuration\" section for more.

## Build/Install

Source: <https://github.com/TurtleEngr/WP-chat-bot-for-claude>

1.  Clone (or fork) this repo.
2.  Or click on the latest \"tag,\" select the \"Source code\" link to
    download the zip file, then unzip the file.
3.  Run \"make build\" to build and create the zip package.
4.  Install `dist/chat-bot-for-claude-VER.zip`{.verbatim} plugin, with
    the above **Install Zip File** directions.

## Usage

To display the chat interface on any page or post, use the shortcode:

``` example
[claude_chat]
```

On the page or post, you will want to add some directions around the
chat area. See
[example-settings.org](https://github.com/TurtleEngr/WP-chat-bot-for-claude/blob/develop/example-settings.org)
for an example page.

## Admin Configuration

Go to \'Settings\' \> \'Claude Chat\' in the WordPress admin panel to
configure the following options:

-   **API Key**: Enter your Claude API key.
-   **Model**: Select the Claude model you wish to use. (Do this after
    saving the API Key.)
-   **Max Tokens**: Set the maximum number of tokens for the response.
-   **Follow Links**: Checkbox. If checked URLs in the prompts will be
    followed.
-   **List of pre-fetch URLs**: One URL per line. Each URL will be read
    and added to the prompts.
-   **Prefix Prompt**: Define a prompt that is sent as the system prompt
    on every request.
-   **Save Settings** button: Save the current settings.
-   **View Log** button: open the chat log (`claude_log.org`{.verbatim})
    in a new browser tab.
-   **Clear Logs** button: remove the text in the chat log
    (`claude_log.org`{.verbatim}).

The chat log is in the `chat-bot-for-claude-log`{.verbatim} directory,
one level above the WordPress root (for example, above
`public_html`{.verbatim}), so it cannot be read from the web. Errors are
written to the PHP error log with `error_log()`{.verbatim}.

See
[example-settings.org](https://github.com/TurtleEngr/WP-chat-bot-for-claude/blob/develop/example-settings.org)
file for a example prompt.

## Code Customization

### Constants

These internal constants can be changed. The defaults values are shown
here. Also, some of these values will be shown in the Claude Chat
Settings admin form.

-   **cb4c~gFetchTimeOut~**: 5sec for each URL fetch

-   **cb4c~gResponseBudget~**: 20sec for the whole response

-   **cb4c~gRateLimit~**: 10 per min

-   **cb4c~gPreFetchTtl~**: 3600 sec (1 hour)

-   **cb4c~gMaxPreFetchUrls~**: 10

    -   Pre-fetch list limits. Content is cached in a transient for this
        many seconds, keyed by a hash of the URL list.

-   **cb4c~gMaxFetchBytes~**: 256 KB

-   **cb4c~gMaxFetchChars~**: 20 KB

    -   The byte cap protects PHP memory; the character cap protects the
        token budget --- a single large page can otherwise crowd out the
        Prefix Prompt and the user\'s actual question. \*/

-   **cb4c~gMaxToolRounds~**: 5

    -   Max number of `send/tool_result`{.verbatim} round trips. The
        response budget is the primary stop condition; this is a
        backstop so a model that keeps asking for cheap, fast fetches
        cannot loop indefinitely inside the budget.

-   **cb4c~gMaxResponseBytes~**: 4 MB

-   **cb4c~gMaxLogDumpChars~**: 4 KB

-   **cb4c~gMaxPrefixPrompt~**: 65 KB

-   **cb4c~gLogDir~**:
    `dirname(ABSPATH) . '/chat-bot-for-claude-log'`{.verbatim}

    -   The directory one level above the WordPress root. If WordPress
        is installed in a subdirectory of `public_html`{.verbatim},
        change this so the log is still outside the web root.

-   **cb4c~gLogFile~**: `claude_log.org`{.verbatim}

### Prefix Prompt

Registered in cb4c~fRegisterSettings~() with
`sanitize_textarea_field`{.verbatim} as its sanitize callback
(multi-line safe).

Added at the bottom of the settings form via
`cb4c_fSettingsInit().`{.verbatim} It uses
`cb4c_fTextareaFieldCallback()`{.verbatim} that renders a &lt;textarea\>
(6 rows × 60 cols) with a description explaining the caching behavior.
Leaving it blank disables the feature entirely.

prefix + `cache_control`{.verbatim} - `cb4c_fApiRequest()`{.verbatim}

When a prefix is saved, it is sent in the `system`{.verbatim} parameter,
separate from the user message. Pre-fetched page text is added as a
second system block.

The `cache_control`{.verbatim}: ephemeral setting on the last system
block tells Anthropic\'s API to cache the system prompt across repeated
requests --- reducing latency and token cost for long prompts. The
anthropic-beta: prompt-caching-2024-07-31 header is added automatically.

### js or css

-   **Styling**: Customize the chat interface by editing the
    `css/chat-bot-for-claude.css`{.verbatim} file.

-   **JavaScript**: Add or modify functionality by editing the
    `js/chat-bot-for-claude.js`{.verbatim} file.

js/chat-bot-for-claude.js --- The JavaScript only handles the chat UI:
capturing the user\'s input, sending it to admin-ajax.php via AJAX, and
displaying the response. None of that flow changed. The prefix prompt is
added (and stripped) entirely on the PHP/server side, invisibly to the
JS layer.

css/chat-bot-for-claude.css --- The new Prefix Prompt field in the admin
settings form uses standard WordPress admin classes (large-text, code,
description) that are already styled by WordPress core. No custom CSS is
needed.

## Requirements

-   **WordPress**: Version 6.0 or higher. (tested with 6.9.4, and 7.1)
-   **PHP**: Version 7.4 or higher. (tested with 8.3.30)
-   **Claude API Key**: A valid Claude API key is required.

### Screenshots

1.  Public View

    ![Claude User View](assets/screenshot-2.png)

2.  Settings

    ![claude admin view](assets/screenshot-1.png)

    -   API Key - Put your Claude API key here
    -   Model - Pick the model you want
    -   Max Tokens - Range: 1 to 8096
    -   Follow Links - checkbox
        -   When checked, Claude may call the `fetch_url`{.verbatim}
            tool to read URLs named in the prompt or the user question.
            Each fetch times out after 5s; the whole fetch loop stops
            after 20s and answers with what it has. Adds an API round
            trip per batch of fetches, so replies are slower and cost
            more tokens.
    -   List of pre-fetch URLs - textbox
        -   Optional. One URL per line, max 10. These are always fetched
            and added to the system prompt, whether or not Follow Links
            is checked. Content is cached for 60 minutes and truncated
            to 20,000 characters per page. Leave blank to disable.
    -   Prefix Prompt - textbox
        -   Optional. Sent as the system prompt on every request,
            keeping it separate from user input. Uses
            `cache_control`{.verbatim} to save costs. Leave blank to
            disable. Max 65,536 bytes.
    -   Save Settings - Save any changes.
    -   View Log - Open the chat log (`claude_log.org`{.verbatim}) in a
        new browser tab.
    -   Clear Logs - Remove the text in the chat log
        (`claude_log.org`{.verbatim}).
        -   The chat log is at:
            `WP-ROOT/../chat-bot-for-claude-log/claude_log.org`{.verbatim}
        -   Errors are written to the PHP error log.

## Support

For support, feature requests, or to report issues, please open an Issue
on the GitHub repository.

## License

This plugin is licensed under the
[GPLv2](https://www.gnu.org/licenses/gpl-2.0.html) license.

## Copyright

TurtleEngr

## Note

This code was initially derived from:
[VolkanSah/WP-Claude-Interface](https://github.com/VolkanSah/WP-Claude-Interface)
