메모리 도구를 사용하면 Claude가 메모리 파일 디렉토리를 통해 대화 간에 정보를 저장하고 검색할 수 있습니다. Claude는 세션 간에 지속되는 파일을 생성, 읽기, 업데이트 및 삭제할 수 있어, 모든 것을 컨텍스트 윈도우에 유지하지 않고도 시간이 지남에 따라 지식을 구축할 수 있습니다.
메모리 도구는 클라이언트 측에서 작동합니다—데이터가 저장되는 위치와 방법을 자체 인프라를 통해 제어할 수 있습니다.
메모리 도구는 현재 베타 버전입니다. 이를 활성화하려면 API 요청에 베타 헤더 context-management-2025-06-27을 사용하세요.
이 기능에 대한 피드백을 공유하려면 피드백 양식을 통해 연락해 주세요.
활성화되면 Claude는 작업을 시작하기 전에 자동으로 메모리 디렉토리를 확인합니다. Claude는 /memories 디렉토리에서 파일을 생성, 읽기, 업데이트 및 삭제하여 작업 중 학습한 내용을 저장한 다음, 향후 대화에서 해당 메모리를 참조하여 유사한 작업을 더 효과적으로 처리하거나 중단된 곳에서 다시 시작할 수 있습니다.
이것은 클라이언트 측 도구이므로 Claude가 메모리 작업을 수행하기 위해 도구 호출을 하면 애플리케이션이 해당 작업을 로컬에서 실행합니다. 이를 통해 메모리가 저장되는 위치와 방법을 완전히 제어할 수 있습니다. 보안을 위해 모든 메모리 작업을 /memories 디렉토리로 제한해야 합니다.
Claude에게 작업을 도와달라고 요청하면 Claude는 먼저 자동으로 메모리 디렉토리를 확인합니다. 일반적인 상호작용은 다음과 같습니다:
1. 사용자 요청:
"이 고객 서비스 티켓에 응답하는 것을 도와주세요."2. Claude가 메모리 디렉토리를 확인합니다:
"고객 서비스 티켓에 응답하는 것을 도와드리겠습니다. 이전 컨텍스트가 있는지 메모리를 확인하겠습니다."Claude가 메모리 도구를 호출합니다:
{
"type": "tool_use",
"id": "toolu_01C4D5E6F7G8H9I0J1K2L3M4",
"name": "memory",
"input": {
"command": "view",
"path": "/memories"
}
}3. 애플리케이션이 디렉토리 내용을 반환합니다:
{
"type": "tool_result",
"tool_use_id": "toolu_01C4D5E6F7G8H9I0J1K2L3M4",
"content": "Here're the files and directories up to 2 levels deep in /memories, excluding hidden items and node_modules:\n4.0K\t/memories\n1.5K\t/memories/customer_service_guidelines.xml\n2.0K\t/memories/refund_policies.xml"
}4. Claude가 관련 파일을 읽습니다:
{
"type": "tool_use",
"id": "toolu_01D5E6F7G8H9I0J1K2L3M4N5",
"name": "memory",
"input": {
"command": "view",
"path": "/memories/customer_service_guidelines.xml"
}
}5. 애플리케이션이 파일 내용을 반환합니다:
{
"type": "tool_result",
"tool_use_id": "toolu_01D5E6F7G8H9I0J1K2L3M4N5",
"content": "Here's the content of /memories/customer_service_guidelines.xml with line numbers:\n 1\t<guidelines>\n 2\t<addressing_customers>\n 3\t- Always address customers by their first name\n 4\t- Use empathetic language\n..."
}6. Claude가 메모리를 사용하여 도움을 줍니다:
"고객 서비스 가이드라인을 기반으로 응답을 작성하는 것을 도와드릴 수 있습니다. 티켓 세부 정보를 공유해 주세요..."메모리 도구는 다음에서 사용할 수 있습니다:
claude-opus-4-6)claude-opus-4-5-20251101)claude-opus-4-1-20250805)claude-opus-4-20250514)claude-sonnet-4-5-20250929)claude-sonnet-4-20250514)claude-haiku-4-5-20251001)메모리 도구를 사용하려면:
context-management-2025-06-27을 포함합니다애플리케이션에서 메모리 도구 작업을 처리하려면 각 메모리 명령에 대한 핸들러를 구현해야 합니다. SDK는 도구 인터페이스를 처리하는 메모리 도구 헬퍼를 제공합니다—BetaAbstractMemoryTool(Python)을 서브클래스하거나 betaMemoryTool(TypeScript)을 사용하여 자체 메모리 백엔드(파일 기반, 데이터베이스, 클라우드 스토리지, 암호화된 파일 등)를 구현할 수 있습니다.
작동 예시는 다음을 참조하세요:
curl https://api.anthropic.com/v1/messages \
--header "x-api-key: $ANTHROPIC_API_KEY" \
--header "anthropic-version: 2023-06-01" \
--header "content-type: application/json" \
--header "anthropic-beta: context-management-2025-06-27" \
--data '{
"model": "claude-opus-4-6",
"max_tokens": 2048,
"messages": [
{
"role": "user",
"content": "I'\''m working on a Python web scraper that keeps crashing with a timeout error. Here'\''s the problematic function:\n\n```python\ndef fetch_page(url, retries=3):\n for i in range(retries):\n try:\n response = requests.get(url, timeout=5)\n return response.text\n except requests.exceptions.Timeout:\n if i == retries - 1:\n raise\n time.sleep(1)\n```\n\nPlease help me debug this."
}
],
"tools": [{
"type": "memory_20250818",
"name": "memory"
}]
}'클라이언트 측 구현에서 이러한 메모리 도구 명령을 처리해야 합니다. 이러한 사양은 Claude가 가장 익숙한 권장 동작을 설명하지만, 사용 사례에 맞게 구현을 수정하고 필요에 따라 문자열을 반환할 수 있습니다.
선택적 줄 범위와 함께 디렉토리 내용 또는 파일 내용을 표시합니다:
{
"command": "view",
"path": "/memories",
"view_range": [1, 10] // 선택 사항: 특정 줄 보기
}디렉토리의 경우: 파일과 디렉토리를 크기와 함께 보여주는 목록을 반환합니다:
Here're the files and directories up to 2 levels deep in {path}, excluding hidden items and node_modules:
{size} {path}
{size} {path}/{filename1}
{size} {path}/{filename2}5.5K, 1.2M).으로 시작하는 파일)과 node_modules를 제외합니다파일의 경우: 헤더와 줄 번호가 포함된 파일 내용을 반환합니다:
Here's the content of {path} with line numbers:
{line_numbers}{tab}{content}줄 번호 형식:
"File {path} exceeds maximum line limit of 999,999 lines."출력 예시:
Here's the content of /memories/notes.txt with line numbers:
1 Hello World
2 This is line two
10 Line ten
100 Line one hundred"The path {path} does not exist. Please provide a valid path."새 파일을 생성합니다:
{
"command": "create",
"path": "/memories/notes.txt",
"file_text": "Meeting notes:\n- Discussed project timeline\n- Next steps defined\n"
}"File created successfully at: {path}""Error: File {path} already exists"파일에서 텍스트를 교체합니다:
{
"command": "str_replace",
"path": "/memories/preferences.txt",
"old_str": "Favorite color: blue",
"new_str": "Favorite color: green"
}"The memory file has been edited." 다음에 줄 번호가 포함된 편집된 파일의 스니펫"Error: The path {path} does not exist. Please provide a valid path.""No replacement was performed, old_str `\{old_str}` did not appear verbatim in {path}."old_str이 여러 번 나타나는 경우 반환: "No replacement was performed. Multiple occurrences of old_str `\{old_str}` in lines: {line_numbers}. Please ensure it is unique"경로가 디렉토리인 경우 "파일이 존재하지 않음" 오류를 반환합니다.
특정 줄에 텍스트를 삽입합니다:
{
"command": "insert",
"path": "/memories/todo.txt",
"insert_line": 2,
"insert_text": "- Review memory tool documentation\n"
}"The file {path} has been edited.""Error: The path {path} does not exist""Error: Invalid `insert_line` parameter: {insert_line}. It should be within the range of lines of the file: [0, {n_lines}]"경로가 디렉토리인 경우 "파일이 존재하지 않음" 오류를 반환합니다.
파일 또는 디렉토리를 삭제합니다:
{
"command": "delete",
"path": "/memories/old_file.txt"
}"Successfully deleted {path}""Error: The path {path} does not exist"디렉토리와 모든 내용을 재귀적으로 삭제합니다.
파일/디렉토리의 이름을 변경하거나 이동합니다:
{
"command": "rename",
"old_path": "/memories/draft.txt",
"new_path": "/memories/final.txt"
}"Successfully renamed {old_path} to {new_path}""Error: The path {old_path} does not exist""Error: The destination {new_path} already exists"디렉토리의 이름을 변경합니다.
메모리 도구가 포함되면 시스템 프롬프트에 다음 지침이 자동으로 포함됩니다:
IMPORTANT: ALWAYS VIEW YOUR MEMORY DIRECTORY BEFORE DOING ANYTHING ELSE.
MEMORY PROTOCOL:
1. Use the `view` command of your `memory` tool to check for earlier progress.
2. ... (work on the task) ...
- As you make progress, record status / progress / thoughts etc in your memory.
ASSUME INTERRUPTION: Your context window might be reset at any moment, so you risk losing any progress that is not recorded in your memory directory.Claude가 지저분한 메모리 파일을 생성하는 것을 관찰하면 다음 지침을 포함할 수 있습니다:
참고: 메모리 폴더를 편집할 때 항상 내용을 최신 상태로 유지하고 일관성 있고 정리된 상태로 유지하세요. 더 이상 관련 없는 파일의 이름을 변경하거나 삭제할 수 있습니다. 필요하지 않은 경우 새 파일을 만들지 마세요.
Claude가 메모리에 기록하는 내용을 안내할 수도 있습니다. 예: "메모리 시스템에 <topic>과 관련된 정보만 기록하세요."
메모리 저장소를 구현할 때 중요한 보안 사항은 다음과 같습니다:
Claude는 일반적으로 메모리 파일에 민감한 정보를 기록하는 것을 거부합니다. 그러나 잠재적으로 민감한 정보를 제거하는 더 엄격한 유효성 검사를 구현할 수 있습니다.
메모리 파일 크기를 추적하고 파일이 너무 커지는 것을 방지하는 것을 고려하세요. 메모리 읽기 명령이 반환할 수 있는 최대 문자 수를 추가하고 Claude가 내용을 페이지네이션할 수 있도록 하는 것을 고려하세요.
오랜 시간 동안 액세스되지 않은 메모리 파일을 주기적으로 정리하는 것을 고려하세요.
악의적인 경로 입력이 /memories 디렉토리 외부의 파일에 액세스하려고 시도할 수 있습니다. 구현에서 디렉토리 순회 공격을 방지하기 위해 모든 경로를 반드시 검증해야 합니다.
다음 보호 조치를 고려하세요:
/memories로 시작하는지 검증../, ..\\ 또는 기타 순회 패턴이 포함된 경로 거부%2e%2e%2f)pathlib.Path.resolve() 및 relative_to())메모리 도구는 텍스트 편집기 도구와 유사한 오류 처리 패턴을 사용합니다. 자세한 오류 메시지와 동작은 위의 개별 도구 명령 섹션을 참조하세요. 일반적인 오류에는 파일을 찾을 수 없음, 권한 오류, 잘못된 경로 및 중복 텍스트 일치가 포함됩니다.
메모리 도구는 컨텍스트 편집과 결합할 수 있으며, 이는 대화 컨텍스트가 구성된 임계값을 초과하면 이전 도구 결과를 자동으로 지웁니다. 이 조합을 통해 컨텍스트 제한을 초과할 수 있는 장기 실행 에이전트 워크플로우가 가능합니다.
컨텍스트 편집이 활성화되고 대화가 정리 임계값에 접근하면 Claude는 자동으로 경고 알림을 받습니다. 이를 통해 Claude는 도구 결과가 컨텍스트 윈도우에서 지워지기 전에 중요한 정보를 메모리 파일에 보존할 수 있습니다.
도구 결과가 지워진 후 Claude는 필요할 때마다 메모리 파일에서 저장된 정보를 검색할 수 있으며, 메모리를 작업 컨텍스트의 확장으로 효과적으로 활용합니다. 이를 통해 Claude는 다음을 수행할 수 있습니다:
많은 파일 작업이 있는 코드 리팩토링 프로젝트를 고려해 보세요:
/memories/refactoring_progress.xml)두 기능을 함께 사용하려면:
response = client.beta.messages.create(
model="claude-opus-4-6",
max_tokens=4096,
messages=[...],
tools=[
{
"type": "memory_20250818",
"name": "memory"
},
# 기타 도구
],
betas=["context-management-2025-06-27"],
context_management={
"edits": [
{
"type": "clear_tool_uses_20250919",
"trigger": {
"type": "input_tokens",
"value": 100000
},
"keep": {
"type": "tool_uses",
"value": 3
}
}
]
}
)메모리 도구 호출이 지워지지 않도록 제외하여 Claude가 항상 최근 메모리 작업에 액세스할 수 있도록 할 수도 있습니다:
context_management={
"edits": [
{
"type": "clear_tool_uses_20250919",
"exclude_tools": ["memory"]
}
]
}메모리 도구는 압축과도 함께 사용할 수 있으며, 이는 이전 대화 컨텍스트의 서버 측 요약을 제공합니다. 컨텍스트 편집이 클라이언트 측에서 특정 도구 결과를 지우는 반면, 압축은 대화가 컨텍스트 윈도우 제한에 접근할 때 서버 측에서 전체 대화를 자동으로 요약합니다.
장기 실행 에이전트 워크플로우의 경우 두 가지를 모두 사용하는 것을 고려하세요: 압축은 클라이언트 측 관리 없이 활성 컨텍스트를 관리 가능한 수준으로 유지하고, 메모리는 압축 경계를 넘어 중요한 정보를 유지하여 요약에서 중요한 내용이 손실되지 않도록 합니다.
Was this page helpful?