Skip to content

Commit 1a5f484

Browse files
tadasantclaude
andauthored
feat: refactor Claude Code Agent directory architecture (v0.0.3) (#166)
## Summary This PR refactors the Claude Code Agent MCP Server's directory architecture to properly separate working directories from state storage, addressing a fundamental design issue. ### Key Changes - **BREAKING:** `init_agent` tool now requires `working_directory` parameter (absolute path) - **BREAKING:** `init_agent` tool now accepts optional `agent_id` parameter for state directory naming - **BREAKING:** Removed transcript resource (state resource now contains transcript path reference) - Implemented directory separation: working directory vs state directory - Fixed transcript path to point to Claude Code's native transcript files - Enhanced path transformation logic to match Claude Code's naming convention ### Architecture Improvements **Before:** `/tmp/claude-agents` was used for both agent operations and state storage (confusing) **After:** Clean separation: - **Working Directory**: Where Claude Code agent operates (user-specified via `working_directory`) - **State Directory**: Where state.json is stored (`${CLAUDE_AGENT_BASE_DIR}/${agent_id}/`) - **Transcript Path**: Points to Claude Code's native files (`~/.claude/projects/{project-dir}/{session-id}.jsonl`) ### Testing - ✅ All manual tests pass (3/3) - ✅ Verified working directory separation with both mock and real Claude Code CLI - ✅ Validated native Claude Code transcript path detection - ✅ Confirmed required parameter validation works correctly ### Breaking Changes Users upgrading from previous versions must update their `init_agent` calls to include the `working_directory` parameter. **Before:** ```json { "system_prompt": "You are a helpful assistant" } ``` **After:** ```json { "system_prompt": "You are a helpful assistant", "working_directory": "/path/to/project" } ``` 🤖 Generated with [Claude Code](https://claude.ai/code) --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent e681fa4 commit 1a5f484

File tree

16 files changed

+241
-213
lines changed

16 files changed

+241
-213
lines changed

experimental/claude-code-agent/CHANGELOG.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,33 @@ All notable changes to the Claude Code Agent MCP Server will be documented in th
44

55
## [Unreleased]
66

7+
## [0.0.3] - 2025-10-10
8+
9+
**BREAKING CHANGES:**
10+
11+
- **BREAKING:** `init_agent` tool now requires `working_directory` parameter (absolute path)
12+
- **BREAKING:** `init_agent` tool now accepts optional `agent_id` parameter for state directory naming
13+
- **BREAKING:** Removed transcript resource (state resource now contains transcript path reference)
14+
15+
**Improvements:**
16+
17+
- Implemented directory separation: working directory (where agent operates) vs state directory (where state is stored)
18+
- Fixed transcript path to point to Claude Code's native transcript files (`~/.claude/projects/{project-dir}/{session-id}.jsonl`)
19+
- Enhanced path transformation logic to match Claude Code's naming convention for project directories
20+
- Updated all tests to use new parameter structure and verify directory separation
21+
- State storage now uses `CLAUDE_AGENT_BASE_DIR` exclusively with agent_id-based folder naming
22+
- Improved security validation to allow both working and state directories
23+
24+
**Technical Details:**
25+
26+
This release addresses the fundamental directory structure issue where `/tmp/claude-agents` was being used for both agent operations and state storage. The new architecture cleanly separates:
27+
28+
- **Working Directory**: Where the Claude Code agent operates (user-specified via `working_directory` parameter)
29+
- **State Directory**: Where state.json and other metadata are stored (`${CLAUDE_AGENT_BASE_DIR}/${agent_id}/`)
30+
- **Transcript Path**: Points to Claude Code's native transcript files for seamless integration
31+
32+
Users upgrading from previous versions must update their `init_agent` calls to include the `working_directory` parameter.
33+
734
## [0.0.2] - 2025-10-08
835

936
**CRITICAL FIX:**

experimental/claude-code-agent/MANUAL_TESTING.md

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ Manual tests for the Claude Code Agent MCP Server verify the integration with th
66

77
## Latest Test Results
88

9-
**Commit:** af8c3e4
10-
**Date:** 2025-10-08
9+
**Commit:** a35b31b
10+
**Date:** 2025-10-10
1111
**Overall:** 100% passing (3/3 test suites)
12-
**Note:** Manual tests from commit 390aabe still valid - this commit only adds prepare-publish.js for npm packaging
12+
**Note:** Verified new working_directory parameter and directory separation functionality
1313

1414
### Test Suite Results
1515

@@ -110,20 +110,20 @@ Tests fail if:
110110

111111
## Manual Test Results
112112

113-
**Last tested**: 2025-10-08
114-
**Commit**: af8c3e4
113+
**Last tested**: 2025-10-10
114+
**Commit**: a35b31b
115115
**Result**: SUCCESS (100% pass rate)
116-
**Note**: Tests from 390aabe still valid - af8c3e4 only adds packaging scripts
116+
**Note**: Verified new required working_directory parameter and directory separation functionality
117117

118118
### Test Execution Details
119119

120120
- [x] Mock workflow test - PASSED
121121
- [x] Tool workflow test (real Claude Code CLI) - PASSED
122122
- [x] Error handling test - PASSED
123123
- [x] All 7 tools verified and working
124-
- [x] Resources properly managed
125-
- [x] State persistence fixed - single client instance maintained
126-
- [x] Session continuation working with --resume flag
124+
- [x] Required working_directory parameter validated
125+
- [x] Directory separation working (state vs working dirs)
126+
- [x] Native Claude Code transcript path detection verified
127127
- [x] Real Claude Code CLI integration verified
128128

129129
### Test Statistics
@@ -134,9 +134,10 @@ Tests fail if:
134134

135135
### Notes
136136

137-
- Mock tests validate all tool functionality
137+
- Mock tests validate all tool functionality including new required parameters
138138
- Real Claude CLI integration fully tested and verified
139-
- Tool workflow test now passes with real Claude Code CLI
140-
- Session continuation properly uses --resume with session ID
141-
- Non-interactive mode working correctly with -p flag
139+
- Working directory separation correctly implemented (state vs working dirs)
140+
- Native Claude Code transcript path detection working (/Users/admin/.claude/projects/)
141+
- Required working_directory parameter validation working properly
142+
- Directory separation architecture verified with both mock and real implementations
142143
- All tests run without skips - complete coverage achieved

experimental/claude-code-agent/local/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "claude-code-agent-mcp-server",
3-
"version": "0.0.2",
3+
"version": "0.0.3",
44
"description": "Local implementation of claude-code-agent MCP server",
55
"mcpName": "claude-code-agent",
66
"main": "build/index.js",

experimental/claude-code-agent/local/prepare-publish.js

Lines changed: 0 additions & 64 deletions
This file was deleted.

experimental/claude-code-agent/package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

experimental/claude-code-agent/shared/src/claude-code-client/claude-code-client.integration-mock.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { AgentState } from '../types.js';
33

44
export class MockClaudeCodeClient implements IClaudeCodeClient {
55
private mockState: AgentState | null = null;
6+
private mockStateDirectory: string | null = null;
67

78
private mockTranscript: Array<{
89
role: string;
@@ -20,16 +21,20 @@ export class MockClaudeCodeClient implements IClaudeCodeClient {
2021
};
2122
}
2223

23-
async initAgent(systemPrompt: string) {
24+
async initAgent(systemPrompt: string, workingDirectory: string, agentId?: string) {
25+
const stateId = agentId || Math.random().toString(36).substr(2, 9);
26+
const sessionId = 'mock-session-' + Math.random().toString(36).substr(2, 9);
27+
this.mockStateDirectory = `/tmp/mock-state/${stateId}`;
2428
this.mockState = {
25-
sessionId: 'mock-session-' + Math.random().toString(36).substr(2, 9),
29+
sessionId,
2630
status: 'idle',
2731
systemPrompt,
2832
installedServers: [],
2933
createdAt: new Date().toISOString(),
3034
lastActiveAt: new Date().toISOString(),
31-
workingDirectory: '/tmp/mock-agent',
35+
workingDirectory: workingDirectory,
3236
claudeProjectPath: '/tmp/mock-claude-projects/integration-test',
37+
transcriptPath: `/tmp/mock-claude-projects/integration-test/${sessionId}.jsonl`,
3338
};
3439

3540
// Clear transcript on new agent init
@@ -38,7 +43,7 @@ export class MockClaudeCodeClient implements IClaudeCodeClient {
3843
return {
3944
sessionId: this.mockState.sessionId,
4045
status: 'idle' as const,
41-
stateUri: 'file:///tmp/mock-agent/state.json',
46+
stateUri: `file://${this.mockStateDirectory}/state.json`,
4247
};
4348
}
4449

@@ -171,4 +176,8 @@ export class MockClaudeCodeClient implements IClaudeCodeClient {
171176
async getAgentState() {
172177
return this.mockState;
173178
}
179+
180+
async getStateDirectory() {
181+
return this.mockStateDirectory;
182+
}
174183
}

0 commit comments

Comments
 (0)