Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
- pi includes recalled lessons in search and can read a full lesson by ID, scoped to its project (#1605 by @YeChenglin8888).
- `npm run build` works under the Windows `cmd.exe` shell (#1362 by @mattamundson).
- `.env.example` names the Agent SDK route and documents `MAX_OBS_PER_SESSION` as a hard per-session cap (#1675, from #1503 by @Rex57).
- The Claude Code plugin passes its URL and secret settings to the MCP server as `CLAUDE_PLUGIN_OPTION_AGENTMEMORY_URL` and `CLAUDE_PLUGIN_OPTION_AGENTMEMORY_SECRET`, the names the plugin directory accepts. An empty URL setting no longer hides `AGENTMEMORY_URL` from the environment, and an empty secret setting still never sends `AGENTMEMORY_SECRET` from the environment.

### Changed

- The Claude Code plugin hooks run in exec form (`command` plus `args`), so the plugin path reaches Node as one argument with no shell quoting. The plugin and `connect claude-code --with-hooks` now need Claude Code 2.1.139 or later.
Comment thread
rohitg00 marked this conversation as resolved.
Resolved

### Known issues

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ agentmemory connect claude-code --with-hooks
```

This merges the same hook commands into `~/.claude/settings.json` with absolute paths resolved to the bundled `plugin/` directory of the currently installed `@agentmemory/agentmemory` package. Re-run the command after upgrading agentmemory to refresh the paths. User entries in the same file are preserved; only previous agentmemory entries are replaced. Using the `/plugin install` path remains the recommended approach.
For remote or protected deployments, launch Claude Code with `AGENTMEMORY_URL` and `AGENTMEMORY_SECRET` set. The plugin passes both values through to its bundled MCP server; when `AGENTMEMORY_URL` is empty, the MCP shim uses `http://localhost:3111`.
For a remote server, enter its `https://` URL and secret in the plugin settings that Claude Code asks for when you enable the plugin. The hooks and the bundled MCP server read both from there. With the URL setting empty, they use `AGENTMEMORY_URL` from your environment, then `http://localhost:3111`; with the secret setting empty, they send only the local server's own secret, and only to a loopback address.
Comment thread
rohitg00 marked this conversation as resolved.
Resolved

### Codex CLI (Codex plugin platform)

Expand Down
4 changes: 2 additions & 2 deletions plugin/.mcp.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"command": "node",
"args": ["${CLAUDE_PLUGIN_ROOT}/scripts/plugin-bridge.mjs"],
"env": {
"AGENTMEMORY_URL": "${user_config.agentmemory_url}",
"AGENTMEMORY_SECRET": "${user_config.agentmemory_secret}"
"CLAUDE_PLUGIN_OPTION_AGENTMEMORY_URL": "${user_config.agentmemory_url}",
"CLAUDE_PLUGIN_OPTION_AGENTMEMORY_SECRET": "${user_config.agentmemory_secret}"
}
}
}
Expand Down
36 changes: 24 additions & 12 deletions plugin/hooks/hooks.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"hooks": [
{
"type": "command",
"command": "node \"${CLAUDE_PLUGIN_ROOT}/scripts/session-start.mjs\""
"command": "node",
"args": ["${CLAUDE_PLUGIN_ROOT}/scripts/session-start.mjs"]
}
]
}
Expand All @@ -15,7 +16,8 @@
"hooks": [
{
"type": "command",
"command": "node \"${CLAUDE_PLUGIN_ROOT}/scripts/prompt-submit.mjs\""
"command": "node",
"args": ["${CLAUDE_PLUGIN_ROOT}/scripts/prompt-submit.mjs"]
}
]
}
Expand All @@ -26,7 +28,8 @@
"hooks": [
{
"type": "command",
"command": "node \"${CLAUDE_PLUGIN_ROOT}/scripts/pre-tool-use.mjs\""
"command": "node",
"args": ["${CLAUDE_PLUGIN_ROOT}/scripts/pre-tool-use.mjs"]
}
]
}
Expand All @@ -36,7 +39,8 @@
"hooks": [
{
"type": "command",
"command": "node \"${CLAUDE_PLUGIN_ROOT}/scripts/post-tool-use.mjs\""
"command": "node",
"args": ["${CLAUDE_PLUGIN_ROOT}/scripts/post-tool-use.mjs"]
}
]
}
Expand All @@ -46,7 +50,8 @@
"hooks": [
{
"type": "command",
"command": "node \"${CLAUDE_PLUGIN_ROOT}/scripts/post-tool-failure.mjs\""
"command": "node",
"args": ["${CLAUDE_PLUGIN_ROOT}/scripts/post-tool-failure.mjs"]
}
]
}
Expand All @@ -56,7 +61,8 @@
"hooks": [
{
"type": "command",
"command": "node \"${CLAUDE_PLUGIN_ROOT}/scripts/pre-compact.mjs\""
"command": "node",
"args": ["${CLAUDE_PLUGIN_ROOT}/scripts/pre-compact.mjs"]
}
]
}
Expand All @@ -66,7 +72,8 @@
"hooks": [
{
"type": "command",
"command": "node \"${CLAUDE_PLUGIN_ROOT}/scripts/subagent-start.mjs\""
"command": "node",
"args": ["${CLAUDE_PLUGIN_ROOT}/scripts/subagent-start.mjs"]
}
]
}
Expand All @@ -76,7 +83,8 @@
"hooks": [
{
"type": "command",
"command": "node \"${CLAUDE_PLUGIN_ROOT}/scripts/subagent-stop.mjs\""
"command": "node",
"args": ["${CLAUDE_PLUGIN_ROOT}/scripts/subagent-stop.mjs"]
}
]
}
Expand All @@ -86,7 +94,8 @@
"hooks": [
{
"type": "command",
"command": "node \"${CLAUDE_PLUGIN_ROOT}/scripts/notification.mjs\""
"command": "node",
"args": ["${CLAUDE_PLUGIN_ROOT}/scripts/notification.mjs"]
}
]
}
Expand All @@ -96,7 +105,8 @@
"hooks": [
{
"type": "command",
"command": "node \"${CLAUDE_PLUGIN_ROOT}/scripts/task-completed.mjs\""
"command": "node",
"args": ["${CLAUDE_PLUGIN_ROOT}/scripts/task-completed.mjs"]
}
]
}
Expand All @@ -106,7 +116,8 @@
"hooks": [
{
"type": "command",
"command": "node \"${CLAUDE_PLUGIN_ROOT}/scripts/stop.mjs\""
"command": "node",
"args": ["${CLAUDE_PLUGIN_ROOT}/scripts/stop.mjs"]
}
]
}
Expand All @@ -116,7 +127,8 @@
"hooks": [
{
"type": "command",
"command": "node \"${CLAUDE_PLUGIN_ROOT}/scripts/session-end.mjs\""
"command": "node",
"args": ["${CLAUDE_PLUGIN_ROOT}/scripts/session-end.mjs"]
}
]
}
Expand Down
22 changes: 15 additions & 7 deletions plugin/scripts/_capture.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,24 @@ function canonicalSecretPath() {
//#region src/hooks/_endpoint.ts
const OPTION_PREFIX = "CLAUDE_PLUGIN_OPTION_";
const DEFAULT_URL = "http://localhost:3111";
function filled(value) {
const trimmed = value?.trim();
if (!trimmed || trimmed.startsWith("${") && trimmed.endsWith("}")) return void 0;
return value;
}
function hookSetting(name, env = process.env) {
const optionKey = `${OPTION_PREFIX}${name}`;
const option = env[optionKey]?.trim();
const option = filled(env[optionKey])?.trim();
if (option) return option;
if (name === "AGENTMEMORY_SECRET" && optionKey in env) return void 0;
return env[name];
return filled(env[name]);
}
function resolveSettingSecret(url, env = process.env) {
const secretEnv = { ...env };
const explicit = hookSetting("AGENTMEMORY_SECRET", env);
if (explicit === void 0) delete secretEnv["AGENTMEMORY_SECRET"];
else secretEnv["AGENTMEMORY_SECRET"] = explicit;
return resolveClientSecret(url, secretEnv);
}
function secretTransportAllowed(url) {
try {
Expand All @@ -109,11 +121,7 @@ function secretTransportAllowed(url) {
}
function resolveHookEndpoint(env = process.env) {
const url = hookSetting("AGENTMEMORY_URL", env) || DEFAULT_URL;
const secretEnv = { ...env };
const explicit = hookSetting("AGENTMEMORY_SECRET", env);
if (explicit === void 0) delete secretEnv["AGENTMEMORY_SECRET"];
else secretEnv["AGENTMEMORY_SECRET"] = explicit;
const secret = resolveClientSecret(url, secretEnv);
const secret = resolveSettingSecret(url, env);
const blocked = !secretTransportAllowed(url);
return {
url,
Expand Down
29 changes: 24 additions & 5 deletions plugin/scripts/plugin-bridge.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,31 @@ function canonicalSecretPath() {
return join(homedir(), ".agentmemory", "secret");
}
//#endregion
//#region src/hooks/_endpoint.ts
const OPTION_PREFIX = "CLAUDE_PLUGIN_OPTION_";
function filled(value) {
const trimmed = value?.trim();
if (!trimmed || trimmed.startsWith("${") && trimmed.endsWith("}")) return void 0;
return value;
}
function hookSetting(name, env = process.env) {
const optionKey = `${OPTION_PREFIX}${name}`;
const option = filled(env[optionKey])?.trim();
if (option) return option;
if (name === "AGENTMEMORY_SECRET" && optionKey in env) return void 0;
return filled(env[name]);
}
function resolveSettingSecret(url, env = process.env) {
const secretEnv = { ...env };
const explicit = hookSetting("AGENTMEMORY_SECRET", env);
if (explicit === void 0) delete secretEnv["AGENTMEMORY_SECRET"];
else secretEnv["AGENTMEMORY_SECRET"] = explicit;
return resolveClientSecret(url, secretEnv);
}
//#endregion
//#region src/mcp/rest-proxy.ts
function resolveEnvOrEmpty(name) {
const raw = process.env[name];
if (!raw) return "";
if (raw.startsWith("${") && raw.endsWith("}")) return "";
return raw;
return hookSetting(name) ?? "";
}
//#endregion
//#region src/mcp/transport.ts
Expand Down Expand Up @@ -307,7 +326,7 @@ function createPluginBridge() {
"[::1]"
].includes(base.hostname) || /^127(?:\.\d{1,3}){3}$/.test(base.hostname);
function resolveSecret() {
const secret = resolveClientSecret(base.href);
const secret = resolveSettingSecret(base.href);
if (secret && base.protocol !== "https:" && !loopback) throw new Error("AGENTMEMORY_URL requires HTTPS when AGENTMEMORY_SECRET is set, except for loopback URLs.");
return secret;
}
Expand Down
22 changes: 15 additions & 7 deletions plugin/scripts/pre-compact.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,24 @@ function canonicalSecretPath() {
//#region src/hooks/_endpoint.ts
const OPTION_PREFIX = "CLAUDE_PLUGIN_OPTION_";
const DEFAULT_URL = "http://localhost:3111";
function filled(value) {
const trimmed = value?.trim();
if (!trimmed || trimmed.startsWith("${") && trimmed.endsWith("}")) return void 0;
return value;
}
function hookSetting(name, env = process.env) {
const optionKey = `${OPTION_PREFIX}${name}`;
const option = env[optionKey]?.trim();
const option = filled(env[optionKey])?.trim();
if (option) return option;
if (name === "AGENTMEMORY_SECRET" && optionKey in env) return void 0;
return env[name];
return filled(env[name]);
}
function resolveSettingSecret(url, env = process.env) {
const secretEnv = { ...env };
const explicit = hookSetting("AGENTMEMORY_SECRET", env);
if (explicit === void 0) delete secretEnv["AGENTMEMORY_SECRET"];
else secretEnv["AGENTMEMORY_SECRET"] = explicit;
return resolveClientSecret(url, secretEnv);
}
function secretTransportAllowed(url) {
try {
Expand All @@ -118,11 +130,7 @@ function secretTransportAllowed(url) {
}
function resolveHookEndpoint(env = process.env) {
const url = hookSetting("AGENTMEMORY_URL", env) || DEFAULT_URL;
const secretEnv = { ...env };
const explicit = hookSetting("AGENTMEMORY_SECRET", env);
if (explicit === void 0) delete secretEnv["AGENTMEMORY_SECRET"];
else secretEnv["AGENTMEMORY_SECRET"] = explicit;
const secret = resolveClientSecret(url, secretEnv);
const secret = resolveSettingSecret(url, env);
const blocked = !secretTransportAllowed(url);
return {
url,
Expand Down
22 changes: 15 additions & 7 deletions plugin/scripts/pre-tool-use.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,24 @@ function canonicalSecretPath() {
//#region src/hooks/_endpoint.ts
const OPTION_PREFIX = "CLAUDE_PLUGIN_OPTION_";
const DEFAULT_URL = "http://localhost:3111";
function filled(value) {
const trimmed = value?.trim();
if (!trimmed || trimmed.startsWith("${") && trimmed.endsWith("}")) return void 0;
return value;
}
function hookSetting(name, env = process.env) {
const optionKey = `${OPTION_PREFIX}${name}`;
const option = env[optionKey]?.trim();
const option = filled(env[optionKey])?.trim();
if (option) return option;
if (name === "AGENTMEMORY_SECRET" && optionKey in env) return void 0;
return env[name];
return filled(env[name]);
}
function resolveSettingSecret(url, env = process.env) {
const secretEnv = { ...env };
const explicit = hookSetting("AGENTMEMORY_SECRET", env);
if (explicit === void 0) delete secretEnv["AGENTMEMORY_SECRET"];
else secretEnv["AGENTMEMORY_SECRET"] = explicit;
return resolveClientSecret(url, secretEnv);
}
function secretTransportAllowed(url) {
try {
Expand All @@ -108,11 +120,7 @@ function secretTransportAllowed(url) {
}
function resolveHookEndpoint(env = process.env) {
const url = hookSetting("AGENTMEMORY_URL", env) || DEFAULT_URL;
const secretEnv = { ...env };
const explicit = hookSetting("AGENTMEMORY_SECRET", env);
if (explicit === void 0) delete secretEnv["AGENTMEMORY_SECRET"];
else secretEnv["AGENTMEMORY_SECRET"] = explicit;
const secret = resolveClientSecret(url, secretEnv);
const secret = resolveSettingSecret(url, env);
const blocked = !secretTransportAllowed(url);
return {
url,
Expand Down
22 changes: 15 additions & 7 deletions plugin/scripts/session-start.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,24 @@ function canonicalSecretPath() {
//#region src/hooks/_endpoint.ts
const OPTION_PREFIX = "CLAUDE_PLUGIN_OPTION_";
const DEFAULT_URL = "http://localhost:3111";
function filled(value) {
const trimmed = value?.trim();
if (!trimmed || trimmed.startsWith("${") && trimmed.endsWith("}")) return void 0;
return value;
}
function hookSetting(name, env = process.env) {
const optionKey = `${OPTION_PREFIX}${name}`;
const option = env[optionKey]?.trim();
const option = filled(env[optionKey])?.trim();
if (option) return option;
if (name === "AGENTMEMORY_SECRET" && optionKey in env) return void 0;
return env[name];
return filled(env[name]);
}
function resolveSettingSecret(url, env = process.env) {
const secretEnv = { ...env };
const explicit = hookSetting("AGENTMEMORY_SECRET", env);
if (explicit === void 0) delete secretEnv["AGENTMEMORY_SECRET"];
else secretEnv["AGENTMEMORY_SECRET"] = explicit;
return resolveClientSecret(url, secretEnv);
}
function secretTransportAllowed(url) {
try {
Expand All @@ -109,11 +121,7 @@ function secretTransportAllowed(url) {
}
function resolveHookEndpoint(env = process.env) {
const url = hookSetting("AGENTMEMORY_URL", env) || DEFAULT_URL;
const secretEnv = { ...env };
const explicit = hookSetting("AGENTMEMORY_SECRET", env);
if (explicit === void 0) delete secretEnv["AGENTMEMORY_SECRET"];
else secretEnv["AGENTMEMORY_SECRET"] = explicit;
const secret = resolveClientSecret(url, secretEnv);
const secret = resolveSettingSecret(url, env);
const blocked = !secretTransportAllowed(url);
return {
url,
Expand Down
12 changes: 8 additions & 4 deletions scripts/release-gate/run.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ class Gate {
for (const entry of entries) {
if (entry.matcher && toolName && !new RegExp(`^(?:${entry.matcher})$`).test(toolName)) continue;
if (entry.matcher && !toolName) continue;
for (const h of entry.hooks ?? []) if (h.type === "command") commands.push(h.command);
for (const h of entry.hooks ?? []) if (h.type === "command") commands.push(h);
}
return commands;
}
Expand Down Expand Up @@ -791,11 +791,15 @@ class Instance {
const commands = gate.hookCommands(event, payload.tool_name);
assert(commands.length > 0, `no bundled ${event} hook matches ${payload.tool_name ?? "this event"}`);
const results = [];
for (const command of commands) {
const r = await run("sh", ["-c", command], {
const pluginRoot = join(gate.pkgDir, "plugin");
for (const handler of commands) {
const [file, argv] = handler.args
? [handler.command, handler.args.map((arg) => arg.replaceAll("${CLAUDE_PLUGIN_ROOT}", pluginRoot))]
: ["sh", ["-c", handler.command]];
const r = await run(file, argv, {
env: {
...gate.baseEnv(this.home),
CLAUDE_PLUGIN_ROOT: join(gate.pkgDir, "plugin"),
CLAUDE_PLUGIN_ROOT: pluginRoot,
CLAUDE_PROJECT_DIR: this.project,
AGENTMEMORY_URL: `http://127.0.0.1:${this.port}`,
AGENTMEMORY_DATA_DIR: this.dataDir,
Expand Down
Loading
Loading