Skip to main content

synap-claude-agent

Synap memory integration for Anthropic's Claude Agent SDK (Python).

A TypeScript sibling package with the same API is published as @maximem/synap-claude-agent.

Install

pip install synap-claude-agent

Requires claude-agent-sdk>=0.1, maximem-synap>=0.7.1.

Two plug points

1. Hooks — automatic context injection

create_synap_hooks(...) installs hooks that fetch Synap context for each prompt and inject it via additionalContext, record the user's prompt and the agent's reply (the Stop hook's last_assistant_message), and report tool calls and results.

The first hook to fire opens the gRPC stream (sdk.instance.listen()) if you have not, and everything goes on it. SYNAP_AUTO_LISTEN=false turns that off and the two turns go over REST.

from claude_agent_sdk import query, ClaudeAgentOptions
from maximem_synap import MaximemSynapSDK
from synap_claude_agent import create_synap_hooks

sdk = MaximemSynapSDK(api_key="sk-...")

async for message in query(
    prompt="What did I tell you about my trial?",
    options=ClaudeAgentOptions(
        hooks=create_synap_hooks(sdk, user_id="alice", customer_id="acme"),
    ),
):
    print(message)

2. MCP tools — explicit read/write

create_synap_mcp_server(...) returns an in-process MCP server with two tools:

  • synap_search(query, max_results?) — semantic search over the user's memory
  • synap_remember(content, metadata?) — persist an explicit fact
options = ClaudeAgentOptions(
    mcp_servers={"synap": create_synap_mcp_server(sdk, user_id="alice")},
    allowed_tools=["mcp__synap__synap_search", "mcp__synap__synap_remember"],
)

3. Session store: resume from Synap's compaction

Claude Code owns its transcript, and a hook can add context to a prompt but not remove what the transcript holds. The one place the SDK lets you decide what a resumed session starts from is session_store:

from synap_claude_agent import create_synap_session_store

options = ClaudeAgentOptions(
    resume=session_id,
    session_store=create_synap_session_store(sdk),
    hooks=create_synap_hooks(sdk, user_id="alice"),
)

Once Synap has compacted the conversation, the resumed session starts from Synap's compaction and the turns after it instead of the stored transcript. Before that, or if Synap cannot answer, it resumes from the transcript unchanged. Inside a running session Claude Code still compacts its own transcript; the PreCompact hook gives its summarizer Synap's compaction to build on.

Use both together for the full experience: automatic context injection plus agent-initiated read/write.

Error policy

  • Hooks never raise — SDK failures log at ERROR and fall through to no-op (no context injected, no prompt recorded). Context-provider style.
  • synap_search tool returns a "no context available" message on SDK failure — the tool call succeeds so the agent loop keeps going.
  • synap_remember tool returns isError=true on ingestion failure — silent drops would hide ingestion outages, so we surface them to the agent explicitly.

Deeper scope ladders

If your account's scope ladder has more levels than customer and user, pass the address of the level to read and write at. It is sent only when set; without it every call is exactly what it was. The MCP tools close it over, so the model cannot choose a level.

path = {"customer": "acme", "team": "payments", "user": "dana"}  # from sdk.get_scope_ladder() / ScopeAddress
hooks = create_synap_hooks(sdk, "dana", "acme", scope_path=path)
server = create_synap_mcp_server(sdk, "dana", "acme", scope_path=path)

Metadata

Release files for maximem-synap-claude-agent 0.3.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 maximem-synap-claude-agent 0.3.0
File Size Uploaded Provenance Actions
maximem_synap_claude_agent-0.3.0.tar.gz 33.5 kB Without provenance Details for maximem_synap_claude_agent-0.3.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for maximem-synap-claude-agent 0.3.0
File Interpreter ABI Platform Actions
maximem_synap_claude_agent-0.3.0-py3-none-any.whl Python 3 none any Details for maximem_synap_claude_agent-0.3.0-py3-none-any.whl

Total release size: 53.5 kB

Release files / maximem_synap_claude_agent-0.3.0.tar.gz

Download URL maximem_synap_claude_agent-0.3.0.tar.gz
Size 33.5 kB
Tags Source
SHA-256 checksum
How to use checksums
171e9ffb639ead4ee4ebfbfd5e877ce121dbe2e52ca6f34c4ee02f9bac7cbd19
BLAKE2b-256 checksum
How to use checksums
56a3c310ada29767b8441c11b8888afb767dbffe9852a922e905fe4f539377f6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.4

Release files / maximem_synap_claude_agent-0.3.0-py3-none-any.whl

Download URL maximem_synap_claude_agent-0.3.0-py3-none-any.whl
Size 20.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2e026a6580fa21684218c9c9f7928bb45b8a02a7f8d6a3e41531f10c0e6b82d8
BLAKE2b-256 checksum
How to use checksums
fbfc0e0c16ca86a569136c0f4ebb2913611af84bd6f19bd6d4d83ce6eb2a8b2d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.4

Security for maximem-synap-claude-agent 0.3.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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