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

# GitHub Integration for Context

> Connect Ana to a GitHub repository to load context dynamically and version-control context updates through pull requests.

<Note>
  TextQL supports both product-native context (managed in the [Context Editor](/core/guides/context/context-editor)) and GitHub-based context. They complement each other and can be used together.
</Note>

The GitHub integration is often described as "version control for context." That is true, but it undersells the more important capability: **Ana reads from the repository at the start of each conversation, dynamically loading only the files relevant to the question being asked.**

These are two distinct features that happen to use the same GitHub connection:

| Capability                                                                            | What it means                                                                                            |
| ------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------- |
| **[Dynamic context loading](/core/guides/context/github-dynamic-loading)**            | Ana reads live files from your repo at query time — not a static snapshot baked into the context library |
| **[Version-controlled context writing](/core/guides/context/github-version-control)** | Ana proposes context changes via pull requests; humans review and approve before anything merges         |

Most teams get more immediate value from dynamic loading. Version control becomes important as your context matures and multiple people are maintaining it.

## Product-native context vs. GitHub context

|                         | Product-Native Context Library                  | GitHub Repository                                                        |
| ----------------------- | ----------------------------------------------- | ------------------------------------------------------------------------ |
| **Best for**            | Universal rules, short definitions, quick setup | Large knowledge bases, structured documentation, team-maintained content |
| **Loading behavior**    | Entire document loaded on every conversation    | Relevant files fetched dynamically per question                          |
| **Editing**             | TextQL UI                                       | Any text editor, Git workflow                                            |
| **Version history**     | None                                            | Full Git history                                                         |
| **Collaboration**       | TextQL users only                               | Anyone with GitHub access                                                |
| **Ana can write to it** | Yes (with permission)                           | Yes, via pull requests                                                   |
| **Setup required**      | None                                            | GitHub repo + personal access token                                      |

**A common pattern:** Put your universal business rules (fiscal calendar, currency conventions, key exclusions) in the product-native context library. Put your data source documentation, metric definitions, and API docs in GitHub. Ana reads both.

## Setting up the integration

