> ## Documentation Index
> Fetch the complete documentation index at: https://docs.oncortex.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Capturing agent conversations

> Turn your AI conversations into memory

The conversations you have with your AI agents are full of knowledge: decisions, reasoning, things you worked out together. There are two ways to keep them in your brain, an easy one that works today, and an automatic one for when you want it to happen without thinking.

## The easy way: just ask

At the end of a conversation, tell your connected agent to save it:

> *"Save a summary of what we worked out to my brain."*

The agent writes a tidy page into your brain, following the [ingest skill](/filing/skills), the same as any other [thing you ask it to save](/capture/asking-your-agent). No setup, nothing to install. This is all most people need.

It lands in your own work brain, so anything captured this way stays yours until you decide to [promote](/brains/promoting) it.

## The automatic way: a session hook (advanced)

If you would rather have every session captured without asking each time, Claude Code can do it for you with a **hook**: a small command it runs automatically when a session ends. Setting this up means creating a short script and editing a settings file, so it is a step up in effort. If you are comfortable with a terminal it takes a few minutes; if not, it is a good one to hand to a developer, or just use the easy way above.

First, the one step that is the same on every system:

<Steps>
  <Step title="Create a service credential">
    In your work brain's [service credentials](/connect/service-credentials), create a read-and-write credential labelled "claude-code-capture" and copy its `ck_` key. This lets the hook post to Cortex without a browser.
  </Step>
</Steps>

Then follow the tab for your operating system. Each one creates a small script, stores your credential, and registers the hook.

