# How to Integrate TencentDB Agent Memory with Claude Code Agent

> Integrate TencentDB Agent Memory with Claude Code Agent easily. Set ANTHROPIC_BASE_URL and ANTHROPIC_AUTH_TOKEN to enable automatic skill and memory injection via the proxy.

- Repository: [Tencent Cloud/TencentDB-Agent-Memory](https://github.com/TencentCloud/TencentDB-Agent-Memory)
- Tags: how-to-guide
- Published: 2026-08-30

---

**Set `ANTHROPIC_BASE_URL` to your Memory Proxy endpoint and `ANTHROPIC_AUTH_TOKEN` to your Memory user-key, then launch Claude Code to enable automatic skill and memory injection via the proxy layer.**

TencentDB Agent Memory provides an Anthropic-compatible proxy layer that enriches Claude Code conversations with **long-term memory**, **skills**, and **knowledge assets**. By routing your Claude Code client through this proxy, the system automatically authenticates your session, initializes memory context through an interactive form flow, and injects relevant system prompts before forwarding requests to the upstream Anthropic API.

## How the Proxy Integration Works

When configured correctly, the **Memory Proxy** component acts as a transparent middleware between your Claude Code client and Anthropic's API. In [`MemoryProxy/src/anthropicHandler.ts`](https://github.com/TencentCloud/TencentDB-Agent-Memory/blob/main/MemoryProxy/src/anthropicHandler.ts), the handler intercepts requests to the `/claude-code/` path prefix and performs three critical operations:

1. **Authentication**: Validates the `ANTHROPIC_AUTH_TOKEN` (Memory user-key) to identify your workspace
2. **Session Initialization**: Triggers a form-based selection flow (team → agent → task) via [`MemoryProxy/src/session/claude-code/init.ts`](https://github.com/TencentCloud/TencentDB-Agent-Memory/blob/main/MemoryProxy/src/session/claude-code/init.ts) to determine which memory assets to load
3. **Prompt Injection**: Augments the `body.system` field of the Anthropic payload with relevant skills and memories before proxying the request

The proxy expects requests at `POST /claude-code/<spaceId>/v1/messages` and uses the `x-claude-code-session-id` header to maintain conversation continuity across multiple turns.

## Prerequisites

Before configuring Claude Code, ensure you have:

- The **Memory Proxy** running locally or on an accessible server (default port `8096`)
- A valid **Memory user-key** (API key) from your Memory Hub dashboard
- Claude Code CLI installed on your system

Start the proxy using Docker or the provided [`start-combined.sh`](https://github.com/TencentCloud/TencentDB-Agent-Memory/blob/main/start-combined.sh) script:

```bash
docker run -p 8096:8096 tencentdb/memory-proxy:latest

```

## Configuration Methods

You can configure Claude Code to use the Memory Proxy through environment variables or a persistent settings file.

### Environment Variables (Quick Setup)

Export the required variables before launching Claude Code:

```bash
export ANTHROPIC_BASE_URL=http://127.0.0.1:8096/claude-code/default
export ANTHROPIC_AUTH_TOKEN="sk-mem-xxxxxxxxxxxxxxxx"
export ANTHROPIC_MODEL="claude-opus-4.7"

claude --model $ANTHROPIC_MODEL

```

The `ANTHROPIC_BASE_URL` must include the `/claude-code/` path prefix to trigger the Claude Code-specific handling logic in the proxy. The `default` segment represents your space ID, which you can replace with a specific workspace identifier if needed.

### Persistent Settings File (Recommended)

For permanent configuration, create or edit `~/.claude/settings.json`:

```json
{
  "env": {
    "ANTHROPIC_AUTH_TOKEN": "sk-mem-xxxxxxxxxxxxxxxx",
    "ANTHROPIC_BASE_URL": "http://127.0.0.1:8096/claude-code/default",
    "ANTHROPIC_MODEL": "claude-sonnet-4-20250514"
  }
}

```

Claude Code reads these values automatically on startup, eliminating the need to export variables for each session.

## Session Initialization Flow

When you send your first message through the proxy, Claude Code triggers the **session-init form** system implemented in [`MemoryProxy/src/session/claude-code/init.ts`](https://github.com/TencentCloud/TencentDB-Agent-Memory/blob/main/MemoryProxy/src/session/claude-code/init.ts). This process:

- Presents a **team selection** menu using Claude Code's `AskUserQuestion` tool
- Displays **agent selection** options filtered by the chosen team
- Shows **task selection** to determine the specific memory context

The proxy supports **2–4 options** per form step. When more options exist, the system automatically adds a **"更多→"** (More) pagination entry to navigate additional choices. Your selection determines which skill libraries and memory contexts get injected into the system prompt for that conversation.

## Importing Existing Memory Assets

If you have pre-existing memories from other agents or previous sessions, import them using the asset-import tool before starting your Claude Code session:

```bash
tsx agents/asset-import.ts \
  --source claude-code \
  --agent-id myClaudeAgent \
  --team-id myTeam \
  -y

```

The [`agents/asset-import.ts`](https://github.com/TencentCloud/TencentDB-Agent-Memory/blob/main/agents/asset-import.ts) script supports bulk importing context files, conversation history, and knowledge bases into the TencentDB Agent Memory system, making them available for the session initialization flow described above.

## Verifying the Integration

To confirm successful integration, check for these indicators:

- **Request URL**: Verify traffic is routing to `POST /claude-code/<spaceId>/v1/messages` on your proxy port (default 8096)
- **Session Headers**: Responses should include the `x-claude-code-session-id` header for conversation tracking
- **System Prompt Injection**: Inspect the request payload to confirm `body.system` contains injected sections labeled `## Skills` and `## Memory` with relevant context from your selected agent and task

Refer to [`MemoryProxy/v3-api-memoryproxy-doc.md`](https://github.com/TencentCloud/TencentDB-Agent-Memory/blob/main/MemoryProxy/v3-api-memoryproxy-doc.md) for detailed API mapping and request/response transformation specifications.

## Summary

- **TencentDB Agent Memory** integrates with Claude Code via a proxy layer that intercepts Anthropic API calls at the `/claude-code/` endpoint
- **Configuration** requires setting `ANTHROPIC_BASE_URL` to the proxy address and `ANTHROPIC_AUTH_TOKEN` to your Memory user-key
- **Session context** is established through an interactive form flow (team → agent → task) managed by [`MemoryProxy/src/session/claude-code/init.ts`](https://github.com/TencentCloud/TencentDB-Agent-Memory/blob/main/MemoryProxy/src/session/claude-code/init.ts)
- **Memory injection** happens automatically in [`MemoryProxy/src/anthropicHandler.ts`](https://github.com/TencentCloud/TencentDB-Agent-Memory/blob/main/MemoryProxy/src/anthropicHandler.ts) by augmenting the system prompt before forwarding to Anthropic
- **Existing assets** can be imported using [`agents/asset-import.ts`](https://github.com/TencentCloud/TencentDB-Agent-Memory/blob/main/agents/asset-import.ts) with the `--source claude-code` flag

## Frequently Asked Questions

### How does the Memory Proxy authenticate Claude Code requests?

The proxy validates the `ANTHROPIC_AUTH_TOKEN` header (treated as a Memory user-key) to identify your workspace and permissions. This token maps to your Memory Hub API key and determines which teams, agents, and memory assets you can access during the session initialization process.

### What is the purpose of the `x-claude-code-session-id` header?

This header maintains conversation continuity across multiple API calls. The proxy uses it to persist the selected team, agent, and task context between messages, ensuring that skills and memories remain consistent throughout your Claude Code session without requiring repeated form submissions.

### Can I import existing conversation history into Claude Code's memory?

Yes. Use the asset-import CLI tool located at [`agents/asset-import.ts`](https://github.com/TencentCloud/TencentDB-Agent-Memory/blob/main/agents/asset-import.ts) with the `--source claude-code` parameter. Specify your target `--agent-id` and `--team-id` to migrate existing memories, documentation, or conversation histories into the TencentDB Agent Memory system for use with Claude Code.

### Which Anthropic models are supported through the proxy?

The proxy supports all Anthropic models available through the standard API, including `claude-opus-4.7`, `claude-sonnet-4-20250514`, and earlier versions. Set your preferred model via the `ANTHROPIC_MODEL` environment variable or in your [`settings.json`](https://github.com/TencentCloud/TencentDB-Agent-Memory/blob/main/settings.json) file; the proxy passes this parameter through to the upstream API unchanged.