<Steps>
  <Step title="Create a GitHub repository">
    Create a new repository on GitHub (can be private). Name it something like `ana-context` or `textql-context`.

    <img src="https://mintcdn.com/textql/WTo4QmI95S9LmbVe/images/guides/github-memory/context_repo.png?fit=max&auto=format&n=WTo4QmI95S9LmbVe&q=85&s=58743e94143dd2e95e272783986a5aaa" alt="Create GitHub repository for Ana's context" width="2438" height="1256" data-path="images/guides/github-memory/context_repo.png" />
  </Step>

  <Step title="Create a personal access token">
    Go to [GitHub Settings > Developer settings > Personal access tokens](https://github.com/settings/personal-access-tokens/new) and generate a new token.

    <img src="https://mintcdn.com/textql/WTo4QmI95S9LmbVe/images/guides/github-memory/access_token2.png?fit=max&auto=format&n=WTo4QmI95S9LmbVe&q=85&s=c4706b3ed7bbe0364726ecadd0acc67e" alt="Generate GitHub personal access token" width="2180" height="1834" data-path="images/guides/github-memory/access_token2.png" />

    Configure the token:

    * **Repository access**: Select "Only select repositories" and choose the repository you just created
    * **Expiration**: Choose an appropriate duration (e.g., 30 days)
    * **Permissions**: Grant `Contents: Read and Write` so Ana can read context and write new context

    <img src="https://mintcdn.com/textql/WTo4QmI95S9LmbVe/images/guides/github-memory/scope.png?fit=max&auto=format&n=WTo4QmI95S9LmbVe&q=85&s=09512b90ad21eaddba41e69e1c262649" alt="Select repository scope permissions" width="1506" height="1478" data-path="images/guides/github-memory/scope.png" />

    Click **Generate token** and copy it — you won't be able to see it again.
  </Step>

  <Step title="Add the token to TextQL">
    Navigate to [API Connectors](/core/datasources/api-connectors) in TextQL and add the token as a connector named `ana_context_access_token`.

    <img src="https://mintcdn.com/textql/WTo4QmI95S9LmbVe/images/guides/github-memory/secrets.png?fit=max&auto=format&n=WTo4QmI95S9LmbVe&q=85&s=ad1716e3e23e0a4d11964a3bff3eab25" alt="Add GitHub token to secrets" width="3456" height="1924" data-path="images/guides/github-memory/secrets.png" />

    Then add the configuration key for the repository:

    <img src="https://mintcdn.com/textql/WTo4QmI95S9LmbVe/images/guides/github-memory/config_key.png?fit=max&auto=format&n=WTo4QmI95S9LmbVe&q=85&s=9b98446a0fb43ca923510634202dfd15" alt="Configure repository access key" width="3456" height="1926" data-path="images/guides/github-memory/config_key.png" />
  </Step>

  <Step title="Configure the system prompt">
    Add a system prompt that tells Ana the repository exists, how to access it, and how to navigate it. This is where you specify whether Ana should read a navigation index first, what kinds of questions should trigger a context lookup, and whether she should write context changes back via PRs.

    <Accordion title="Example system prompt template">
      ```
      BEFORE doing ANYTHING - ESPECIALLY AT THE START OF A NEW CHAT:
      1. Read overview.md from GitHub using ana_context_access_token
      2. NEVER make assumptions about how APIs work
      3. ALWAYS read supporting documentation from the context repo before using any API
      4. Use provided Python code - DO NOT use web search for API documentation

      GitHub Access Code:

      import requests
      import base64

      GITHUB_PAT = ana_context_access_token
      headers = {
          'Authorization': f'token {GITHUB_PAT}',
          'Accept': 'application/vnd.github.v3+json'
      }

      # REPLACE WITH YOUR VALUES
      REPO_OWNER = "your-github-username"
      REPO_NAME = "your-repo-name"

      # Reading files from the context repo:
      url = f"https://api.github.com/repos/{REPO_OWNER}/{REPO_NAME}/contents/overview.md"
      response = requests.get(url, headers=headers)
      content = base64.b64decode(response.json()['content']).decode('utf-8')

      Role:
      Ana helps keep context updated via GitHub access token. She maintains persistent memory across sessions by reading and writing to the context repository.

      When to Save:
      Save when user says:
      - "remember", "save", "store", "keep in mind"
      - Provides preferences or instructions
      - Likes a graph, visualization, or code cell
      - Shares important information for future sessions

      Save Procedure:
      1. Create a new branch (never push to main)
      2. Write to appropriate location (e.g., apis/{service-name}/ for API docs)
      3. Create descriptive PR
      4. Confirm to user
      ```
    </Accordion>

    <img src="https://mintcdn.com/textql/WTo4QmI95S9LmbVe/images/guides/github-memory/organization_context.png?fit=max&auto=format&n=WTo4QmI95S9LmbVe&q=85&s=742cae83312825f1a1a5177fc4d1da6f" alt="Configure organization context prompt" width="3456" height="1922" data-path="images/guides/github-memory/organization_context.png" />
  </Step>
</Steps>

## Demo: GitHub context in action

Ana references the context repository to understand previous work and team preferences:

<img src="https://mintcdn.com/textql/WTo4QmI95S9LmbVe/images/guides/github-memory/usecase.png?fit=max&auto=format&n=WTo4QmI95S9LmbVe&q=85&s=debc773cad3800ec843f722326c7a174" alt="Ana accessing persistent memory for context" width="3456" height="1924" data-path="images/guides/github-memory/usecase.png" />

Ana retrieves and applies stored context, providing responses aligned with previous work and established patterns:

<img src="https://mintcdn.com/textql/WTo4QmI95S9LmbVe/images/guides/github-memory/result.png?fit=max&auto=format&n=WTo4QmI95S9LmbVe&q=85&s=2a967d05a6cd2fa28fb7ba05a6fd4365" alt="Ana applying persistent memory to deliver contextual results" width="1719" height="1293" data-path="images/guides/github-memory/result.png" />

## Best practices

<AccordionGroup>
  <Accordion title="Always review pull requests manually">
    Never auto-merge PRs from Ana. Always manually review to ensure changes are accurate, don't contain sensitive information, and will produce the desired behavior.
  </Accordion>

  <Accordion title="Keep files focused">
    Create multiple focused files rather than one large file. This makes PR reviews easier, version history clearer, and dynamic loading more precise — Ana fetches whole files, so smaller files mean more targeted context.
  </Accordion>

  <Accordion title="Protect your main branch">
    Configure GitHub branch protection to require PR reviews before merging and prevent direct commits to main.
  </Accordion>

  <Accordion title="Rotate tokens periodically">
    Rotate your GitHub personal access token regularly and use an appropriate expiration window. Update the secret in TextQL when you rotate.
  </Accordion>
</AccordionGroup>

## Troubleshooting

**Ana can't access the repository**

* Verify the PAT has correct permissions (`Contents: Read and Write`)
* Check the repository URL and owner are correct in the system prompt
* Ensure the repository is not empty
* Confirm the PAT hasn't expired

**Context not updating after a merge**

* Verify changes are merged to the main branch
* Check that files are in markdown format (`.md`)
* Start a new chat to trigger a fresh context read

**Pull requests not being created**

* Verify the PAT has write permissions to branches
* Check that repository settings allow PR creation
* Ensure the system prompt includes instructions for Ana to save context

<CardGroup cols={2}>
  <Card title="Dynamic Context Loading" icon="bolt" href="/core/guides/context/github-dynamic-loading">
    How Ana navigates your repository to fetch only the files relevant to each question
  </Card>

  <Card title="Version-Controlled Context Writing" icon="code-branch" href="/core/guides/context/github-version-control">
    How Ana proposes context changes via pull requests and why the PR workflow matters
  </Card>
</CardGroup>