<Tabs>
  <Tab title="macOS">
    The script uses `curl` (already on macOS) and `jq`, a small JSON tool. Install `jq` once:

    ```bash theme={null}
    brew install jq
    ```

    **1. Save this as `.claude/hooks/cortex-capture.sh`:**

    ```bash theme={null}
    #!/usr/bin/env bash
    set -euo pipefail

    # Claude Code sends details about the finished session on stdin.
    input=$(cat)
    transcript_path=$(echo "$input" | jq -r '.transcript_path')
    session_id=$(echo "$input" | jq -r '.session_id')

    # Build the request safely and post the transcript to your default inbox.
    body=$(jq -n \
      --arg filename "claude-code-$session_id.jsonl" \
      --arg externalId "$session_id" \
      --rawfile content "$transcript_path" \
      '{filename: $filename, content: $content, externalId: $externalId}')

    curl -s https://api.oncortex.ai/api/v1/inbox \
      -H "Authorization: Bearer $CORTEX_TOKEN" \
      -H "Content-Type: application/json" \
      -d "$body" > /dev/null
    ```

    Make it runnable:

    ```bash theme={null}
    chmod +x .claude/hooks/cortex-capture.sh
    ```

    **2. Store your credential** in `.claude/settings.local.json` (kept out of shared files):

    ```json theme={null}
    {
      "env": { "CORTEX_TOKEN": "ck_your_key_here" }
    }
    ```

    **3. Register the hook** in `.claude/settings.json`:

    ```json theme={null}
    {
      "hooks": {
        "SessionEnd": [
          {
            "hooks": [
              {
                "type": "command",
                "command": "$CLAUDE_PROJECT_DIR/.claude/hooks/cortex-capture.sh"
              }
            ]
          }
        ]
      }
    }
    ```
  </Tab>

  <Tab title="Linux">
    The script uses `curl` and `jq`, a small JSON tool. Install `jq` once with your package manager:

    ```bash theme={null}
    sudo apt install jq    # Debian / Ubuntu
    sudo dnf install jq    # Fedora
    ```

    **1. Save this as `.claude/hooks/cortex-capture.sh`:**

    ```bash theme={null}
    #!/usr/bin/env bash
    set -euo pipefail

    # Claude Code sends details about the finished session on stdin.
    input=$(cat)
    transcript_path=$(echo "$input" | jq -r '.transcript_path')
    session_id=$(echo "$input" | jq -r '.session_id')

    # Build the request safely and post the transcript to your default inbox.
    body=$(jq -n \
      --arg filename "claude-code-$session_id.jsonl" \
      --arg externalId "$session_id" \
      --rawfile content "$transcript_path" \
      '{filename: $filename, content: $content, externalId: $externalId}')

    curl -s https://api.oncortex.ai/api/v1/inbox \
      -H "Authorization: Bearer $CORTEX_TOKEN" \
      -H "Content-Type: application/json" \
      -d "$body" > /dev/null
    ```

    Make it runnable:

    ```bash theme={null}
    chmod +x .claude/hooks/cortex-capture.sh
    ```

    **2. Store your credential** in `.claude/settings.local.json` (kept out of shared files):

    ```json theme={null}
    {
      "env": { "CORTEX_TOKEN": "ck_your_key_here" }
    }
    ```

    **3. Register the hook** in `.claude/settings.json`:

    ```json theme={null}
    {
      "hooks": {
        "SessionEnd": [
          {
            "hooks": [
              {
                "type": "command",
                "command": "$CLAUDE_PROJECT_DIR/.claude/hooks/cortex-capture.sh"
              }
            ]
          }
        ]
      }
    }
    ```
  </Tab>

  <Tab title="Windows">
    Windows uses PowerShell, which is built in, so there is nothing extra to install. Claude Code runs the hook without any change to your execution policy.

    **1. Save this as `.claude/hooks/cortex-capture.ps1`:**

    ```powershell theme={null}
    # Claude Code sends details about the finished session on stdin.
    $data = [Console]::In.ReadToEnd() | ConvertFrom-Json
    $transcript = Get-Content -Path $data.transcript_path -Raw

    # Build the request and post the transcript to your default inbox.
    $body = @{
      filename   = "claude-code-$($data.session_id).jsonl"
      content    = $transcript
      externalId = $data.session_id
    } | ConvertTo-Json -Depth 10

    Invoke-RestMethod -Uri "https://api.oncortex.ai/api/v1/inbox" `
      -Method Post `
      -Headers @{ Authorization = "Bearer $env:CORTEX_TOKEN" } `
      -ContentType "application/json" `
      -Body $body | Out-Null
    ```

    **2. Store your credential** in `.claude/settings.local.json` (kept out of shared files):

    ```json theme={null}
    {
      "env": { "CORTEX_TOKEN": "ck_your_key_here" }
    }
    ```

    **3. Register the hook** in `.claude/settings.json`. The `"shell": "powershell"` line is what tells Claude Code to run the `.ps1` script:

    ```json theme={null}
    {
      "hooks": {
        "SessionEnd": [
          {
            "hooks": [
              {
                "type": "command",
                "command": "$CLAUDE_PROJECT_DIR/.claude/hooks/cortex-capture.ps1",
                "shell": "powershell"
              }
            ]
          }
        ]
      }
    }
    ```

    Use forward slashes in the path even on Windows; Claude Code converts them. Needs PowerShell 5.1 or newer, which ships with Windows 10 and 11.
  </Tab>
</Tabs>

To capture sessions across every project rather than just the current one, put the same hook in your user-level `~/.claude/settings.json` and use the script's full path.

From then on, each session's transcript lands in your personal inbox through the same door as any other item. What happens next is different from a document you chose to upload. A cheap first pass decides whether the session is worth a closer look at all; if not, it waits in the review queue with the reason. If it is, the [conversation skill](/filing/skills) reads it with a high bar: only a real decision, an idea in your own words, a durable fact about someone or something your brain tracks, or a substantial piece of work gets filed. Most sessions produce nothing, and that is the intended result. The transcript stays on the archived item either way, so nothing is lost. Ask your next session *"what did we work on last time?"* and it can tell you.

## Other agents

Any tool that can run a command or call a web address when it finishes can capture the same way: post the conversation to `https://api.oncortex.ai/api/v1/inbox` with a [service credential](/connect/service-credentials). The default-inbox address means you never name a brain; it goes to the credential's brain.

## Keeping it tidy

Captured conversations are filed by the [conversation skill](/filing/skills), which pulls out the substance rather than dumping raw transcripts, and files nothing when a session held nothing durable. If two sessions capture the same thing, [duplicate handling](/capture/the-inbox#duplicates-take-care-of-themselves) stops your brain filling up with repeats.
